-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
175 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package briefing.scrap.application.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import briefing.scrap.domain.Scrap; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class ScrapV2 extends Scrap { | ||
private Integer scrapCount; | ||
private Boolean isScrap; | ||
private LocalDateTime createdAt; | ||
|
||
private ScrapV2(Scrap scrap, Integer scrapCount, Boolean isScrap) { | ||
super(scrap.getId(), scrap.getMember(), scrap.getBriefing()); | ||
this.scrapCount = scrapCount; | ||
this.isScrap = isScrap; | ||
this.createdAt = scrap.getCreatedAt(); | ||
} | ||
|
||
public static ScrapV2 of(Scrap scrap, Integer scrapCount, Boolean isScrap) { | ||
return new ScrapV2(scrap, scrapCount, isScrap); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/briefing/scrap/application/strategy/helper/ScrapCreationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package briefing.scrap.application.strategy.helper; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import briefing.briefing.domain.Briefing; | ||
import briefing.briefing.domain.repository.BriefingRepository; | ||
import briefing.exception.ErrorCode; | ||
import briefing.exception.handler.BriefingException; | ||
import briefing.member.domain.Member; | ||
import briefing.member.domain.repository.MemberRepository; | ||
import briefing.member.exception.MemberException; | ||
import briefing.scrap.api.ScrapConverter; | ||
import briefing.scrap.application.dto.ScrapRequest; | ||
import briefing.scrap.domain.Scrap; | ||
import briefing.scrap.domain.repository.ScrapRepository; | ||
import briefing.scrap.exception.ScrapException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ScrapCreationHelper { | ||
private final ScrapRepository scrapRepository; | ||
private final MemberRepository memberRepository; | ||
private final BriefingRepository briefingRepository; | ||
|
||
public Scrap createScrap(ScrapRequest.CreateDTO request) { | ||
if (scrapRepository.existsByMember_IdAndBriefing_Id( | ||
request.getMemberId(), request.getBriefingId())) | ||
throw new ScrapException(ErrorCode.SCRAP_ALREADY_EXISTS); | ||
|
||
Member member = | ||
memberRepository | ||
.findById(request.getMemberId()) | ||
.orElseThrow(() -> new MemberException(ErrorCode.MEMBER_NOT_FOUND)); | ||
|
||
Briefing briefing = | ||
briefingRepository | ||
.findById(request.getBriefingId()) | ||
.orElseThrow(() -> new BriefingException(ErrorCode.NOT_FOUND_BRIEFING)); | ||
|
||
return ScrapConverter.toScrap(member, briefing); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/briefing/scrap/application/strategy/helper/ScrapDeletionHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package briefing.scrap.application.strategy.helper; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import briefing.exception.ErrorCode; | ||
import briefing.scrap.domain.Scrap; | ||
import briefing.scrap.domain.repository.ScrapRepository; | ||
import briefing.scrap.exception.ScrapException; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ScrapDeletionHelper { | ||
private final ScrapRepository scrapRepository; | ||
|
||
public Scrap deleteScrap(Long briefingId, Long memberId) { | ||
Scrap scrap = | ||
scrapRepository | ||
.findByBriefing_IdAndMember_Id(briefingId, memberId) | ||
.orElseThrow(() -> new ScrapException(ErrorCode.SCRAP_NOT_FOUND)); | ||
scrapRepository.delete(scrap); | ||
return scrap; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/briefing/scrap/domain/repository/ScrapCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package briefing.scrap.domain.repository; | ||
|
||
public interface ScrapCustomRepository {} |
6 changes: 6 additions & 0 deletions
6
src/main/java/briefing/scrap/domain/repository/ScrapCustomRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package briefing.scrap.domain.repository; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class ScrapCustomRepositoryImpl implements ScrapCustomRepository {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters