Skip to content

Commit

Permalink
Merge pull request #49 from Team-Shaka/refactor/48
Browse files Browse the repository at this point in the history
♻️ Refactor: scrap삭제 API
  • Loading branch information
swa07016 authored Oct 7, 2023
2 parents c8d9635 + a16cdc8 commit bdbff34
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/java/briefing/scrap/api/ScrapApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public CommonResponse<ScrapResponse.CreateDTO> create(@RequestBody ScrapRequest.
}

@Operation(summary = "05-02 Scrap📁 스크랩 취소 #FRAME", description = "스크랩을 취소하는 API입니다.")
@DeleteMapping("/{scrapId}")
public CommonResponse<ScrapResponse.DeleteDTO> delete(@PathVariable Long scrapId) {
Scrap deletedScrap = scrapCommandService.delete(scrapId);
@DeleteMapping("/briefings/{briefingId}/members/{memberId}")
public CommonResponse<ScrapResponse.DeleteDTO> delete(@PathVariable Long briefingId, @PathVariable Long memberId) {
Scrap deletedScrap = scrapCommandService.delete(briefingId, memberId);
return CommonResponse.onSuccess(ScrapConverter.toDeleteDTO(deletedScrap));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public Scrap create(ScrapRequest.CreateDTO request) {
return scrapRepository.save(scrap);
}

public Scrap delete(Long scrapId) {
Scrap scrap = scrapRepository.findById(scrapId)
public Scrap delete(Long briefingId, Long memberId) {
Scrap scrap = scrapRepository.findByBriefing_IdAndMember_Id(briefingId, memberId)
.orElseThrow(() -> new ScrapException(ErrorCode.SCRAP_NOT_FOUND));
scrapRepository.delete(scrap);
return scrap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface ScrapRepository extends JpaRepository<Scrap, Long> {

Optional<Scrap> findByBriefing_IdAndMember_Id(Long briefingId, Long memberId);

boolean existsByMember_IdAndBriefing_Id(Long memberId, Long briefingId);

List<Scrap> findByMember_Id(Long memberId);
Expand Down

0 comments on commit bdbff34

Please sign in to comment.