|
| 1 | +package flipnote.group.adapter.in.web; |
| 2 | + |
| 3 | +import org.springframework.http.HttpStatus; |
| 4 | +import org.springframework.http.ResponseEntity; |
| 5 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 6 | +import org.springframework.web.bind.annotation.GetMapping; |
| 7 | +import org.springframework.web.bind.annotation.PatchMapping; |
| 8 | +import org.springframework.web.bind.annotation.PathVariable; |
| 9 | +import org.springframework.web.bind.annotation.PostMapping; |
| 10 | +import org.springframework.web.bind.annotation.RequestBody; |
| 11 | +import org.springframework.web.bind.annotation.RequestHeader; |
| 12 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 13 | +import org.springframework.web.bind.annotation.RestController; |
| 14 | + |
| 15 | +import flipnote.group.api.dto.request.CreateInviteRequestDto; |
| 16 | +import flipnote.group.api.dto.request.InviteRespondRequestDto; |
| 17 | +import flipnote.group.api.dto.response.CreateInviteResponseDto; |
| 18 | +import flipnote.group.api.dto.response.FindOutgoingInviteListResponseDto; |
| 19 | +import flipnote.group.application.port.in.CancelInviteUseCase; |
| 20 | +import flipnote.group.application.port.in.CreateInviteUseCase; |
| 21 | +import flipnote.group.application.port.in.FindInviteUseCase; |
| 22 | +import flipnote.group.application.port.in.InviteRespondUseCase; |
| 23 | +import flipnote.group.application.port.in.command.CancelInviteCommand; |
| 24 | +import flipnote.group.application.port.in.command.CreateInviteCommand; |
| 25 | +import flipnote.group.application.port.in.command.FindOutgoingInviteCommand; |
| 26 | +import flipnote.group.application.port.in.command.InviteRespondCommand; |
| 27 | +import flipnote.group.application.port.in.result.CreateInviteResult; |
| 28 | +import flipnote.group.application.port.in.result.FindOutgoingInviteListResult; |
| 29 | +import flipnote.group.application.port.in.result.InviteRespondResult; |
| 30 | +import jakarta.validation.Valid; |
| 31 | +import lombok.RequiredArgsConstructor; |
| 32 | + |
| 33 | +@RestController |
| 34 | +@RequestMapping("/v1/groups/{groupId}/invitations") |
| 35 | +@RequiredArgsConstructor |
| 36 | +public class InviteController { |
| 37 | + |
| 38 | + private final CreateInviteUseCase createInviteUseCase; |
| 39 | + private final CancelInviteUseCase cancelInviteUseCase; |
| 40 | + private final InviteRespondUseCase inviteRespondUseCase; |
| 41 | + private final FindInviteUseCase findInviteUseCase; |
| 42 | + |
| 43 | + @PostMapping("") |
| 44 | + public ResponseEntity<CreateInviteResponseDto> createInvite( |
| 45 | + @RequestHeader("X-USER-ID") Long userId, |
| 46 | + @RequestHeader("X-USER-EMAIL") String userEmail, |
| 47 | + @PathVariable("groupId") Long groupId, |
| 48 | + @Valid @RequestBody CreateInviteRequestDto req |
| 49 | + ) { |
| 50 | + |
| 51 | + CreateInviteCommand cmd = new CreateInviteCommand(userId, userEmail, groupId, req.email()); |
| 52 | + |
| 53 | + CreateInviteResult result = createInviteUseCase.createInvite(cmd); |
| 54 | + |
| 55 | + CreateInviteResponseDto res = CreateInviteResponseDto.from(result); |
| 56 | + |
| 57 | + return ResponseEntity.status(HttpStatus.CREATED).body(res); |
| 58 | + } |
| 59 | + |
| 60 | + @DeleteMapping("/{invitationId}") |
| 61 | + public ResponseEntity<Void> cancelInvite( |
| 62 | + @RequestHeader("X-USER-ID") Long userId, |
| 63 | + @PathVariable("groupId") Long groupId, |
| 64 | + @PathVariable("invitationId") Long invitationId |
| 65 | + ) { |
| 66 | + |
| 67 | + CancelInviteCommand cmd = new CancelInviteCommand(userId, groupId, invitationId); |
| 68 | + |
| 69 | + cancelInviteUseCase.cancelInvite(cmd); |
| 70 | + |
| 71 | + return ResponseEntity.noContent().build(); |
| 72 | + } |
| 73 | + |
| 74 | + @PatchMapping("/{invitationId}") |
| 75 | + public ResponseEntity<Void> respondToInvite( |
| 76 | + @RequestHeader("X-USER-ID") Long userId, |
| 77 | + @PathVariable("groupId") Long groupId, |
| 78 | + @PathVariable("invitationId") Long invitationId, |
| 79 | + @Valid @RequestBody InviteRespondRequestDto req |
| 80 | + ) { |
| 81 | + |
| 82 | + InviteRespondCommand cmd = new InviteRespondCommand( |
| 83 | + groupId, userId, invitationId, req.status().toInviteStatus() |
| 84 | + ); |
| 85 | + |
| 86 | + inviteRespondUseCase.respondToInvite(cmd); |
| 87 | + |
| 88 | + return ResponseEntity.ok().build(); |
| 89 | + } |
| 90 | + |
| 91 | + @GetMapping("") |
| 92 | + public ResponseEntity<FindOutgoingInviteListResponseDto> findOutgoingInvites( |
| 93 | + @RequestHeader("X-USER-ID") Long userId, |
| 94 | + @PathVariable("groupId") Long groupId |
| 95 | + ) { |
| 96 | + |
| 97 | + FindOutgoingInviteCommand cmd = new FindOutgoingInviteCommand(userId, groupId); |
| 98 | + |
| 99 | + FindOutgoingInviteListResult result = findInviteUseCase.findOutgoingInvites(cmd); |
| 100 | + |
| 101 | + FindOutgoingInviteListResponseDto res = FindOutgoingInviteListResponseDto.from(result); |
| 102 | + |
| 103 | + return ResponseEntity.ok(res); |
| 104 | + } |
| 105 | +} |
0 commit comments