From e74c3e794fdbfa111d45ac706bc8bdf3b334b5ee Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 18:39:04 +0900 Subject: [PATCH 01/20] add: added table option --- .../postgresql/persistence/entity/CorrectionEntity.java | 1 + .../persistence/postgresql/persistence/entity/VisitEntity.java | 1 + 2 files changed, 2 insertions(+) diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/CorrectionEntity.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/CorrectionEntity.java index 9950f823..f213acd2 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/CorrectionEntity.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/CorrectionEntity.java @@ -9,6 +9,7 @@ import java.util.UUID; @Entity +@Table(name = "correction", schema = "smeem") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class CorrectionEntity extends BaseEntity { @Id diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/VisitEntity.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/VisitEntity.java index 295329aa..68bfc09b 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/VisitEntity.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/VisitEntity.java @@ -7,6 +7,7 @@ import java.time.LocalDate; @Entity +@Table(name = "visit", schema = "smeem") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class VisitEntity { @Id From 582d40e34be8b8f3a1e5c4af23ed0baf73920dc8 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 18:44:00 +0900 Subject: [PATCH 02/20] add: added method --- .../port/output/persistence/CorrectionPort.java | 6 ++++++ .../postgresql/adapter/CorrectionAdapter.java | 10 ++++++++++ .../repository/diary/CorrectionRepository.java | 3 +++ 3 files changed, 19 insertions(+) diff --git a/smeem-application/src/main/java/com/smeem/application/port/output/persistence/CorrectionPort.java b/smeem-application/src/main/java/com/smeem/application/port/output/persistence/CorrectionPort.java index a6e01210..7c2a7ea2 100644 --- a/smeem-application/src/main/java/com/smeem/application/port/output/persistence/CorrectionPort.java +++ b/smeem-application/src/main/java/com/smeem/application/port/output/persistence/CorrectionPort.java @@ -10,4 +10,10 @@ public interface CorrectionPort { List saveAll(List corrections, Diary diary); int countDistinctByMemberAndDate(long memberId, LocalDate date); + + //TODO: 일기 삭제, 일기 수정 + void deleteByDiary(long diaryId); + + //TODO: 회원탈퇴 + void deleteByMember(long memberId); } diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.java index 9b40a9e4..7a34ebea 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.java @@ -29,4 +29,14 @@ public List saveAll(List corrections, Diary diary) { public int countDistinctByMemberAndDate(long memberId, LocalDate date) { return correctionRepository.countDistinctKeyByMemberIdAndCreatedAt(memberId, date); } + + @Override + public void deleteByDiary(long diaryId) { + correctionRepository.deleteByDiaryId(diaryId); + } + + @Override + public void deleteByMember(long memberId) { + correctionRepository.deleteByMemberId(memberId); + } } diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/repository/diary/CorrectionRepository.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/repository/diary/CorrectionRepository.java index 538fe0f7..637e1e66 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/repository/diary/CorrectionRepository.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/repository/diary/CorrectionRepository.java @@ -5,4 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface CorrectionRepository extends JpaRepository, CorrectionCustomRepository { + void deleteByDiaryId(long diaryId); + + void deleteByMemberId(long memberId); } From 4ff11af11923850e738f43c700b31efe45ee8a4f Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 18:55:07 +0900 Subject: [PATCH 03/20] add: added corrections --- .../domain/diary/DiaryService.java | 8 ++++++- .../response/diary/RetrieveDiaryResponse.java | 24 ++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java b/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java index 009a2dd9..ded39a8c 100644 --- a/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java +++ b/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java @@ -4,6 +4,7 @@ import com.smeem.application.domain.badge.Badge; import com.smeem.application.domain.badge.BadgeType; import com.smeem.application.domain.member.Member; +import com.smeem.application.domain.topic.Topic; import com.smeem.application.port.input.DiaryUseCase; import com.smeem.application.port.input.dto.request.diary.WriteDiaryRequest; import com.smeem.application.port.input.dto.response.diary.RetrieveDiariesResponse; @@ -29,6 +30,7 @@ public class DiaryService implements DiaryUseCase { private final MemberBadgePort memberBadgePort; private final TopicPort topicPort; private final SmeemProperties smeemProperties; + private final CorrectionPort correctionPort; @Transactional public WriteDiaryResponse writeDiary(long memberId, WriteDiaryRequest request) { @@ -60,7 +62,11 @@ private List acquireBadgeOfWritingDiary(Member member) { } public RetrieveDiaryResponse retrieveDiary(long diaryId) { - return RetrieveDiaryResponse.of(diaryPort.findByIdJoinMemberAndTopic(diaryId)); + Diary diary = diaryPort.findById(diaryId); + Topic topic = diary.getTopicId() != null ? topicPort.findById(diary.getTopicId()) : null; + Member member = memberPort.findById(diary.getMemberId()); + List corrections = correctionPort.findByDiary(diaryId); + return RetrieveDiaryResponse.of(diary, topic, member, corrections); } @Transactional diff --git a/smeem-application/src/main/java/com/smeem/application/port/input/dto/response/diary/RetrieveDiaryResponse.java b/smeem-application/src/main/java/com/smeem/application/port/input/dto/response/diary/RetrieveDiaryResponse.java index 144f700d..6f982411 100644 --- a/smeem-application/src/main/java/com/smeem/application/port/input/dto/response/diary/RetrieveDiaryResponse.java +++ b/smeem-application/src/main/java/com/smeem/application/port/input/dto/response/diary/RetrieveDiaryResponse.java @@ -1,10 +1,16 @@ package com.smeem.application.port.input.dto.response.diary; +import com.smeem.application.domain.diary.Correction; import com.smeem.application.domain.diary.Diary; +import com.smeem.application.domain.member.Member; +import com.smeem.application.domain.topic.Topic; import com.smeem.common.util.SmeemConverter; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; import lombok.Builder; +import java.util.List; + import static lombok.AccessLevel.PRIVATE; @Builder(access = PRIVATE) @@ -18,18 +24,24 @@ public record RetrieveDiaryResponse( @Schema(description = "일기 작성일") String createdAt, @Schema(description = "일기 작성자 닉네임") - String username + String username, + @Schema(description = "코칭 결과 정보") + List corrections ) { - - public static RetrieveDiaryResponse of(Diary diary) { + public static RetrieveDiaryResponse of( + @NotNull Diary diary, + Topic topic, + @NotNull Member member, + @NotNull List corrections + ) { return RetrieveDiaryResponse.builder() .diaryId(diary.getId()) - .topic(diary.getTopic() != null ? diary.getTopic().getContent() : "") + .topic(topic != null ? topic.getContent() : "") .content(diary.getContent()) .createdAt(SmeemConverter.toString(diary.getCreatedAt())) - .username(diary.getMember().getUsername()) + .username(member.getUsername()) + .corrections(corrections) .build(); } - } From e6d40d31c7079e9ab7be356377eb9113f259a400 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:04:16 +0900 Subject: [PATCH 04/20] refactor: optimized finding from db --- .../application/port/output/persistence/TopicPort.java | 2 ++ .../smeem/persistence/postgresql/adapter/TopicAdapter.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/smeem-application/src/main/java/com/smeem/application/port/output/persistence/TopicPort.java b/smeem-application/src/main/java/com/smeem/application/port/output/persistence/TopicPort.java index 88966130..e9712bbe 100644 --- a/smeem-application/src/main/java/com/smeem/application/port/output/persistence/TopicPort.java +++ b/smeem-application/src/main/java/com/smeem/application/port/output/persistence/TopicPort.java @@ -5,4 +5,6 @@ public interface TopicPort { Topic findById(long id); Topic findRandom(); + + void checkValidation(long topicId); } diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/TopicAdapter.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/TopicAdapter.java index 7f11bd75..beda90d1 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/TopicAdapter.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/TopicAdapter.java @@ -24,6 +24,13 @@ public Topic findRandom() { return topicRepository.findRandom().toDomain(); } + @Override + public void checkValidation(long topicId) { + if (!topicRepository.existsById(topicId)) { + throw new SmeemException(ExceptionCode.NOT_FOUND, ": Topic ID=" + topicId); + } + } + private TopicEntity find(long id) { return topicRepository.findById(id) .orElseThrow(() -> new SmeemException( From 3361ec172e8d56ba4d55ba854ace907594793f0f Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:08:05 +0900 Subject: [PATCH 05/20] add: added validation of diary owner --- .../com/smeem/application/port/input/DiaryUseCase.java | 2 +- .../main/java/com/smeem/http/controller/DiaryApi.java | 10 +++++++--- .../com/smeem/http/controller/docs/DiaryApiDocs.java | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/smeem-application/src/main/java/com/smeem/application/port/input/DiaryUseCase.java b/smeem-application/src/main/java/com/smeem/application/port/input/DiaryUseCase.java index 4af2f4e8..2494e6fa 100644 --- a/smeem-application/src/main/java/com/smeem/application/port/input/DiaryUseCase.java +++ b/smeem-application/src/main/java/com/smeem/application/port/input/DiaryUseCase.java @@ -10,7 +10,7 @@ public interface DiaryUseCase { WriteDiaryResponse writeDiary(long memberId, WriteDiaryRequest request); RetrieveDiaryResponse retrieveDiary(long diaryId); - void modifyDiary(long diaryId, WriteDiaryRequest request); + void modifyDiary(long memberId, long diaryId, WriteDiaryRequest request); void deleteDiary(long diary); RetrieveDiariesResponse retrieveDiariesByTerm(long memberId, LocalDate startDate, LocalDate endDate); void deleteExpiredDiaries(int duration); diff --git a/smeem-input-http/src/main/java/com/smeem/http/controller/DiaryApi.java b/smeem-input-http/src/main/java/com/smeem/http/controller/DiaryApi.java index 715f96a6..2522f6c9 100644 --- a/smeem-input-http/src/main/java/com/smeem/http/controller/DiaryApi.java +++ b/smeem-input-http/src/main/java/com/smeem/http/controller/DiaryApi.java @@ -3,7 +3,6 @@ import com.smeem.application.domain.generic.SmeemMessage; import com.smeem.application.port.input.DiaryUseCase; import com.smeem.application.port.input.dto.request.diary.WriteDiaryRequest; -import com.smeem.application.port.input.dto.response.diary.CorrectionsResponse; import com.smeem.http.controller.dto.SmeemResponse; import com.smeem.application.port.input.dto.response.diary.RetrieveDiariesResponse; import com.smeem.application.port.input.dto.response.diary.RetrieveDiaryResponse; @@ -45,8 +44,13 @@ public SmeemResponse retrieveDiary(@PathVariable long dia @ResponseStatus(HttpStatus.OK) @PatchMapping("/{diaryId}") - public SmeemResponse modifyDiary(@PathVariable long diaryId, @RequestBody WriteDiaryRequest request) { - diaryUseCase.modifyDiary(diaryId, request); + public SmeemResponse modifyDiary( + Principal principal, + @PathVariable long diaryId, + @RequestBody WriteDiaryRequest request + ) { + long memberId = smeemConverter.toMemberId(principal); + diaryUseCase.modifyDiary(memberId, diaryId, request); return SmeemResponse.of(SmeemMessage.MODIFY_DIARY); } diff --git a/smeem-input-http/src/main/java/com/smeem/http/controller/docs/DiaryApiDocs.java b/smeem-input-http/src/main/java/com/smeem/http/controller/docs/DiaryApiDocs.java index 5d3764f3..55820860 100644 --- a/smeem-input-http/src/main/java/com/smeem/http/controller/docs/DiaryApiDocs.java +++ b/smeem-input-http/src/main/java/com/smeem/http/controller/docs/DiaryApiDocs.java @@ -59,6 +59,7 @@ SmeemResponse retrieveDiary( description = "OK success") }) SmeemResponse modifyDiary( + @Parameter(hidden = true) Principal principal, @Parameter( name = "diaryId", description = "수정할 일기 id", From 6c67f9f68338ca7e4fe6e2b9f35fd60357bbf01c Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:13:57 +0900 Subject: [PATCH 06/20] delete: deleted other domain --- .../main/java/com/smeem/application/domain/diary/Diary.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/smeem-application/src/main/java/com/smeem/application/domain/diary/Diary.java b/smeem-application/src/main/java/com/smeem/application/domain/diary/Diary.java index d1e4830b..6a1865a2 100644 --- a/smeem-application/src/main/java/com/smeem/application/domain/diary/Diary.java +++ b/smeem-application/src/main/java/com/smeem/application/domain/diary/Diary.java @@ -1,8 +1,6 @@ package com.smeem.application.domain.diary; import com.smeem.application.domain.generic.LangType; -import com.smeem.application.domain.member.Member; -import com.smeem.application.domain.topic.Topic; import com.smeem.common.exception.ExceptionCode; import com.smeem.common.exception.SmeemException; import lombok.Builder; @@ -16,8 +14,7 @@ public class Diary { private Long id; private String content; private LangType targetLang; - private Topic topic; - private Member member; + private Long topicId; private long memberId; private LocalDateTime createdAt; From 32ba5c4537bdb5b2ff6ba4ae8d97f8c229ea28dd Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:15:26 +0900 Subject: [PATCH 07/20] delete: deleted unused method --- .../port/output/persistence/DiaryPort.java | 1 - .../postgresql/adapter/DiaryAdapter.java | 26 ------------------- 2 files changed, 27 deletions(-) diff --git a/smeem-application/src/main/java/com/smeem/application/port/output/persistence/DiaryPort.java b/smeem-application/src/main/java/com/smeem/application/port/output/persistence/DiaryPort.java index 2ca8cc8a..c1de56ff 100644 --- a/smeem-application/src/main/java/com/smeem/application/port/output/persistence/DiaryPort.java +++ b/smeem-application/src/main/java/com/smeem/application/port/output/persistence/DiaryPort.java @@ -9,7 +9,6 @@ public interface DiaryPort { int countByMember(long memberId); Diary save(Diary diary); boolean isExistByMemberAndYesterday(long memberId); - Diary findByIdJoinMemberAndTopic(long id); Diary findById(long id); Diary update(Diary diary); void softDelete(long id); diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/DiaryAdapter.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/DiaryAdapter.java index 93d37560..f148d92f 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/DiaryAdapter.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/DiaryAdapter.java @@ -6,12 +6,8 @@ import com.smeem.common.exception.SmeemException; import com.smeem.persistence.postgresql.persistence.entity.DeletedDiaryEntity; import com.smeem.persistence.postgresql.persistence.entity.DiaryEntity; -import com.smeem.persistence.postgresql.persistence.entity.MemberEntity; -import com.smeem.persistence.postgresql.persistence.entity.TopicEntity; import com.smeem.persistence.postgresql.persistence.repository.DeletedDiaryRepository; import com.smeem.persistence.postgresql.persistence.repository.DiaryRepository; -import com.smeem.persistence.postgresql.persistence.repository.MemberRepository; -import com.smeem.persistence.postgresql.persistence.repository.TopicRepository; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Repository; @@ -23,8 +19,6 @@ @RequiredArgsConstructor public class DiaryAdapter implements DiaryPort { private final DiaryRepository diaryRepository; - private final MemberRepository memberRepository; - private final TopicRepository topicRepository; private final DeletedDiaryRepository deletedDiaryRepository; @Override @@ -42,14 +36,6 @@ public boolean isExistByMemberAndYesterday(long memberId) { return diaryRepository.existsByMemberIdAndYesterday(memberId); } - @Override - public Diary findByIdJoinMemberAndTopic(long id) { - val foundDiary = find(id); - val member = findByMemberId(foundDiary.getMemberId()).toDomain(); - val topic = foundDiary.getTopicId() != null ? findByTopicId(foundDiary.getTopicId()).toDomain() : null; - return foundDiary.toDomain(member, topic); - } - @Override public Diary findById(long id) { return find(id).toDomain(); @@ -95,16 +81,4 @@ private DiaryEntity find(long id) { return diaryRepository.findById(id) .orElseThrow(() -> new SmeemException(ExceptionCode.NOT_FOUND, "(Diary ID: " + id + ")")); } - - private MemberEntity findByMemberId(long id) { - return memberRepository.findById(id) - .orElseThrow(() -> new SmeemException(ExceptionCode.NOT_FOUND, "(Member ID: " + id + ")")); - } - - private TopicEntity findByTopicId(long id) { - return topicRepository.findById(id) - .orElseThrow(() -> new SmeemException( - ExceptionCode.NOT_FOUND, - "(서버 개발자에게 문의: Topic ID: " + id + ")")); - } } From 756ff1602b8aee42bafd8fb76c7ba33592d51770 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:16:00 +0900 Subject: [PATCH 08/20] fix: updated from refactored diary --- .../dto/request/diary/WriteDiaryRequest.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/smeem-application/src/main/java/com/smeem/application/port/input/dto/request/diary/WriteDiaryRequest.java b/smeem-application/src/main/java/com/smeem/application/port/input/dto/request/diary/WriteDiaryRequest.java index cebcbfab..da0e4bc0 100644 --- a/smeem-application/src/main/java/com/smeem/application/port/input/dto/request/diary/WriteDiaryRequest.java +++ b/smeem-application/src/main/java/com/smeem/application/port/input/dto/request/diary/WriteDiaryRequest.java @@ -2,7 +2,6 @@ import com.smeem.application.domain.diary.Diary; import com.smeem.application.domain.member.Member; -import com.smeem.application.domain.topic.Topic; import io.swagger.v3.oas.annotations.media.Schema; import lombok.NonNull; @@ -14,21 +13,21 @@ public record WriteDiaryRequest( Long topicId ) { - public Diary toDomain(Member member, Topic topic) { + public Diary toDomain(Member member) { return Diary.builder() .content(content) .targetLang(member.getTargetLang()) - .topic(topic) - .member(member) + .topicId(topicId) + .memberId(member.getId()) .build(); } - public Diary toDomain(Diary diary) { + public Diary toDomain(Diary originDiary) { return Diary.builder() - .id(diary.getId()) .content(content) - .targetLang(diary.getTargetLang()) - .topic(Topic.builder().id(topicId).build()) + .targetLang(originDiary.getTargetLang()) + .topicId(topicId) + .memberId(originDiary.getMemberId()) .build(); } } From fd8a9203f292476ba470e4e69c049b63de966d93 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:19:04 +0900 Subject: [PATCH 09/20] fix: updated diary for optimization --- .../domain/diary/DiaryService.java | 22 ++++++++----- .../postgresql/adapter/DiaryAdapter.java | 2 +- .../persistence/entity/DiaryEntity.java | 33 +++++-------------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java b/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java index ded39a8c..76a69629 100644 --- a/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java +++ b/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java @@ -24,19 +24,21 @@ @Transactional(readOnly = true) @RequiredArgsConstructor public class DiaryService implements DiaryUseCase { + private final CorrectionPort correctionPort; private final DiaryPort diaryPort; private final MemberPort memberPort; private final BadgePort badgePort; private final MemberBadgePort memberBadgePort; private final TopicPort topicPort; private final SmeemProperties smeemProperties; - private final CorrectionPort correctionPort; @Transactional public WriteDiaryResponse writeDiary(long memberId, WriteDiaryRequest request) { - val member = memberPort.findById(memberId); - val topic = request.topicId() != null ? topicPort.findById(request.topicId()) : null; - val savedDiary = diaryPort.save(request.toDomain(member, topic)); + Member member = memberPort.findById(memberId); + if (request.topicId() != null) { + topicPort.checkValidation(request.topicId()); + } + Diary savedDiary = diaryPort.save(request.toDomain(member)); val diaryWrittenYesterday = diaryPort.isExistByMemberAndYesterday(memberId); memberPort.update(member.updateDiaryComboCount(diaryWrittenYesterday)); @@ -70,15 +72,17 @@ public RetrieveDiaryResponse retrieveDiary(long diaryId) { } @Transactional - public void modifyDiary(long diaryId, WriteDiaryRequest request) { - val foundDiary = diaryPort.findById(diaryId); + public void modifyDiary(long memberId, long diaryId, WriteDiaryRequest request) { + Diary foundDiary = diaryPort.findById(diaryId); + foundDiary.validateDiaryOwnership(memberId); diaryPort.update(request.toDomain(foundDiary)); + correctionPort.deleteByDiary(diaryId); } @Transactional - public void deleteDiary(long diary) { - diaryPort.softDelete(diary); - //TODO: 코칭 정보 삭제 + public void deleteDiary(long diaryId) { + diaryPort.softDelete(diaryId); + correctionPort.deleteByDiary(diaryId); } public RetrieveDiariesResponse retrieveDiariesByTerm(long memberId, LocalDate startDate, LocalDate endDate) { diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/DiaryAdapter.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/DiaryAdapter.java index f148d92f..1d929f02 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/DiaryAdapter.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/DiaryAdapter.java @@ -28,7 +28,7 @@ public int countByMember(long memberId) { @Override public Diary save(Diary diary) { - return diaryRepository.save(DiaryEntity.of(diary)).toDomain(); + return diaryRepository.save(new DiaryEntity(diary)).toDomain(); } @Override diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/DiaryEntity.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/DiaryEntity.java index 54f42c2a..0325cec3 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/DiaryEntity.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/entity/DiaryEntity.java @@ -2,16 +2,12 @@ import com.smeem.application.domain.diary.Diary; import com.smeem.application.domain.generic.LangType; -import com.smeem.application.domain.member.Member; -import com.smeem.application.domain.topic.Topic; import jakarta.persistence.*; import lombok.*; @Entity @Table(name = "diary", schema = "smeem") -@Builder(access = AccessLevel.PRIVATE) -@NoArgsConstructor -@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class DiaryEntity extends BaseEntity { @Id @@ -26,13 +22,11 @@ public class DiaryEntity extends BaseEntity { @Column(nullable = false) private long memberId; - public static DiaryEntity of(Diary diary) { - return DiaryEntity.builder() - .content(diary.getContent()) - .targetLang(diary.getTargetLang()) - .topicId(diary.getTopic() != null ? diary.getTopic().getId() : null) - .memberId(diary.getMember().getId()) - .build(); + public DiaryEntity(Diary diary) { + this.content = diary.getContent(); + this.targetLang = diary.getTargetLang(); + this.topicId = diary.getTopicId(); + this.memberId = diary.getMemberId(); } public Diary toDomain() { @@ -40,26 +34,15 @@ public Diary toDomain() { .id(id) .content(content) .targetLang(targetLang) - .createdAt(createdAt) + .topicId(topicId) .memberId(memberId) - .build(); - } - - public Diary toDomain(Member member, Topic topic) { - return Diary.builder() - .id(id) - .content(content) - .targetLang(targetLang) .createdAt(createdAt) - .member(member) - .memberId(memberId) - .topic(topic) .build(); } public DiaryEntity update(Diary diary) { this.content = diary.getContent(); - this.topicId = diary.getTopic() != null ? diary.getTopic().getId() : null; + this.topicId = diary.getTopicId(); return this; } } From d9c24802081990bbf89ce378ac6ad01d3fa4a695 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:19:17 +0900 Subject: [PATCH 10/20] add: added method --- .../application/port/output/persistence/CorrectionPort.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smeem-application/src/main/java/com/smeem/application/port/output/persistence/CorrectionPort.java b/smeem-application/src/main/java/com/smeem/application/port/output/persistence/CorrectionPort.java index 7c2a7ea2..85a0cdde 100644 --- a/smeem-application/src/main/java/com/smeem/application/port/output/persistence/CorrectionPort.java +++ b/smeem-application/src/main/java/com/smeem/application/port/output/persistence/CorrectionPort.java @@ -11,7 +11,8 @@ public interface CorrectionPort { int countDistinctByMemberAndDate(long memberId, LocalDate date); - //TODO: 일기 삭제, 일기 수정 + List findByDiary(long diary); + void deleteByDiary(long diaryId); //TODO: 회원탈퇴 From a4993a26c29f3804a3f1658eed62561e40be534b Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:21:45 +0900 Subject: [PATCH 11/20] add: added implementation --- .../persistence/postgresql/adapter/CorrectionAdapter.java | 5 +++++ .../persistence/repository/diary/CorrectionRepository.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.java index 7a34ebea..571b290f 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/CorrectionAdapter.java @@ -30,6 +30,11 @@ public int countDistinctByMemberAndDate(long memberId, LocalDate date) { return correctionRepository.countDistinctKeyByMemberIdAndCreatedAt(memberId, date); } + @Override + public List findByDiary(long diaryId) { + return correctionRepository.findByDiaryId(diaryId).stream().map(CorrectionEntity::toDomain).toList(); + } + @Override public void deleteByDiary(long diaryId) { correctionRepository.deleteByDiaryId(diaryId); diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/repository/diary/CorrectionRepository.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/repository/diary/CorrectionRepository.java index 637e1e66..11a22a92 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/repository/diary/CorrectionRepository.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/persistence/repository/diary/CorrectionRepository.java @@ -4,8 +4,12 @@ import com.smeem.persistence.postgresql.persistence.repository.diary.custom.CorrectionCustomRepository; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface CorrectionRepository extends JpaRepository, CorrectionCustomRepository { void deleteByDiaryId(long diaryId); void deleteByMemberId(long memberId); + + List findByDiaryId(long diaryId); } From cfca92a6c2b89a0082ee6bd88007f3934a66e09d Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:22:42 +0900 Subject: [PATCH 12/20] delete: deleted completed task --- .../src/main/java/com/smeem/http/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smeem-input-http/src/main/java/com/smeem/http/config/SecurityConfig.java b/smeem-input-http/src/main/java/com/smeem/http/config/SecurityConfig.java index 2326b041..a0415f60 100644 --- a/smeem-input-http/src/main/java/com/smeem/http/config/SecurityConfig.java +++ b/smeem-input-http/src/main/java/com/smeem/http/config/SecurityConfig.java @@ -48,7 +48,7 @@ private void setHttp(HttpSecurity http) throws Exception { authorizeHttpRequests .requestMatchers(new AntPathRequestMatcher("/api/v2/auth", "POST")).permitAll() .requestMatchers(new AntPathRequestMatcher("/actuator/health")).permitAll() - .requestMatchers(new AntPathRequestMatcher("/api/v2/test")).permitAll() //TODO: 삭제 + .requestMatchers(new AntPathRequestMatcher("/api/v2/test")).permitAll() .requestMatchers(new AntPathRequestMatcher("/api/v2/versions/client/app")).permitAll() .requestMatchers(new AntPathRequestMatcher("/api/v2/goals/{type}")).permitAll() .requestMatchers(new AntPathRequestMatcher("/api/v2/goals")).permitAll() From dc1d6e0bbc458c3a960737fb2621805cc8997276 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:31:28 +0900 Subject: [PATCH 13/20] fix: updated exception message --- .../java/com/smeem/common/exception/SmeemException.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/smeem-common/src/main/java/com/smeem/common/exception/SmeemException.java b/smeem-common/src/main/java/com/smeem/common/exception/SmeemException.java index 66ea2513..06a6b83f 100644 --- a/smeem-common/src/main/java/com/smeem/common/exception/SmeemException.java +++ b/smeem-common/src/main/java/com/smeem/common/exception/SmeemException.java @@ -18,4 +18,11 @@ public SmeemException(ExceptionCode exceptionCode, String message) { this.defaultMessage = exceptionCode.getMessage(); this.detailMessage = message; } + + public String getMessage() { + if (detailMessage != null) { + return "[" + defaultMessage + "] " + detailMessage; + } + return defaultMessage; + } } From c88e02de25835b6dac83bed8c8a47524820f1994 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 19:59:11 +0900 Subject: [PATCH 14/20] fix: updated for visiting --- .../smeem/output/cache/redis/adapter/RedisCacheAdapter.java | 4 +++- .../src/main/resources/postgres-config/application-dev.yml | 2 +- .../src/main/resources/postgres-config/application-prod.yml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/smeem-output-cache/redis/src/main/java/com/smeem/output/cache/redis/adapter/RedisCacheAdapter.java b/smeem-output-cache/redis/src/main/java/com/smeem/output/cache/redis/adapter/RedisCacheAdapter.java index a3c31271..76f79c4d 100644 --- a/smeem-output-cache/redis/src/main/java/com/smeem/output/cache/redis/adapter/RedisCacheAdapter.java +++ b/smeem-output-cache/redis/src/main/java/com/smeem/output/cache/redis/adapter/RedisCacheAdapter.java @@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.core.RedisTemplate; +import java.util.Arrays; import java.util.Optional; //TODO: Redis 죽으면 어떻게 할 것인가? @@ -26,7 +27,8 @@ public boolean getBit(String key, long offset) { @Override public String getBitmap(String key) { - return redisTemplate.opsForValue().get(key); + byte[] arr = redisTemplate.execute(it -> it.stringCommands().get(key.getBytes()), true); + return Arrays.toString(arr); } @Override diff --git a/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-dev.yml b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-dev.yml index da69532b..6a014511 100644 --- a/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-dev.yml +++ b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-dev.yml @@ -13,7 +13,7 @@ spring: ddl-auto: validate properties: hibernate: - format_sql: true +# format_sql: true default_batch_fetch_size: 1000 auto_quote_keyword: true # generate_statistics: true diff --git a/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-prod.yml b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-prod.yml index 27ec4472..768c30fd 100644 --- a/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-prod.yml +++ b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-prod.yml @@ -13,7 +13,7 @@ spring: ddl-auto: validate properties: hibernate: - format_sql: true +# format_sql: true default_batch_fetch_size: 1000 auto_quote_keyword: true # generate_statistics: true From fd91c377430c780a5c2eb0ac8bffdddef3063d06 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 20:46:35 +0900 Subject: [PATCH 15/20] test: test region --- .github/workflows/deploy-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 194389c6..2d4b7650 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -25,7 +25,7 @@ jobs: with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }} aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }} - aws-region: ${{ secrets.AWS_REGION }} + aws-region: ap-northeast-2 # AWS 자격 증명 설정 - name: Set FCM JSON File Path From d98e9e8ee36c94ce5ed5cec558b01fee89dc03a4 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 20:51:57 +0900 Subject: [PATCH 16/20] test: ci --- .github/workflows/deploy-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 2d4b7650..194389c6 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -25,7 +25,7 @@ jobs: with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }} aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }} - aws-region: ap-northeast-2 + aws-region: ${{ secrets.AWS_REGION }} # AWS 자격 증명 설정 - name: Set FCM JSON File Path From ddde7ee42fef9abef06fbe5abecc14e8487139fa Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 21:16:05 +0900 Subject: [PATCH 17/20] test: ci --- .github/workflows/deploy-dev.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 194389c6..d3437ba3 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -23,9 +23,9 @@ jobs: - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }} - aws-region: ${{ secrets.AWS_REGION }} + aws-access-key-id: AKIAQ4NXP2SIBKMKH72W #${{ secrets.AWS_ACCESS_KEY_DEV }} + aws-secret-access-key: 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 #${{ secrets.AWS_SECRET_KEY_DEV }} + aws-region: ap-northeast-2 # AWS 자격 증명 설정 - name: Set FCM JSON File Path From f6cfa9331fd25d0a325e66b20729b301c60465f6 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 21:38:12 +0900 Subject: [PATCH 18/20] test: ci --- .github/workflows/deploy-dev.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index d3437ba3..bc9bbfae 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -20,11 +20,15 @@ jobs: java-version: '17' # 자바 버전을 JDK 17로 설정 + - name: Verify AWS Access Key Setup + run: + echo "AWS Access Key ID Length: ${{ secrets.AWS_ACCESS_KEY_DEV }}" + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 with: - aws-access-key-id: AKIAQ4NXP2SIBKMKH72W #${{ secrets.AWS_ACCESS_KEY_DEV }} - aws-secret-access-key: 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 #${{ secrets.AWS_SECRET_KEY_DEV }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }} aws-region: ap-northeast-2 # AWS 자격 증명 설정 From 683ee4e0e306f00be9619f21629b6c071b173d5b Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 21:41:33 +0900 Subject: [PATCH 19/20] test: ci --- .github/workflows/ci.yml | 6 +++--- .github/workflows/deploy-dev.yml | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25064b95..b67091c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout @@ -22,8 +22,8 @@ jobs: - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_DEV }} aws-region: ${{ secrets.AWS_REGION }} - name: Set FCM_JSON_PATH diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index bc9bbfae..2d4b7650 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -20,10 +20,6 @@ jobs: java-version: '17' # 자바 버전을 JDK 17로 설정 - - name: Verify AWS Access Key Setup - run: - echo "AWS Access Key ID Length: ${{ secrets.AWS_ACCESS_KEY_DEV }}" - - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 with: From d3c55b4c6d06eda6848a20ab95f3b13269e86e26 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 18 Oct 2024 21:48:12 +0900 Subject: [PATCH 20/20] fix: updated path --- .github/workflows/ci.yml | 4 +--- .github/workflows/deploy-dev.yml | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b67091c8..715cf16c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,12 +28,10 @@ jobs: - name: Set FCM_JSON_PATH run: | - echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/ \ - smeem_fcm_dev.json" >> $GITHUB_ENV + echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_dev.json" >> $GITHUB_ENV - name: Create FireBase JSON file From AWS run: aws s3 cp --region ap-northeast-2 ${{ secrets.AWS_S3_FCM_JSON_URI_DEV }} ${{ env.FCM_JSON_PATH }} - - name: Grant execute permission for gradlew run: chmod +x ./gradlew shell: bash diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 2d4b7650..1694397a 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -30,8 +30,7 @@ jobs: - name: Set FCM JSON File Path run: | - echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/ \ - smeem_fcm_dev.json" >> $GITHUB_ENV + echo "FCM_JSON_PATH=smeem-output-notification/src/main/resources/firebase-config/smeem_fcm_dev.json" >> $GITHUB_ENV # FCM JSON 파일 위치 경로 설정 - name: Create FCM JSON File from AWS