Skip to content

Commit

Permalink
Merge pull request #126 from soma-baekgu/feature/BG-416-retrieve-task…
Browse files Browse the repository at this point in the history
…-event

[BG-416]: 태스크 이벤트 상세조회 (1h / 1h)
  • Loading branch information
GGHDMS authored Nov 8, 2024
2 parents b7f61a6 + bd01b5d commit 8602f26
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ApiResult<TaskEventDetailResponse>> =
ResponseEntity
.ok()
.body(
apiHandler.onSuccess(
TaskEventDetailResponse.of(
eventFacadeService.getTaskEvent(
token.id,
chatRoomId,
eventId,
),
),
),
)

@PostMapping("/events/reply")
override fun createReplyEvent(
@AuthenticationPrincipal token: JwtAuthentication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,6 +50,21 @@ interface EventSwagger {
eventId: Long,
): ResponseEntity<ApiResult<ReactionEventDetailResponse>>

@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<ApiResult<TaskEventDetailResponse>>

@Operation(summary = "reply 이벤트 생성", description = "reply 이벤트 생성합니다.")
@ApiResponses(
value = [
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UserDto>,
val waitingUser: List<UserDto>,
) {
companion object {
fun of(
taskEvent: TaskEvent,
eventCreator: UserDto,
finishUser: List<UserDto>,
waitingUser: List<UserDto>,
) = 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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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<UserResponse>,
@Schema(description = "이벤트 수행 대기중인 유저")
val waitingUser: List<UserResponse>,
) {
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) },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8602f26

Please sign in to comment.