From 27c9905e114d699199b20a242260de8050e10244 Mon Sep 17 00:00:00 2001 From: callendev20 Date: Wed, 30 Oct 2024 13:51:33 +0900 Subject: [PATCH 1/4] :white_check_mark: Add TbsubjectDto - detail --- .../com/thc/realspr/dto/TbsubjectDto.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/main/java/com/thc/realspr/dto/TbsubjectDto.java diff --git a/src/main/java/com/thc/realspr/dto/TbsubjectDto.java b/src/main/java/com/thc/realspr/dto/TbsubjectDto.java new file mode 100644 index 0000000..2ebd9de --- /dev/null +++ b/src/main/java/com/thc/realspr/dto/TbsubjectDto.java @@ -0,0 +1,69 @@ +package com.thc.realspr.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.util.List; + +public class TbsubjectDto { + @Schema(description = "주제 세부내용 요청 DTO") + @Getter + @Setter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class DetailReqDto { + private Long subjectId; + private String userId; + } + + + @Schema(description = "주제 세부내용 응답 DTO") + @Getter + @Setter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class DetailResDto { + private Long subjectId; + private boolean like; + private LastMessageServDto lastMessage; + private List messageHistory; + } + + @Schema(description = "주제 세부내용 서비스 DTO") + @Getter + @Setter + @AllArgsConstructor + @NoArgsConstructor + public static class DetailServDto { + private Long subjectId; + private boolean like; + private String lastMessageId; + } + + + + @Schema(description = "주제 마지막 메시지 서비스 DTO") + @Getter + @Setter + @AllArgsConstructor + @NoArgsConstructor + public static class LastMessageServDto { + private String id; + private long sentAt; + private String message; + } + + @Schema(description = "주제 메시지 이력 서비스 DTO") + @Getter + @Setter + @AllArgsConstructor + @NoArgsConstructor + public static class MessageHistoryServDto { + private String id; + private long sentAt; + private String message; + } + +} From 9f8e828293b9f4d42e14b6359efa5fcd5bae7aa3 Mon Sep 17 00:00:00 2001 From: callendev20 Date: Wed, 30 Oct 2024 13:52:27 +0900 Subject: [PATCH 2/4] :sparkles: Implement get subject detail --- .../thc/realspr/mapper/TbsubjectMapper.java | 15 +++++++ src/main/resources/mapper/TbsubjectMapper.xml | 44 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/main/java/com/thc/realspr/mapper/TbsubjectMapper.java create mode 100644 src/main/resources/mapper/TbsubjectMapper.xml diff --git a/src/main/java/com/thc/realspr/mapper/TbsubjectMapper.java b/src/main/java/com/thc/realspr/mapper/TbsubjectMapper.java new file mode 100644 index 0000000..376d65d --- /dev/null +++ b/src/main/java/com/thc/realspr/mapper/TbsubjectMapper.java @@ -0,0 +1,15 @@ +package com.thc.realspr.mapper; + +import com.thc.realspr.dto.TbsubjectDto; +import org.apache.ibatis.annotations.*; + +import java.util.List; + +@Mapper +public interface TbsubjectMapper { + TbsubjectDto.DetailServDto getDetailById(TbsubjectDto.DetailReqDto reqDto); + + TbsubjectDto.LastMessageServDto getLastMessageByMessageId(String lastMessageId); + + List getMessageHistoryById(Long subjectId); +} diff --git a/src/main/resources/mapper/TbsubjectMapper.xml b/src/main/resources/mapper/TbsubjectMapper.xml new file mode 100644 index 0000000..b2c406a --- /dev/null +++ b/src/main/resources/mapper/TbsubjectMapper.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + From cbefb664aed26fec1610cd03dfe3ff47e21f0455 Mon Sep 17 00:00:00 2001 From: callendev20 Date: Wed, 30 Oct 2024 13:53:01 +0900 Subject: [PATCH 3/4] :sparkles: Implement get detail - TbsubjectService --- .../thc/realspr/service/TbsubjectService.java | 13 +++++++++ .../service/impl/TbsubjectServiceImpl.java | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/java/com/thc/realspr/service/TbsubjectService.java create mode 100644 src/main/java/com/thc/realspr/service/impl/TbsubjectServiceImpl.java diff --git a/src/main/java/com/thc/realspr/service/TbsubjectService.java b/src/main/java/com/thc/realspr/service/TbsubjectService.java new file mode 100644 index 0000000..932853f --- /dev/null +++ b/src/main/java/com/thc/realspr/service/TbsubjectService.java @@ -0,0 +1,13 @@ +package com.thc.realspr.service; + + +import com.thc.realspr.dto.TbsubjectDto; +import org.springframework.stereotype.Service; + + +@Service +public interface TbsubjectService { + + TbsubjectDto.DetailResDto getDetail(TbsubjectDto.DetailReqDto param); + +} \ No newline at end of file diff --git a/src/main/java/com/thc/realspr/service/impl/TbsubjectServiceImpl.java b/src/main/java/com/thc/realspr/service/impl/TbsubjectServiceImpl.java new file mode 100644 index 0000000..231585c --- /dev/null +++ b/src/main/java/com/thc/realspr/service/impl/TbsubjectServiceImpl.java @@ -0,0 +1,27 @@ +package com.thc.realspr.service.impl; + +import com.thc.realspr.dto.TbsubjectDto; +import com.thc.realspr.mapper.TbsubjectMapper; +import com.thc.realspr.service.TbsubjectService; +import org.springframework.stereotype.Service; + + +@Service +public class TbsubjectServiceImpl implements TbsubjectService { + + private final TbsubjectMapper tbsubjectMapper; + + public TbsubjectServiceImpl(TbsubjectMapper tbsubjectMapper) { + this.tbsubjectMapper = tbsubjectMapper; + } + + public TbsubjectDto.DetailResDto getDetail(TbsubjectDto.DetailReqDto param){ + TbsubjectDto.DetailServDto detailServDto = tbsubjectMapper.getDetailById(param); + return TbsubjectDto.DetailResDto.builder() + .subjectId(detailServDto.getSubjectId()) + .like(detailServDto.isLike()) + .lastMessage(tbsubjectMapper.getLastMessageByMessageId(detailServDto.getLastMessageId())) + .messageHistory(tbsubjectMapper.getMessageHistoryById(detailServDto.getSubjectId())) + .build(); + } +} From 0262bf900c01c8774ca82e920a4ccb7c0753992b Mon Sep 17 00:00:00 2001 From: callendev20 Date: Wed, 30 Oct 2024 13:54:26 +0900 Subject: [PATCH 4/4] :white_check_mark: Add getSubjectDetail - TbsubjectController --- .../controller/TbsubjectController.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/com/thc/realspr/controller/TbsubjectController.java diff --git a/src/main/java/com/thc/realspr/controller/TbsubjectController.java b/src/main/java/com/thc/realspr/controller/TbsubjectController.java new file mode 100644 index 0000000..0751af2 --- /dev/null +++ b/src/main/java/com/thc/realspr/controller/TbsubjectController.java @@ -0,0 +1,59 @@ +package com.thc.realspr.controller; + +import com.thc.realspr.dto.TbmessageDto; +import com.thc.realspr.dto.TbsubjectDto; +import com.thc.realspr.dto.UserInteractionDto; +import com.thc.realspr.service.TbKaFeedService; +import com.thc.realspr.service.TbsubjectService; +import io.swagger.v3.oas.annotations.Operation; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RequestMapping("/api/subject") +@RestController +public class TbsubjectController { + + private final TbsubjectService tbsubjectService; + + public TbsubjectController( + TbsubjectService tbsubjectService + ) { + this.tbsubjectService = tbsubjectService; + } + + @Operation(summary = "주제 세부내용", + description = "주제의 id와 유저 id로 세부내용 조회
" + + "@param Long subjectId
" + + "@return HttpStatus.OK(200) ResponseEntity\\
" + + "@exception 필수 파라미터 누락하였을 때 등
" + + "@exception 404 Not Found (주제 또는 유저를 찾을 수 없는 경우)
" + + "@exception 400 Bad Request (필수 파라미터 누락 시)" + ) + @GetMapping("/{subjectId}") + public ResponseEntity getSubjectDetail(@Valid @PathVariable("subjectId") Long subjectId, HttpServletRequest request) { + String userId = (String) request.getAttribute("reqUserId"); + if (userId == null) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); + } + + TbsubjectDto.DetailResDto detail = tbsubjectService.getDetail( + TbsubjectDto.DetailReqDto.builder() + .subjectId(subjectId) + .userId(userId) + .build() + ); + + if (detail == null) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + } + + return ResponseEntity.status(HttpStatus.OK).body(detail); + } + + +}