From bd01b5d67ec33b1c43affc89c0eaf9ae87dfe0e2 Mon Sep 17 00:00:00 2001 From: dltmd202 Date: Wed, 6 Nov 2024 16:13:11 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=83=9C=EC=8A=A4=ED=81=AC=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/event/controller/EventController.kt | 21 ++++++++++ .../api/event/controller/EventSwagger.kt | 16 +++++++ .../api/event/dto/TaskEventDetailDto.kt | 36 ++++++++++++++++ .../dto/response/TaskEventDetailResponse.kt | 42 +++++++++++++++++++ .../api/event/service/EventFacadeService.kt | 38 +++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 api/src/main/kotlin/com/backgu/amaker/api/event/dto/TaskEventDetailDto.kt create mode 100644 api/src/main/kotlin/com/backgu/amaker/api/event/dto/response/TaskEventDetailResponse.kt diff --git a/api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventController.kt b/api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventController.kt index c6d8b6c3..fecfd10c 100644 --- a/api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventController.kt +++ b/api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventController.kt @@ -5,6 +5,7 @@ import com.backgu.amaker.api.event.dto.request.ReplyEventCreateRequest import com.backgu.amaker.api.event.dto.request.TaskEventCreateRequest import com.backgu.amaker.api.event.dto.response.ReactionEventDetailResponse import com.backgu.amaker.api.event.dto.response.ReplyEventDetailResponse +import com.backgu.amaker.api.event.dto.response.TaskEventDetailResponse import com.backgu.amaker.api.event.service.EventFacadeService import com.backgu.amaker.common.http.ApiHandler import com.backgu.amaker.common.http.response.ApiResult @@ -66,6 +67,26 @@ class EventController( ), ) + @GetMapping("/events/{event-id}/task") + override fun geTaskEvent( + @AuthenticationPrincipal token: JwtAuthentication, + @PathVariable("chat-room-id") chatRoomId: Long, + @PathVariable("event-id") eventId: Long, + ): ResponseEntity> = + ResponseEntity + .ok() + .body( + apiHandler.onSuccess( + TaskEventDetailResponse.of( + eventFacadeService.getTaskEvent( + token.id, + chatRoomId, + eventId, + ), + ), + ), + ) + @PostMapping("/events/reply") override fun createReplyEvent( @AuthenticationPrincipal token: JwtAuthentication, diff --git a/api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventSwagger.kt b/api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventSwagger.kt index dcde911b..3cf85c95 100644 --- a/api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventSwagger.kt +++ b/api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventSwagger.kt @@ -5,6 +5,7 @@ import com.backgu.amaker.api.event.dto.request.ReplyEventCreateRequest import com.backgu.amaker.api.event.dto.request.TaskEventCreateRequest import com.backgu.amaker.api.event.dto.response.ReactionEventDetailResponse import com.backgu.amaker.api.event.dto.response.ReplyEventDetailResponse +import com.backgu.amaker.api.event.dto.response.TaskEventDetailResponse import com.backgu.amaker.common.http.response.ApiResult import com.backgu.amaker.common.security.jwt.authentication.JwtAuthentication import io.swagger.v3.oas.annotations.Operation @@ -49,6 +50,21 @@ interface EventSwagger { eventId: Long, ): ResponseEntity> + @Operation(summary = "task 이벤트 상세조회", description = "task 이벤트 상세조회합니다.") + @ApiResponses( + value = [ + ApiResponse( + responseCode = "200", + description = "task 이벤트 상세조회 성공", + ), + ], + ) + fun geTaskEvent( + @AuthenticationPrincipal token: JwtAuthentication, + @PathVariable("chat-room-id") chatRoomId: Long, + @PathVariable("event-id") eventId: Long, + ): ResponseEntity> + @Operation(summary = "reply 이벤트 생성", description = "reply 이벤트 생성합니다.") @ApiResponses( value = [ diff --git a/api/src/main/kotlin/com/backgu/amaker/api/event/dto/TaskEventDetailDto.kt b/api/src/main/kotlin/com/backgu/amaker/api/event/dto/TaskEventDetailDto.kt new file mode 100644 index 00000000..ef943e4d --- /dev/null +++ b/api/src/main/kotlin/com/backgu/amaker/api/event/dto/TaskEventDetailDto.kt @@ -0,0 +1,36 @@ +package com.backgu.amaker.api.event.dto + +import com.backgu.amaker.api.user.dto.UserDto +import com.backgu.amaker.domain.event.TaskEvent +import java.time.LocalDateTime + +data class TaskEventDetailDto( + val id: Long, + val eventTitle: String, + val eventDetails: String, + val deadLine: LocalDateTime, + val notificationStartTime: LocalDateTime, + val notificationInterval: Int, + val eventCreator: UserDto, + val finishUser: List, + val waitingUser: List, +) { + companion object { + fun of( + taskEvent: TaskEvent, + eventCreator: UserDto, + finishUser: List, + waitingUser: List, + ) = TaskEventDetailDto( + id = taskEvent.id, + eventTitle = taskEvent.eventTitle, + eventDetails = taskEvent.eventDetails, + deadLine = taskEvent.deadLine, + notificationStartTime = taskEvent.notificationStartTime, + notificationInterval = taskEvent.notificationInterval, + eventCreator = eventCreator, + finishUser = finishUser, + waitingUser = waitingUser, + ) + } +} diff --git a/api/src/main/kotlin/com/backgu/amaker/api/event/dto/response/TaskEventDetailResponse.kt b/api/src/main/kotlin/com/backgu/amaker/api/event/dto/response/TaskEventDetailResponse.kt new file mode 100644 index 00000000..c0376cfe --- /dev/null +++ b/api/src/main/kotlin/com/backgu/amaker/api/event/dto/response/TaskEventDetailResponse.kt @@ -0,0 +1,42 @@ +package com.backgu.amaker.api.event.dto.response + +import com.backgu.amaker.api.event.dto.TaskEventDetailDto +import com.backgu.amaker.api.user.dto.response.UserResponse +import io.swagger.v3.oas.annotations.media.Schema +import java.time.LocalDateTime + +data class TaskEventDetailResponse( + @Schema(description = "이벤트 id", example = "1") + val id: Long, + @Schema(description = "이벤트 제목", example = "우리 어디서 만날지") + val eventTitle: String, + @Schema(description = "이벤트 디테일 한 정보", example = "우리 어디서 만날지 정해봅시다") + val eventDetails: String, + @Schema(description = "데드라인", example = "2024-07-24T07:39:37.598") + val deadLine: LocalDateTime, + @Schema(description = "알림 보낼 시작 시간", example = "2024-07-24T06:09:37.598") + val notificationStartTime: LocalDateTime, + @Schema(description = "알림 주기", example = "15") + val notificationInterval: Int, + @Schema(description = "이벤트 생성자") + val eventCreator: UserResponse, + @Schema(description = "이벤트를 수행한 유저") + val finishUser: List, + @Schema(description = "이벤트 수행 대기중인 유저") + val waitingUser: List, +) { + companion object { + fun of(taskEventDetailDto: TaskEventDetailDto) = + TaskEventDetailResponse( + id = taskEventDetailDto.id, + eventTitle = taskEventDetailDto.eventTitle, + eventDetails = taskEventDetailDto.eventDetails, + deadLine = taskEventDetailDto.deadLine, + notificationStartTime = taskEventDetailDto.notificationStartTime, + notificationInterval = taskEventDetailDto.notificationInterval, + eventCreator = UserResponse.of(taskEventDetailDto.eventCreator), + finishUser = taskEventDetailDto.finishUser.map { UserResponse.of(it) }, + waitingUser = taskEventDetailDto.waitingUser.map { UserResponse.of(it) }, + ) + } +} diff --git a/api/src/main/kotlin/com/backgu/amaker/api/event/service/EventFacadeService.kt b/api/src/main/kotlin/com/backgu/amaker/api/event/service/EventFacadeService.kt index 95106b97..4a5ea0fc 100644 --- a/api/src/main/kotlin/com/backgu/amaker/api/event/service/EventFacadeService.kt +++ b/api/src/main/kotlin/com/backgu/amaker/api/event/service/EventFacadeService.kt @@ -8,6 +8,7 @@ import com.backgu.amaker.api.event.dto.ReplyEventCreateDto import com.backgu.amaker.api.event.dto.ReplyEventDetailDto import com.backgu.amaker.api.event.dto.ReplyEventDto import com.backgu.amaker.api.event.dto.TaskEventCreateDto +import com.backgu.amaker.api.event.dto.TaskEventDetailDto import com.backgu.amaker.api.event.dto.TaskEventDto import com.backgu.amaker.api.user.dto.UserDto import com.backgu.amaker.application.chat.event.EventChatSaveEvent @@ -129,6 +130,43 @@ class EventFacadeService( ) } + fun getTaskEvent( + userId: String, + chatRoomId: Long, + eventId: Long, + ): TaskEventDetailDto { + val user = userService.getById(userId) + val chatRoom = chatRoomService.getById(chatRoomId) + chatRoomUserService.validateUserInChatRoom(user, chatRoom) + + val chat = chatService.getById(eventId) + val eventAssignedUsers = eventAssignedUserService.findAllByEventId(eventId) + val eventAssignedUserIds = eventAssignedUsers.map { it.userId } + + val users = userService.findAllByUserIdsToMap(eventAssignedUserIds.union(listOf(chat.userId)).toList()) + + val taskEvent = taskEventService.getById(eventId) + + val (finishedUsers, waitingUsers) = eventAssignedUsers.partition { it.isFinished } + + return TaskEventDetailDto.of( + taskEvent = taskEvent, + eventCreator = UserDto.of(users[chat.userId] ?: throw BusinessException(StatusCode.USER_NOT_FOUND)), + finishUser = + finishedUsers.map { + UserDto.of( + users[it.userId] ?: throw BusinessException(StatusCode.USER_NOT_FOUND), + ) + }, + waitingUser = + waitingUsers.map { + UserDto.of( + users[it.userId] ?: throw BusinessException(StatusCode.USER_NOT_FOUND), + ) + }, + ) + } + @Transactional fun createReplyEvent( userId: String,