Skip to content

Commit

Permalink
Merge pull request #155 from WooRibound/fix/#143-test
Browse files Browse the repository at this point in the history
[fix] #143 -  test
  • Loading branch information
Oodls authored Nov 28, 2024
2 parents b7be394 + 1ae526a commit 97ba6c6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "지헤 나눔 등록")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public List<WbUserKnowhowDTO> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface KnowhowRepository extends JpaRepository<Knowhow, Long> {
// 신고 횟수 기준으로 내림차순
@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) " +
Expand All @@ -28,7 +28,7 @@ List<AdminKnowhowProjection> 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) " +
Expand All @@ -40,7 +40,7 @@ List<AdminKnowhowProjection> 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) " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface AdminKnowhowProjection {

String getUserId();

String getUserName();

String getKnowhowTitle();

Date getUploadDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public List<AdminKnowhowDTO> getAllKnowhows(AdminKnowhowReqDTO adminKnowhowReqDT
return AdminKnowhowDTO.builder()
.knowhowId(projection.getKnowhowId())
.userId(projection.getUserId())
.userName(projection.getUserName())
.knowhowJob(projection.getKnowhowJob())
.knowhowTitle(projection.getKnowhowTitle())
.uploadDate(projection.getUploadDate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface WbUserKnowhowService {

List<WbUserKnowhowDTO> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,17 +46,16 @@ public WbUserKnowhowDTO getShareKnowhowDetail(Long knowhowId) {
}

@Override
public Long deleteShareKnowhow(String userId, Long knowhowId) {
Optional<Knowhow> 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();
}
Expand Down

0 comments on commit 97ba6c6

Please sign in to comment.