Skip to content

Commit

Permalink
Merge pull request #124 from soma-baekgu/feature/BG-415-retrieve-reac…
Browse files Browse the repository at this point in the history
…tion-event-comment

[BG-415]: 리액션 이벤트 응답 조회 (3h / 3h)
  • Loading branch information
GGHDMS authored Nov 6, 2024
2 parents f30bc42 + 80c9b0b commit 3a08ec7
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.backgu.amaker.api.event.controller
import com.backgu.amaker.api.event.dto.query.ReplyQueryRequest
import com.backgu.amaker.api.event.dto.request.ReactionCommentCreateRequest
import com.backgu.amaker.api.event.dto.request.ReplyCommentCreateRequest
import com.backgu.amaker.api.event.dto.response.ReactionOptionWithCommentResponse
import com.backgu.amaker.api.event.dto.response.ReplyCommentWithUserResponse
import com.backgu.amaker.api.event.dto.response.ReplyCommentsViewResponse
import com.backgu.amaker.api.event.service.EventCommentFacadeService
Expand Down Expand Up @@ -55,6 +56,19 @@ class EventCommentController(
)
}

@GetMapping("/events/{event-id}/reaction/comments")
override fun findReactionComments(
@AuthenticationPrincipal token: JwtAuthentication,
@PathVariable("event-id") eventId: Long,
): ResponseEntity<ApiResult<List<ReactionOptionWithCommentResponse>>> =
ResponseEntity.ok(
apiHandler.onSuccess(
eventCommentFacadeService
.findReactionComment(token.id, eventId)
.map { ReactionOptionWithCommentResponse.of(it) },
),
)

@PostMapping("/events/{event-id}/reply/comments")
override fun createReplyComment(
@AuthenticationPrincipal token: JwtAuthentication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.backgu.amaker.api.event.controller
import com.backgu.amaker.api.event.dto.query.ReplyQueryRequest
import com.backgu.amaker.api.event.dto.request.ReactionCommentCreateRequest
import com.backgu.amaker.api.event.dto.request.ReplyCommentCreateRequest
import com.backgu.amaker.api.event.dto.response.ReactionOptionWithCommentResponse
import com.backgu.amaker.api.event.dto.response.ReplyCommentWithUserResponse
import com.backgu.amaker.common.http.response.ApiResult
import com.backgu.amaker.common.http.response.PageResponse
Expand All @@ -12,6 +13,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.PathVariable

@Tag(name = "eventComment", description = "이벤트 응답 API")
interface EventCommentSwagger {
Expand All @@ -30,6 +33,20 @@ interface EventCommentSwagger {
replyQueryRequest: ReplyQueryRequest,
): ResponseEntity<ApiResult<PageResponse<ReplyCommentWithUserResponse>>>

@Operation(summary = "reaction 이벤트 응답 조회", description = "reaction 이벤트 응답 조회합니다.")
@ApiResponses(
value = [
ApiResponse(
responseCode = "200",
description = "reaction 이벤트 응답 조회 성공",
),
],
)
fun findReactionComments(
@AuthenticationPrincipal token: JwtAuthentication,
@PathVariable("event-id") eventId: Long,
): ResponseEntity<ApiResult<List<ReactionOptionWithCommentResponse>>>

@Operation(summary = "reply 이벤트 응답 생성", description = "reply 이벤트 응답 생성합니다.")
@ApiResponses(
value = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.backgu.amaker.api.event.dto

import com.backgu.amaker.api.user.dto.UserDto
import com.backgu.amaker.domain.event.ReactionComment
import com.backgu.amaker.domain.user.User
import java.time.LocalDateTime

data class ReactionCommentWithUserDto(
val id: Long,
val eventId: Long,
val createdAt: LocalDateTime = LocalDateTime.now(),
val updatedAt: LocalDateTime = LocalDateTime.now(),
val userDto: UserDto,
) {
companion object {
fun of(
reactionComment: ReactionComment,
user: User,
) = ReactionCommentWithUserDto(
id = reactionComment.id,
eventId = reactionComment.eventId,
createdAt = reactionComment.createdAt,
updatedAt = reactionComment.updatedAt,
userDto = UserDto.of(user),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.backgu.amaker.api.event.dto

import com.backgu.amaker.common.exception.BusinessException
import com.backgu.amaker.common.status.StatusCode
import com.backgu.amaker.domain.event.ReactionComment
import com.backgu.amaker.domain.event.ReactionOption
import com.backgu.amaker.domain.user.User

data class ReactionOptionWithCommentDto(
val id: Long,
val eventId: Long,
val content: String,
val comments: List<ReactionCommentWithUserDto>,
) {
companion object {
fun of(
reactionOption: ReactionOption,
reactionComment: List<ReactionComment>,
userMap: Map<String, User>,
) = ReactionOptionWithCommentDto(
id = reactionOption.id,
eventId = reactionOption.eventId,
content = reactionOption.content,
comments =
reactionComment.map {
ReactionCommentWithUserDto.of(
it,
userMap[it.userId] ?: throw BusinessException(StatusCode.USER_NOT_FOUND),
)
},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.backgu.amaker.api.event.dto.response

import com.backgu.amaker.api.event.dto.ReactionCommentWithUserDto
import com.backgu.amaker.api.user.dto.response.UserResponse
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDateTime

data class ReactionCommentWithUserResponse(
@Schema(description = "리액션 응답 id", example = "1")
val id: Long,
@Schema(description = "생성 시간", example = "2024-07-02T19:56:05.624+09:00")
val createdAt: LocalDateTime = LocalDateTime.now(),
@Schema(description = "수정 시간", example = "2024-07-02T19:56:05.624+09:00")
val updatedAt: LocalDateTime = LocalDateTime.now(),
val userDto: UserResponse,
) {
companion object {
fun of(reactionComment: ReactionCommentWithUserDto) =
ReactionCommentWithUserResponse(
id = reactionComment.id,
createdAt = reactionComment.createdAt,
updatedAt = reactionComment.updatedAt,
userDto = UserResponse.of(reactionComment.userDto),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.backgu.amaker.api.event.dto.response

import com.backgu.amaker.api.event.dto.ReactionOptionWithCommentDto
import io.swagger.v3.oas.annotations.media.Schema

data class ReactionOptionWithCommentResponse(
@Schema(description = "리액션 응답 옵션 id", example = "1")
val id: Long,
@Schema(description = "이벤트 id", example = "2")
val eventId: Long,
@Schema(description = "응답 내용", example = "좋네용!")
val content: String,
val comments: List<ReactionCommentWithUserResponse>,
) {
companion object {
fun of(reactionOptionWithComment: ReactionOptionWithCommentDto) =
ReactionOptionWithCommentResponse(
id = reactionOptionWithComment.id,
eventId = reactionOptionWithComment.eventId,
content = reactionOptionWithComment.content,
comments = reactionOptionWithComment.comments.map { ReactionCommentWithUserResponse.of(it) },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.backgu.amaker.api.event.service

import com.backgu.amaker.api.event.dto.ReactionCommentCreateDto
import com.backgu.amaker.api.event.dto.ReactionCommentDto
import com.backgu.amaker.api.event.dto.ReactionOptionWithCommentDto
import com.backgu.amaker.api.event.dto.ReplyCommentCreateDto
import com.backgu.amaker.api.event.dto.ReplyCommentDto
import com.backgu.amaker.api.event.dto.ReplyCommentWithUserDto
Expand All @@ -16,6 +17,8 @@ import com.backgu.amaker.application.user.service.UserService
import com.backgu.amaker.application.workspace.WorkspaceUserService
import com.backgu.amaker.common.exception.BusinessException
import com.backgu.amaker.common.status.StatusCode
import com.backgu.amaker.domain.event.ReactionComment
import com.backgu.amaker.domain.user.User
import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
Expand Down Expand Up @@ -101,4 +104,29 @@ class EventCommentFacadeService(
)
}
}

fun findReactionComment(
userId: String,
eventId: Long,
): List<ReactionOptionWithCommentDto> {
workspaceUserService.validByUserIdAndChatIdInWorkspace(userId, eventId)
val reactionOptions = reactionOptionService.getAllByEventId(eventId)
val reactionCommentGroupByOption: Map<Long, List<ReactionComment>> =
reactionCommentService.findAllByEventIdGroupByReactionOptions(eventId)
val userMap: Map<String, User> =
userService.findAllByUserIdsToMap(
reactionCommentGroupByOption.flatMap {
it.value.map { it.userId }.toList()
},
)

return reactionOptions.map {
ReactionOptionWithCommentDto.of(
it,
reactionCommentGroupByOption[it.id]
?: emptyList(),
userMap,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ class ReactionCommentService(
event: ReactionEvent,
user: User,
): ReactionComment? = reactionCommentRepository.findByEventIdAndUserId(event.id, user.id)?.toDomain()

fun findAllByEventIdGroupByReactionOptions(eventId: Long): Map<Long, List<ReactionComment>> {
return reactionCommentRepository.findByEventId(eventId).map { it.toDomain() }.groupBy { it.optionId }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ interface ReactionCommentRepository : JpaRepository<ReactionCommentEntity, Long>
eventId: Long,
userId: String,
): ReactionCommentEntity?

fun findByEventId(eventId: Long): List<ReactionCommentEntity>
}

0 comments on commit 3a08ec7

Please sign in to comment.