From c9c2d2a7da9dcbabce6c7a174bc0c2a00beee88e Mon Sep 17 00:00:00 2001 From: soljjang777 Date: Thu, 28 Nov 2024 19:35:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[refactor]=20#143=20-=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=20=ED=9A=8C=EC=9B=90=20=EC=A7=80=ED=98=9C=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20API=20=EB=A6=AC=ED=8E=99=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WbUserKnowhowController.java | 3 +-- .../individual/facade/WBUserKnowhowFacade.java | 2 +- .../knowhow/service/WbUserKnowhowService.java | 2 +- .../knowhow/service/WbUserKnowhowServiceImpl.java | 15 ++++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/wooribound/api/individual/controller/WbUserKnowhowController.java b/src/main/java/com/wooribound/api/individual/controller/WbUserKnowhowController.java index dc978c8..4e7bd87 100644 --- a/src/main/java/com/wooribound/api/individual/controller/WbUserKnowhowController.java +++ b/src/main/java/com/wooribound/api/individual/controller/WbUserKnowhowController.java @@ -31,8 +31,7 @@ public ResponseEntity getAllShareKnowhows(Authentication authentication, @Operation(summary = "지헤 나눔 삭제", description = "지헤 나눔 삭제") @DeleteMapping("/share/delete") public ResponseEntity deleteShareKnowhow(Authentication authentication, @RequestParam("knowhowId") Long knowhowId) { - wbUserKnowhowFacade.deleteShareKnowhow(authentication, knowhowId); - return ResponseEntity.ok().body("삭제가 완료되었습니다."); + return ResponseEntity.ok().body(wbUserKnowhowFacade.deleteShareKnowhow(authentication, knowhowId)); } @Operation(summary = "지헤 나눔 등록", description = "지헤 나눔 등록") diff --git a/src/main/java/com/wooribound/api/individual/facade/WBUserKnowhowFacade.java b/src/main/java/com/wooribound/api/individual/facade/WBUserKnowhowFacade.java index b1a6b72..f26d2e1 100644 --- a/src/main/java/com/wooribound/api/individual/facade/WBUserKnowhowFacade.java +++ b/src/main/java/com/wooribound/api/individual/facade/WBUserKnowhowFacade.java @@ -26,7 +26,7 @@ public List getAllShareKnowhows(Authentication authentication, } @Transactional - public Long deleteShareKnowhow(Authentication authentication, Long knowhowId) { + public String deleteShareKnowhow(Authentication authentication, Long knowhowId) { String userId = authenticateUtil.CheckWbUserAuthAndGetUserId(authentication); return wbUserKnowhowService.deleteShareKnowhow(userId, knowhowId); } diff --git a/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowService.java b/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowService.java index 6d63fa3..a06c207 100644 --- a/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowService.java +++ b/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowService.java @@ -8,7 +8,7 @@ public interface WbUserKnowhowService { List getAllShareKnowhows(String userId, String knowhowTitle, String knowhowJob); - Long deleteShareKnowhow (String userId, Long knowhowId); + String deleteShareKnowhow (String userId, Long knowhowId); Long createShareKnowhow(String userId, WbUserKnowhowDTO wbUserKnowhowDTO); diff --git a/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowServiceImpl.java b/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowServiceImpl.java index 20b2dd4..1e77641 100644 --- a/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowServiceImpl.java +++ b/src/main/java/com/wooribound/domain/knowhow/service/WbUserKnowhowServiceImpl.java @@ -6,6 +6,8 @@ import com.wooribound.domain.wbuser.WbUser; import com.wooribound.domain.wbuser.WbUserRepository; import com.wooribound.global.exception.KnowhowNotFoundException; +import com.wooribound.global.exception.NoKnowhowException; +import com.wooribound.global.exception.NotEntityException; import com.wooribound.global.exception.UnauthorizedAccessException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -44,17 +46,16 @@ public WbUserKnowhowDTO getShareKnowhowDetail(Long knowhowId) { } @Override - public Long deleteShareKnowhow(String userId, Long knowhowId) { - Optional byKnowhowId = knowhowRepository.findById(knowhowId); + public String deleteShareKnowhow(String userId, Long knowhowId) { + wbUserRepository.findById(userId) + .orElseThrow(() -> new NotEntityException("[WbUser, ID :" + userId + "]")); - if (byKnowhowId.isEmpty()) { - throw new IllegalArgumentException("없는 지혜 나눔 게시물입니다."); - } + Knowhow knowhow = knowhowRepository.findById(knowhowId) + .orElseThrow(() -> new NotEntityException("[Knowhow, ID :" + knowhowId + "]")); - Knowhow knowhow = byKnowhowId.get(); if (knowhow.getWbUser().getUserId().equals(userId)) { knowhowRepository.delete(knowhow); - return knowhowId; + return "삭제가 완료되었습니다."; } else { throw new UnauthorizedAccessException(); } From 1ae526ad4491a787b86920adafb391e18b5ce4ad Mon Sep 17 00:00:00 2001 From: soljjang777 Date: Thu, 28 Nov 2024 19:41:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[update]=20#143=20-=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EA=B4=80=EB=A6=AC=EC=9E=90=20=EC=A7=80=ED=98=9C?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=EC=97=90=20username=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wooribound/domain/knowhow/KnowhowRepository.java | 6 +++--- .../com/wooribound/domain/knowhow/dto/AdminKnowhowDTO.java | 1 + .../domain/knowhow/dto/AdminKnowhowProjection.java | 2 ++ .../domain/knowhow/service/AdminKnowhowServiceImpl.java | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/wooribound/domain/knowhow/KnowhowRepository.java b/src/main/java/com/wooribound/domain/knowhow/KnowhowRepository.java index 0868df4..3ea6095 100644 --- a/src/main/java/com/wooribound/domain/knowhow/KnowhowRepository.java +++ b/src/main/java/com/wooribound/domain/knowhow/KnowhowRepository.java @@ -16,7 +16,7 @@ public interface KnowhowRepository extends JpaRepository { // 신고 횟수 기준으로 내림차순 @Query("SELECT k.knowhowId AS knowhowId, k.knowhowJob AS knowhowJob, " + "k.knowhowTitle AS knowhowTitle, k.uploadDate AS uploadDate, " + - "COUNT(k_report) AS reportedCnt, k.wbUser.userId AS userId FROM Knowhow k " + + "COUNT(k_report) AS reportedCnt, k.wbUser.userId AS userId, k.wbUser.name AS userName FROM Knowhow k " + "LEFT JOIN KnowhowReported k_report ON k_report.knowhow = k " + "WHERE (:knowhowTitle IS NULL OR k.knowhowTitle LIKE %:knowhowTitle%) " + "AND (:knowhowJob IS NULL OR k.knowhowJob = :knowhowJob) " + @@ -28,7 +28,7 @@ List findAllWithReportedCntDesc(@Param("knowhowTitle") S // 신고 횟수 기준으로 오름차순 @Query("SELECT k.knowhowId AS knowhowId, k.knowhowJob AS knowhowJob, " + "k.knowhowTitle AS knowhowTitle, k.uploadDate AS uploadDate, " + - "COUNT(k_report) AS reportedCnt, k.wbUser.userId AS userId FROM Knowhow k " + + "COUNT(k_report) AS reportedCnt, k.wbUser.userId AS userId, k.wbUser.name AS userName FROM Knowhow k " + "LEFT JOIN KnowhowReported k_report ON k_report.knowhow = k " + "WHERE (:knowhowTitle IS NULL OR k.knowhowTitle LIKE %:knowhowTitle%) " + "AND (:knowhowJob IS NULL OR k.knowhowJob = :knowhowJob) " + @@ -40,7 +40,7 @@ List findAllWithReportedCntAsc(@Param("knowhowTitle") St // 업로드 날짜 기준 내림차순 @Query("SELECT k.knowhowId AS knowhowId, k.knowhowJob AS knowhowJob, " + "k.knowhowTitle AS knowhowTitle, k.uploadDate AS uploadDate, " + - "COUNT(k_report) AS reportedCnt, k.wbUser.userId AS userId FROM Knowhow k " + + "COUNT(k_report) AS reportedCnt, k.wbUser.userId AS userId, k.wbUser.name AS userName FROM Knowhow k " + "LEFT JOIN KnowhowReported k_report ON k_report.knowhow = k " + "WHERE (:knowhowTitle IS NULL OR k.knowhowTitle LIKE %:knowhowTitle%) " + "AND (:knowhowJob IS NULL OR k.knowhowJob = :knowhowJob) " + diff --git a/src/main/java/com/wooribound/domain/knowhow/dto/AdminKnowhowDTO.java b/src/main/java/com/wooribound/domain/knowhow/dto/AdminKnowhowDTO.java index 493f0cc..bef9f01 100644 --- a/src/main/java/com/wooribound/domain/knowhow/dto/AdminKnowhowDTO.java +++ b/src/main/java/com/wooribound/domain/knowhow/dto/AdminKnowhowDTO.java @@ -12,6 +12,7 @@ public class AdminKnowhowDTO { private Long knowhowId; private String userId; + private String userName; private String knowhowJob; private String knowhowTitle; private Date uploadDate; diff --git a/src/main/java/com/wooribound/domain/knowhow/dto/AdminKnowhowProjection.java b/src/main/java/com/wooribound/domain/knowhow/dto/AdminKnowhowProjection.java index 35f9614..eef64c0 100644 --- a/src/main/java/com/wooribound/domain/knowhow/dto/AdminKnowhowProjection.java +++ b/src/main/java/com/wooribound/domain/knowhow/dto/AdminKnowhowProjection.java @@ -9,6 +9,8 @@ public interface AdminKnowhowProjection { String getUserId(); + String getUserName(); + String getKnowhowTitle(); Date getUploadDate(); diff --git a/src/main/java/com/wooribound/domain/knowhow/service/AdminKnowhowServiceImpl.java b/src/main/java/com/wooribound/domain/knowhow/service/AdminKnowhowServiceImpl.java index e70dee7..c570f44 100644 --- a/src/main/java/com/wooribound/domain/knowhow/service/AdminKnowhowServiceImpl.java +++ b/src/main/java/com/wooribound/domain/knowhow/service/AdminKnowhowServiceImpl.java @@ -38,6 +38,7 @@ public List getAllKnowhows(AdminKnowhowReqDTO adminKnowhowReqDT return AdminKnowhowDTO.builder() .knowhowId(projection.getKnowhowId()) .userId(projection.getUserId()) + .userName(projection.getUserName()) .knowhowJob(projection.getKnowhowJob()) .knowhowTitle(projection.getKnowhowTitle()) .uploadDate(projection.getUploadDate())