Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] #143 - test #155

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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