Skip to content

Commit 8602f26

Browse files
authored
Merge pull request #126 from soma-baekgu/feature/BG-416-retrieve-task-event
[BG-416]: 태스크 이벤트 상세조회 (1h / 1h)
2 parents b7f61a6 + bd01b5d commit 8602f26

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
lines changed

api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventController.kt

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.backgu.amaker.api.event.dto.request.ReplyEventCreateRequest
55
import com.backgu.amaker.api.event.dto.request.TaskEventCreateRequest
66
import com.backgu.amaker.api.event.dto.response.ReactionEventDetailResponse
77
import com.backgu.amaker.api.event.dto.response.ReplyEventDetailResponse
8+
import com.backgu.amaker.api.event.dto.response.TaskEventDetailResponse
89
import com.backgu.amaker.api.event.service.EventFacadeService
910
import com.backgu.amaker.common.http.ApiHandler
1011
import com.backgu.amaker.common.http.response.ApiResult
@@ -66,6 +67,26 @@ class EventController(
6667
),
6768
)
6869

70+
@GetMapping("/events/{event-id}/task")
71+
override fun geTaskEvent(
72+
@AuthenticationPrincipal token: JwtAuthentication,
73+
@PathVariable("chat-room-id") chatRoomId: Long,
74+
@PathVariable("event-id") eventId: Long,
75+
): ResponseEntity<ApiResult<TaskEventDetailResponse>> =
76+
ResponseEntity
77+
.ok()
78+
.body(
79+
apiHandler.onSuccess(
80+
TaskEventDetailResponse.of(
81+
eventFacadeService.getTaskEvent(
82+
token.id,
83+
chatRoomId,
84+
eventId,
85+
),
86+
),
87+
),
88+
)
89+
6990
@PostMapping("/events/reply")
7091
override fun createReplyEvent(
7192
@AuthenticationPrincipal token: JwtAuthentication,

api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventSwagger.kt

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.backgu.amaker.api.event.dto.request.ReplyEventCreateRequest
55
import com.backgu.amaker.api.event.dto.request.TaskEventCreateRequest
66
import com.backgu.amaker.api.event.dto.response.ReactionEventDetailResponse
77
import com.backgu.amaker.api.event.dto.response.ReplyEventDetailResponse
8+
import com.backgu.amaker.api.event.dto.response.TaskEventDetailResponse
89
import com.backgu.amaker.common.http.response.ApiResult
910
import com.backgu.amaker.common.security.jwt.authentication.JwtAuthentication
1011
import io.swagger.v3.oas.annotations.Operation
@@ -49,6 +50,21 @@ interface EventSwagger {
4950
eventId: Long,
5051
): ResponseEntity<ApiResult<ReactionEventDetailResponse>>
5152

53+
@Operation(summary = "task 이벤트 상세조회", description = "task 이벤트 상세조회합니다.")
54+
@ApiResponses(
55+
value = [
56+
ApiResponse(
57+
responseCode = "200",
58+
description = "task 이벤트 상세조회 성공",
59+
),
60+
],
61+
)
62+
fun geTaskEvent(
63+
@AuthenticationPrincipal token: JwtAuthentication,
64+
@PathVariable("chat-room-id") chatRoomId: Long,
65+
@PathVariable("event-id") eventId: Long,
66+
): ResponseEntity<ApiResult<TaskEventDetailResponse>>
67+
5268
@Operation(summary = "reply 이벤트 생성", description = "reply 이벤트 생성합니다.")
5369
@ApiResponses(
5470
value = [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.backgu.amaker.api.event.dto
2+
3+
import com.backgu.amaker.api.user.dto.UserDto
4+
import com.backgu.amaker.domain.event.TaskEvent
5+
import java.time.LocalDateTime
6+
7+
data class TaskEventDetailDto(
8+
val id: Long,
9+
val eventTitle: String,
10+
val eventDetails: String,
11+
val deadLine: LocalDateTime,
12+
val notificationStartTime: LocalDateTime,
13+
val notificationInterval: Int,
14+
val eventCreator: UserDto,
15+
val finishUser: List<UserDto>,
16+
val waitingUser: List<UserDto>,
17+
) {
18+
companion object {
19+
fun of(
20+
taskEvent: TaskEvent,
21+
eventCreator: UserDto,
22+
finishUser: List<UserDto>,
23+
waitingUser: List<UserDto>,
24+
) = TaskEventDetailDto(
25+
id = taskEvent.id,
26+
eventTitle = taskEvent.eventTitle,
27+
eventDetails = taskEvent.eventDetails,
28+
deadLine = taskEvent.deadLine,
29+
notificationStartTime = taskEvent.notificationStartTime,
30+
notificationInterval = taskEvent.notificationInterval,
31+
eventCreator = eventCreator,
32+
finishUser = finishUser,
33+
waitingUser = waitingUser,
34+
)
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.backgu.amaker.api.event.dto.response
2+
3+
import com.backgu.amaker.api.event.dto.TaskEventDetailDto
4+
import com.backgu.amaker.api.user.dto.response.UserResponse
5+
import io.swagger.v3.oas.annotations.media.Schema
6+
import java.time.LocalDateTime
7+
8+
data class TaskEventDetailResponse(
9+
@Schema(description = "이벤트 id", example = "1")
10+
val id: Long,
11+
@Schema(description = "이벤트 제목", example = "우리 어디서 만날지")
12+
val eventTitle: String,
13+
@Schema(description = "이벤트 디테일 한 정보", example = "우리 어디서 만날지 정해봅시다")
14+
val eventDetails: String,
15+
@Schema(description = "데드라인", example = "2024-07-24T07:39:37.598")
16+
val deadLine: LocalDateTime,
17+
@Schema(description = "알림 보낼 시작 시간", example = "2024-07-24T06:09:37.598")
18+
val notificationStartTime: LocalDateTime,
19+
@Schema(description = "알림 주기", example = "15")
20+
val notificationInterval: Int,
21+
@Schema(description = "이벤트 생성자")
22+
val eventCreator: UserResponse,
23+
@Schema(description = "이벤트를 수행한 유저")
24+
val finishUser: List<UserResponse>,
25+
@Schema(description = "이벤트 수행 대기중인 유저")
26+
val waitingUser: List<UserResponse>,
27+
) {
28+
companion object {
29+
fun of(taskEventDetailDto: TaskEventDetailDto) =
30+
TaskEventDetailResponse(
31+
id = taskEventDetailDto.id,
32+
eventTitle = taskEventDetailDto.eventTitle,
33+
eventDetails = taskEventDetailDto.eventDetails,
34+
deadLine = taskEventDetailDto.deadLine,
35+
notificationStartTime = taskEventDetailDto.notificationStartTime,
36+
notificationInterval = taskEventDetailDto.notificationInterval,
37+
eventCreator = UserResponse.of(taskEventDetailDto.eventCreator),
38+
finishUser = taskEventDetailDto.finishUser.map { UserResponse.of(it) },
39+
waitingUser = taskEventDetailDto.waitingUser.map { UserResponse.of(it) },
40+
)
41+
}
42+
}

api/src/main/kotlin/com/backgu/amaker/api/event/service/EventFacadeService.kt

+38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.backgu.amaker.api.event.dto.ReplyEventCreateDto
88
import com.backgu.amaker.api.event.dto.ReplyEventDetailDto
99
import com.backgu.amaker.api.event.dto.ReplyEventDto
1010
import com.backgu.amaker.api.event.dto.TaskEventCreateDto
11+
import com.backgu.amaker.api.event.dto.TaskEventDetailDto
1112
import com.backgu.amaker.api.event.dto.TaskEventDto
1213
import com.backgu.amaker.api.user.dto.UserDto
1314
import com.backgu.amaker.application.chat.event.EventChatSaveEvent
@@ -129,6 +130,43 @@ class EventFacadeService(
129130
)
130131
}
131132

133+
fun getTaskEvent(
134+
userId: String,
135+
chatRoomId: Long,
136+
eventId: Long,
137+
): TaskEventDetailDto {
138+
val user = userService.getById(userId)
139+
val chatRoom = chatRoomService.getById(chatRoomId)
140+
chatRoomUserService.validateUserInChatRoom(user, chatRoom)
141+
142+
val chat = chatService.getById(eventId)
143+
val eventAssignedUsers = eventAssignedUserService.findAllByEventId(eventId)
144+
val eventAssignedUserIds = eventAssignedUsers.map { it.userId }
145+
146+
val users = userService.findAllByUserIdsToMap(eventAssignedUserIds.union(listOf(chat.userId)).toList())
147+
148+
val taskEvent = taskEventService.getById(eventId)
149+
150+
val (finishedUsers, waitingUsers) = eventAssignedUsers.partition { it.isFinished }
151+
152+
return TaskEventDetailDto.of(
153+
taskEvent = taskEvent,
154+
eventCreator = UserDto.of(users[chat.userId] ?: throw BusinessException(StatusCode.USER_NOT_FOUND)),
155+
finishUser =
156+
finishedUsers.map {
157+
UserDto.of(
158+
users[it.userId] ?: throw BusinessException(StatusCode.USER_NOT_FOUND),
159+
)
160+
},
161+
waitingUser =
162+
waitingUsers.map {
163+
UserDto.of(
164+
users[it.userId] ?: throw BusinessException(StatusCode.USER_NOT_FOUND),
165+
)
166+
},
167+
)
168+
}
169+
132170
@Transactional
133171
fun createReplyEvent(
134172
userId: String,

0 commit comments

Comments
 (0)