From 0515233285e8ef28001f946a5e1cf097918419ce Mon Sep 17 00:00:00 2001 From: Cho-D-YoungRae <49931252+Cho-D-YoungRae@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:26:24 +0900 Subject: [PATCH] Feature/#143 remove auditor aware (#144) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Notice 도메인 에러 적용 * prune: 불필요한 도메인 클래스 제거 * fix: CreatorId JoinColumn 제거 * feat: Image 생성자 Creator 추가 * feat: LostItem Creator 생성자에 추가 * feat: Party 생성자 CreatorId 추가 * feat: Report 생성자 CreatorId 추가 * feat: Review 생성자 CreatorId 추가 * feat: AuditorAware 제거 --- .../domain/core/BaseCreatedByEntity.java | 19 --------- .../curtaincall/domain/core/BaseEntity.java | 9 ++--- .../domain/core/DomainErrorCode.java | 18 --------- .../domain/core/DomainException.java | 31 -------------- .../cmc/curtaincall/domain/image/Image.java | 12 ++++-- .../curtaincall/domain/lostitem/LostItem.java | 20 ++++++---- .../notice/exception/NoticeErrorCode.java | 19 +++++++++ .../exception/NoticeNotFoundException.java | 11 +++++ .../cmc/curtaincall/domain/party/Party.java | 16 +++++--- .../cmc/curtaincall/domain/report/Report.java | 4 +- .../curtaincall/domain/review/ShowReview.java | 4 +- .../domain/common/AbstractDataJpaTest.java | 6 --- .../lostitem/dao/LostItemExistsDaoTest.java | 14 ++----- .../domain/member/dao/MemberDaoTest.java | 9 +---- .../domain/review/ShowReviewTest.java | 17 ++++---- .../domain/review/dao/ShowReviewDaoTest.java | 26 ++++++------ .../review/dao/ShowReviewExistsDaoTest.java | 18 ++------- web/src/docs/asciidoc/showreview.adoc | 8 ---- .../web/common/config/AppConfig.java | 9 ----- .../config/LoginMemberAuditorAware.java | 40 ------------------- .../web/controller/ImageController.java | 8 ++-- .../web/lostitem/LostItemController.java | 2 +- .../web/lostitem/LostItemService.java | 4 +- .../curtaincall/web/notice/NoticeService.java | 2 +- .../exception/NoticeNotFoundException.java | 17 -------- .../web/party/PartyController.java | 6 ++- .../curtaincall/web/party/PartyService.java | 4 +- .../web/report/ReportController.java | 7 +++- .../curtaincall/web/report/ReportService.java | 4 +- .../web/review/ShowReviewController.java | 9 ----- .../web/review/ShowReviewService.java | 14 +------ .../web/service/image/ImageService.java | 4 +- .../controller/ImageControllerDocsTest.java | 2 +- .../lostitem/LostItemControllerDocsTest.java | 2 +- .../web/party/PartyControllerDocsTest.java | 2 +- .../web/party/PartyControllerTest.java | 8 ++-- .../review/ShowReviewControllerDocsTest.java | 39 ------------------ 37 files changed, 136 insertions(+), 308 deletions(-) delete mode 100644 domain/src/main/java/org/cmc/curtaincall/domain/core/BaseCreatedByEntity.java delete mode 100644 domain/src/main/java/org/cmc/curtaincall/domain/core/DomainErrorCode.java delete mode 100644 domain/src/main/java/org/cmc/curtaincall/domain/core/DomainException.java create mode 100644 domain/src/main/java/org/cmc/curtaincall/domain/notice/exception/NoticeErrorCode.java create mode 100644 domain/src/main/java/org/cmc/curtaincall/domain/notice/exception/NoticeNotFoundException.java delete mode 100644 web/src/main/java/org/cmc/curtaincall/web/common/config/LoginMemberAuditorAware.java delete mode 100644 web/src/main/java/org/cmc/curtaincall/web/notice/exception/NoticeNotFoundException.java diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/core/BaseCreatedByEntity.java b/domain/src/main/java/org/cmc/curtaincall/domain/core/BaseCreatedByEntity.java deleted file mode 100644 index bcf435ef..00000000 --- a/domain/src/main/java/org/cmc/curtaincall/domain/core/BaseCreatedByEntity.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.cmc.curtaincall.domain.core; - -import jakarta.persistence.*; -import lombok.Getter; -import org.cmc.curtaincall.domain.member.Member; -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -@Getter -@MappedSuperclass -@EntityListeners(AuditingEntityListener.class) -public abstract class BaseCreatedByEntity { - - @CreatedBy - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "created_by", updatable = false, - foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private Member createdBy; -} diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/core/BaseEntity.java b/domain/src/main/java/org/cmc/curtaincall/domain/core/BaseEntity.java index 1624b4fc..52ee75d4 100644 --- a/domain/src/main/java/org/cmc/curtaincall/domain/core/BaseEntity.java +++ b/domain/src/main/java/org/cmc/curtaincall/domain/core/BaseEntity.java @@ -1,16 +1,15 @@ package org.cmc.curtaincall.domain.core; -import jakarta.persistence.*; +import jakarta.persistence.Embedded; +import jakarta.persistence.MappedSuperclass; import lombok.Getter; import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @MappedSuperclass -@EntityListeners(AuditingEntityListener.class) public abstract class BaseEntity extends BaseTimeEntity { @CreatedBy - @JoinColumn(name = "created_by", updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private CreatorId createdBy; + @Embedded + protected CreatorId createdBy; } diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/core/DomainErrorCode.java b/domain/src/main/java/org/cmc/curtaincall/domain/core/DomainErrorCode.java deleted file mode 100644 index e17cc5fd..00000000 --- a/domain/src/main/java/org/cmc/curtaincall/domain/core/DomainErrorCode.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.cmc.curtaincall.domain.core; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum DomainErrorCode { - - BAD_REQUEST(400), - FORBIDDEN(403), - NOT_FOUND(404), - CONFLICT(409), - INTERNAL_SERVER_ERROR(500) - ; - - private final int status; -} diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/core/DomainException.java b/domain/src/main/java/org/cmc/curtaincall/domain/core/DomainException.java deleted file mode 100644 index 641d6be6..00000000 --- a/domain/src/main/java/org/cmc/curtaincall/domain/core/DomainException.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.cmc.curtaincall.domain.core; - -import lombok.Getter; - -@Getter -public abstract class DomainException extends RuntimeException { - - protected final DomainErrorCode code; - - protected DomainException(DomainErrorCode code) { - super(); - this.code = code; - } - - protected DomainException(DomainErrorCode code, String message) { - super(message); - this.code = code; - } - - protected DomainException(DomainErrorCode code, String message, Throwable cause) { - super(message, cause); - this.code = code; - } - - protected DomainException(DomainErrorCode code, Throwable cause) { - super(cause); - this.code = code; - } - - public abstract String getExternalMessage(); -} diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/image/Image.java b/domain/src/main/java/org/cmc/curtaincall/domain/image/Image.java index 819ca662..9d38e80b 100644 --- a/domain/src/main/java/org/cmc/curtaincall/domain/image/Image.java +++ b/domain/src/main/java/org/cmc/curtaincall/domain/image/Image.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.cmc.curtaincall.domain.core.BaseEntity; +import org.cmc.curtaincall.domain.core.CreatorId; @Entity @Table(name = "images") @@ -28,12 +29,15 @@ public class Image extends BaseEntity { private String url; @Builder - private Image( - String originName, - String storedName, - String url) { + public Image( + final String originName, + final String storedName, + final String url, + final CreatorId createdBy + ) { this.originName = originName; this.storedName = storedName; this.url = url; + this.createdBy = createdBy; } } diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/lostitem/LostItem.java b/domain/src/main/java/org/cmc/curtaincall/domain/lostitem/LostItem.java index 5eacc5f3..843c1ef2 100644 --- a/domain/src/main/java/org/cmc/curtaincall/domain/lostitem/LostItem.java +++ b/domain/src/main/java/org/cmc/curtaincall/domain/lostitem/LostItem.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.cmc.curtaincall.domain.core.BaseEntity; +import org.cmc.curtaincall.domain.core.CreatorId; import org.cmc.curtaincall.domain.image.Image; import org.cmc.curtaincall.domain.show.FacilityId; @@ -67,14 +68,16 @@ public class LostItem extends BaseEntity { @Builder public LostItem( - FacilityId facilityId, - Image image, - String title, - LostItemType type, - String foundPlaceDetail, - LocalDate foundDate, - @Nullable LocalTime foundTime, - String particulars) { + final FacilityId facilityId, + final Image image, + final String title, + final LostItemType type, + final String foundPlaceDetail, + final LocalDate foundDate, + final @Nullable LocalTime foundTime, + final String particulars, + final CreatorId createdBy + ) { this.facilityId = facilityId; this.image = image; this.title = title; @@ -83,6 +86,7 @@ public LostItem( this.foundDate = foundDate; this.foundTime = foundTime; this.particulars = particulars; + this.createdBy = createdBy; } public LostItemEditor.LostItemEditorBuilder toEditor() { diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/notice/exception/NoticeErrorCode.java b/domain/src/main/java/org/cmc/curtaincall/domain/notice/exception/NoticeErrorCode.java new file mode 100644 index 00000000..bd6c9ca1 --- /dev/null +++ b/domain/src/main/java/org/cmc/curtaincall/domain/notice/exception/NoticeErrorCode.java @@ -0,0 +1,19 @@ +package org.cmc.curtaincall.domain.notice.exception; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.cmc.curtaincall.domain.core.ErrorCodeType; + +@Getter +@RequiredArgsConstructor +public enum NoticeErrorCode implements ErrorCodeType { + + NOT_FOUND("NOTICE-001", "존재하지 않는 공지입니다.", 404), + ; + + private final String code; + + private final String message; + + private final int status; +} diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/notice/exception/NoticeNotFoundException.java b/domain/src/main/java/org/cmc/curtaincall/domain/notice/exception/NoticeNotFoundException.java new file mode 100644 index 00000000..9a8f299f --- /dev/null +++ b/domain/src/main/java/org/cmc/curtaincall/domain/notice/exception/NoticeNotFoundException.java @@ -0,0 +1,11 @@ +package org.cmc.curtaincall.domain.notice.exception; + +import org.cmc.curtaincall.domain.core.AbstractDomainException; +import org.cmc.curtaincall.domain.notice.NoticeId; + +public class NoticeNotFoundException extends AbstractDomainException { + + public NoticeNotFoundException(final NoticeId noticeId) { + super(NoticeErrorCode.NOT_FOUND, "NoticeId=" + noticeId); + } +} diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/party/Party.java b/domain/src/main/java/org/cmc/curtaincall/domain/party/Party.java index c4e3710f..17447f22 100644 --- a/domain/src/main/java/org/cmc/curtaincall/domain/party/Party.java +++ b/domain/src/main/java/org/cmc/curtaincall/domain/party/Party.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.cmc.curtaincall.domain.core.BaseEntity; +import org.cmc.curtaincall.domain.core.CreatorId; import org.cmc.curtaincall.domain.member.MemberId; import org.cmc.curtaincall.domain.party.exception.PartyAlreadyClosedException; import org.cmc.curtaincall.domain.party.exception.PartyAlreadyParticipatedException; @@ -71,18 +72,21 @@ public class Party extends BaseEntity { @Builder public Party( - ShowId showId, - LocalDateTime partyAt, - String title, - String content, - Integer maxMemberNum, - PartyCategory category) { + final ShowId showId, + final LocalDateTime partyAt, + final String title, + final String content, + final Integer maxMemberNum, + final PartyCategory category, + final CreatorId createdBy + ) { this.showId = showId; this.partyAt = partyAt; this.title = title; this.content = content; this.maxMemberNum = maxMemberNum; this.category = category; + this.createdBy = createdBy; if (category == PartyCategory.ETC) { this.showId = null; diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/report/Report.java b/domain/src/main/java/org/cmc/curtaincall/domain/report/Report.java index 54aa4fbc..f340284c 100644 --- a/domain/src/main/java/org/cmc/curtaincall/domain/report/Report.java +++ b/domain/src/main/java/org/cmc/curtaincall/domain/report/Report.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.cmc.curtaincall.domain.core.BaseEntity; +import org.cmc.curtaincall.domain.core.CreatorId; @Entity @Table(name = "report") @@ -33,10 +34,11 @@ public class Report extends BaseEntity { private ReportType type; @Builder - private Report(String content, Long reportedId, ReportReason reason, ReportType type) { + private Report(String content, Long reportedId, ReportReason reason, ReportType type, CreatorId createdBy) { this.content = content; this.reportedId = reportedId; this.reason = reason; this.type = type; + this.createdBy = createdBy; } } diff --git a/domain/src/main/java/org/cmc/curtaincall/domain/review/ShowReview.java b/domain/src/main/java/org/cmc/curtaincall/domain/review/ShowReview.java index e7548d96..69c09585 100644 --- a/domain/src/main/java/org/cmc/curtaincall/domain/review/ShowReview.java +++ b/domain/src/main/java/org/cmc/curtaincall/domain/review/ShowReview.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.cmc.curtaincall.domain.core.BaseEntity; +import org.cmc.curtaincall.domain.core.CreatorId; import org.cmc.curtaincall.domain.member.MemberId; import org.cmc.curtaincall.domain.review.exception.ShowReviewInvalidGradeException; import org.cmc.curtaincall.domain.review.repository.ShowReviewLikeRepository; @@ -52,7 +53,7 @@ public class ShowReview extends BaseEntity { private Integer likeCount; @Builder - public ShowReview(final ShowId showId, final int grade, final String content) { + public ShowReview(final ShowId showId, final int grade, final String content, final CreatorId createdBy) { if (isInGradeRange(grade)) { throw new ShowReviewInvalidGradeException(grade); } @@ -60,6 +61,7 @@ public ShowReview(final ShowId showId, final int grade, final String content) { this.grade = grade; this.content = content; this.likeCount = 0; + this.createdBy = createdBy; } private boolean isInGradeRange(int grade) { diff --git a/domain/src/test/java/org/cmc/curtaincall/domain/common/AbstractDataJpaTest.java b/domain/src/test/java/org/cmc/curtaincall/domain/common/AbstractDataJpaTest.java index 735378de..db005ebb 100644 --- a/domain/src/test/java/org/cmc/curtaincall/domain/common/AbstractDataJpaTest.java +++ b/domain/src/test/java/org/cmc/curtaincall/domain/common/AbstractDataJpaTest.java @@ -1,12 +1,9 @@ package org.cmc.curtaincall.domain.common; import jakarta.persistence.EntityManager; -import org.cmc.curtaincall.domain.core.CreatorId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; -import org.springframework.data.domain.AuditorAware; import org.springframework.transaction.annotation.Transactional; @DataJpaTest @@ -16,7 +13,4 @@ public abstract class AbstractDataJpaTest { @Autowired protected EntityManager em; - - @MockBean - protected AuditorAware auditorProvider; } diff --git a/domain/src/test/java/org/cmc/curtaincall/domain/lostitem/dao/LostItemExistsDaoTest.java b/domain/src/test/java/org/cmc/curtaincall/domain/lostitem/dao/LostItemExistsDaoTest.java index 6b1edae2..1d2aa950 100644 --- a/domain/src/test/java/org/cmc/curtaincall/domain/lostitem/dao/LostItemExistsDaoTest.java +++ b/domain/src/test/java/org/cmc/curtaincall/domain/lostitem/dao/LostItemExistsDaoTest.java @@ -14,10 +14,8 @@ import java.time.LocalDate; import java.time.LocalTime; -import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; @Import(LostItemExistsDao.class) class LostItemExistsDaoTest extends AbstractDataJpaTest { @@ -28,9 +26,6 @@ class LostItemExistsDaoTest extends AbstractDataJpaTest { @Test void existsByIdAndCreatedBy() { // given - given(auditorProvider.getCurrentAuditor()).willReturn( - Optional.of(new CreatorId(new MemberId(20L)))); - LostItem lostItem = LostItem.builder() .facilityId(new FacilityId("facility-id")) .image(em.getReference(Image.class, 10L)) @@ -40,6 +35,7 @@ void existsByIdAndCreatedBy() { .foundDate(LocalDate.of(2023, 11, 4)) .foundTime(LocalTime.of(0, 37)) .particulars("particulars") + .createdBy(new CreatorId(new MemberId(20L))) .build(); em.persist(lostItem); @@ -55,9 +51,6 @@ void existsByIdAndCreatedBy() { @Test void existsByIdAndCreatedBy_IdDifferent() { // given - given(auditorProvider.getCurrentAuditor()).willReturn( - Optional.of(new CreatorId(new MemberId(20L)))); - LostItem lostItem = LostItem.builder() .facilityId(new FacilityId("facility-id")) .image(em.getReference(Image.class, 10L)) @@ -67,6 +60,7 @@ void existsByIdAndCreatedBy_IdDifferent() { .foundDate(LocalDate.of(2023, 11, 4)) .foundTime(LocalTime.of(0, 37)) .particulars("particulars") + .createdBy(new CreatorId(new MemberId(20L))) .build(); em.persist(lostItem); @@ -82,9 +76,6 @@ void existsByIdAndCreatedBy_IdDifferent() { @Test void existsByIdAndCreatedBy_CreatedByDifferent() { // given - given(auditorProvider.getCurrentAuditor()).willReturn( - Optional.of(new CreatorId(new MemberId(20L)))); - LostItem lostItem = LostItem.builder() .facilityId(new FacilityId("facility-id")) .image(em.getReference(Image.class, 10L)) @@ -94,6 +85,7 @@ void existsByIdAndCreatedBy_CreatedByDifferent() { .foundDate(LocalDate.of(2023, 11, 4)) .foundTime(LocalTime.of(0, 37)) .particulars("particulars") + .createdBy(new CreatorId(new MemberId(20L))) .build(); em.persist(lostItem); diff --git a/domain/src/test/java/org/cmc/curtaincall/domain/member/dao/MemberDaoTest.java b/domain/src/test/java/org/cmc/curtaincall/domain/member/dao/MemberDaoTest.java index ec7a64dd..75aebceb 100644 --- a/domain/src/test/java/org/cmc/curtaincall/domain/member/dao/MemberDaoTest.java +++ b/domain/src/test/java/org/cmc/curtaincall/domain/member/dao/MemberDaoTest.java @@ -13,11 +13,8 @@ import org.springframework.context.annotation.Import; import java.time.LocalDateTime; -import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.BDDMockito.given; @Import(MemberDao.class) class MemberDaoTest extends AbstractDataJpaTest { @@ -40,9 +37,8 @@ void getDetail() { .content("content") .maxMemberNum(5) .category(PartyCategory.WATCHING) + .createdBy(new CreatorId(new MemberId(member.getId()))) .build(); - given(auditorProvider.getCurrentAuditor()) - .willReturn(Optional.of(new CreatorId(new MemberId(member.getId())))); em.persist(party); // when @@ -72,9 +68,8 @@ void getDetail_given_recruiting_party_delete_then_recruiting_num_zero() { .content("content") .maxMemberNum(5) .category(PartyCategory.WATCHING) + .createdBy(new CreatorId(new MemberId(member.getId()))) .build(); - given(auditorProvider.getCurrentAuditor()) - .willReturn(Optional.of(new CreatorId(new MemberId(member.getId())))); em.persist(party); party.delete(); diff --git a/domain/src/test/java/org/cmc/curtaincall/domain/review/ShowReviewTest.java b/domain/src/test/java/org/cmc/curtaincall/domain/review/ShowReviewTest.java index a202d2bc..913613f7 100644 --- a/domain/src/test/java/org/cmc/curtaincall/domain/review/ShowReviewTest.java +++ b/domain/src/test/java/org/cmc/curtaincall/domain/review/ShowReviewTest.java @@ -1,5 +1,6 @@ package org.cmc.curtaincall.domain.review; +import org.cmc.curtaincall.domain.core.CreatorId; import org.cmc.curtaincall.domain.review.exception.ShowReviewInvalidGradeException; import org.cmc.curtaincall.domain.show.ShowId; import org.junit.jupiter.api.Test; @@ -11,30 +12,30 @@ class ShowReviewTest { @Test void create_Success() { - assertThatCode(() -> new ShowReview(new ShowId("show-id"), 0, "content")) + assertThatCode(() -> new ShowReview(new ShowId("show-id"), 0, "content", new CreatorId(1L))) .doesNotThrowAnyException(); - assertThatCode(() -> new ShowReview(new ShowId("show-id"), 1, "content")) + assertThatCode(() -> new ShowReview(new ShowId("show-id"), 1, "content", new CreatorId(1L))) .doesNotThrowAnyException(); - assertThatCode(() -> new ShowReview(new ShowId("show-id"), 2, "content")) + assertThatCode(() -> new ShowReview(new ShowId("show-id"), 2, "content", new CreatorId(1L))) .doesNotThrowAnyException(); - assertThatCode(() -> new ShowReview(new ShowId("show-id"), 3, "content")) + assertThatCode(() -> new ShowReview(new ShowId("show-id"), 3, "content", new CreatorId(1L))) .doesNotThrowAnyException(); - assertThatCode(() -> new ShowReview(new ShowId("show-id"), 4, "content")) + assertThatCode(() -> new ShowReview(new ShowId("show-id"), 4, "content", new CreatorId(1L))) .doesNotThrowAnyException(); - assertThatCode(() -> new ShowReview(new ShowId("show-id"), 5, "content")) + assertThatCode(() -> new ShowReview(new ShowId("show-id"), 5, "content", new CreatorId(1L))) .doesNotThrowAnyException(); } @Test void create_GradeGreaterThan5() { - assertThatThrownBy(() -> new ShowReview(new ShowId("show-id"), 6, "content")) + assertThatThrownBy(() -> new ShowReview(new ShowId("show-id"), 6, "content", new CreatorId(1L))) .isInstanceOf(ShowReviewInvalidGradeException.class); } @Test void create_GradeLessThan0() { - assertThatThrownBy(() -> new ShowReview(new ShowId("show-id"), -1, "content")) + assertThatThrownBy(() -> new ShowReview(new ShowId("show-id"), -1, "content", new CreatorId(1L))) .isInstanceOf(ShowReviewInvalidGradeException.class); } } \ No newline at end of file diff --git a/domain/src/test/java/org/cmc/curtaincall/domain/review/dao/ShowReviewDaoTest.java b/domain/src/test/java/org/cmc/curtaincall/domain/review/dao/ShowReviewDaoTest.java index e68a38d9..47bae020 100644 --- a/domain/src/test/java/org/cmc/curtaincall/domain/review/dao/ShowReviewDaoTest.java +++ b/domain/src/test/java/org/cmc/curtaincall/domain/review/dao/ShowReviewDaoTest.java @@ -8,7 +8,12 @@ import org.cmc.curtaincall.domain.review.repository.ShowReviewLikeRepository; import org.cmc.curtaincall.domain.review.response.ShowReviewMyResponse; import org.cmc.curtaincall.domain.review.response.ShowReviewResponse; -import org.cmc.curtaincall.domain.show.*; +import org.cmc.curtaincall.domain.show.Facility; +import org.cmc.curtaincall.domain.show.FacilityId; +import org.cmc.curtaincall.domain.show.Show; +import org.cmc.curtaincall.domain.show.ShowGenre; +import org.cmc.curtaincall.domain.show.ShowId; +import org.cmc.curtaincall.domain.show.ShowState; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Import; @@ -17,10 +22,8 @@ import java.time.LocalDate; import java.util.List; -import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; @Import(ShowReviewDao.class) class ShowReviewDaoTest extends AbstractDataJpaTest { @@ -38,24 +41,24 @@ void getList() { .nickname("test-nickname") .build(); em.persist(member); - given(auditorProvider.getCurrentAuditor()).willReturn( - Optional.of(new CreatorId(new MemberId(member.getId())))); - List showReviews = List.of( ShowReview.builder() .showId(new ShowId("test-show-id")) .grade(1) .content("test-content-1") + .createdBy(new CreatorId(new MemberId(member.getId()))) .build(), ShowReview.builder() .showId(new ShowId("test-show-id")) .grade(2) .content("test-content-2") + .createdBy(new CreatorId(new MemberId(member.getId()))) .build(), ShowReview.builder() .showId(new ShowId("different")) .grade(3) .content("test-content-3") + .createdBy(new CreatorId(new MemberId(member.getId()))) .build() ); showReviews.forEach(em::persist); @@ -81,19 +84,18 @@ void getList_LikeCountOrderDesc() { .nickname("test-nickname") .build(); em.persist(member); - given(auditorProvider.getCurrentAuditor()).willReturn( - Optional.of(new CreatorId(new MemberId(member.getId())))); - List showReviews = List.of( ShowReview.builder() .showId(new ShowId("test-show-id")) .grade(1) .content("test-content-1") + .createdBy(new CreatorId(new MemberId(member.getId()))) .build(), ShowReview.builder() .showId(new ShowId("test-show-id")) .grade(2) .content("test-content-2") + .createdBy(new CreatorId(new MemberId(member.getId()))) .build() ); showReviews.forEach(em::persist); @@ -135,21 +137,19 @@ void getMyList() { .genre(ShowGenre.MUSICAL) .build() ); - given(auditorProvider.getCurrentAuditor()).willReturn(Optional.of(new CreatorId(new MemberId(10L)))); - ShowReview showReview1 = ShowReview.builder() .showId(new ShowId("show-id")) .grade(1) .content("test-content-1") + .createdBy(new CreatorId(new MemberId(10L))) .build(); em.persist(showReview1); - given(auditorProvider.getCurrentAuditor()).willReturn(Optional.of(new CreatorId(new MemberId(20L)))); - ShowReview showReview2 = ShowReview.builder() .showId(new ShowId("test-show-id")) .grade(2) .content("test-content-2") + .createdBy(new CreatorId(new MemberId(20L))) .build(); em.persist(showReview2); diff --git a/domain/src/test/java/org/cmc/curtaincall/domain/review/dao/ShowReviewExistsDaoTest.java b/domain/src/test/java/org/cmc/curtaincall/domain/review/dao/ShowReviewExistsDaoTest.java index 42990c81..1bee4a73 100644 --- a/domain/src/test/java/org/cmc/curtaincall/domain/review/dao/ShowReviewExistsDaoTest.java +++ b/domain/src/test/java/org/cmc/curtaincall/domain/review/dao/ShowReviewExistsDaoTest.java @@ -10,10 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Import; -import java.util.Optional; - import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; @Import(ShowReviewExistsDao.class) class ShowReviewExistsDaoTest extends AbstractDataJpaTest { @@ -24,10 +21,7 @@ class ShowReviewExistsDaoTest extends AbstractDataJpaTest { @Test void existsByIdAndCreatedBy() { // given - given(auditorProvider.getCurrentAuditor()) - .willReturn(Optional.of(new CreatorId(new MemberId(10L)))); - - ShowReview showReview = new ShowReview(new ShowId("show-id"), 5, "content"); + ShowReview showReview = new ShowReview(new ShowId("show-id"), 5, "content", new CreatorId(new MemberId(10L))); em.persist(showReview); em.flush(); @@ -42,10 +36,7 @@ void existsByIdAndCreatedBy() { @Test void existsByIdAndCreatedBy_ShowReviewIdDifferent_False() { // given - given(auditorProvider.getCurrentAuditor()) - .willReturn(Optional.of(new CreatorId(new MemberId(10L)))); - - ShowReview showReview = new ShowReview(new ShowId("show-id"), 5, "content"); + ShowReview showReview = new ShowReview(new ShowId("show-id"), 5, "content", new CreatorId(new MemberId(10L))); em.persist(showReview); em.flush(); @@ -60,10 +51,7 @@ void existsByIdAndCreatedBy_ShowReviewIdDifferent_False() { @Test void existsByIdAndCreatedBy_CreatorIdDifferent_False() { // given - given(auditorProvider.getCurrentAuditor()) - .willReturn(Optional.of(new CreatorId(new MemberId(10L)))); - - ShowReview showReview = new ShowReview(new ShowId("show-id"), 5, "content"); + ShowReview showReview = new ShowReview(new ShowId("show-id"), 5, "content", new CreatorId(new MemberId(10L))); em.persist(showReview); em.flush(); diff --git a/web/src/docs/asciidoc/showreview.adoc b/web/src/docs/asciidoc/showreview.adoc index e5510cbc..6c8e9c22 100644 --- a/web/src/docs/asciidoc/showreview.adoc +++ b/web/src/docs/asciidoc/showreview.adoc @@ -13,14 +13,6 @@ operation::showreview-create[snippets='http-request,request-headers,http-response,response-fields'] -[[show-review-create-show-review]] -== 공연 리뷰 생성 (Deprecated) - -위의 공연 리뷰 생성 API 로 모두 이전 후 삭제 예정 - -operation::showreview-create-show-review[snippets='http-request,request-headers,path-parameters,http-response,response-fields'] - - [[showreview-get-list]] == 공연 리뷰 리스트 조회 diff --git a/web/src/main/java/org/cmc/curtaincall/web/common/config/AppConfig.java b/web/src/main/java/org/cmc/curtaincall/web/common/config/AppConfig.java index 35cab047..6573f790 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/common/config/AppConfig.java +++ b/web/src/main/java/org/cmc/curtaincall/web/common/config/AppConfig.java @@ -1,14 +1,10 @@ package org.cmc.curtaincall.web.common.config; import jakarta.annotation.PostConstruct; -import org.cmc.curtaincall.domain.core.CreatorId; import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.data.domain.AuditorAware; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.core.JdbcTemplate; import java.util.TimeZone; @@ -22,9 +18,4 @@ public class AppConfig { void postConstruct() { TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul")); } - - @Bean - public AuditorAware auditorProvider(final JdbcTemplate jdbcTemplate) { - return new LoginMemberAuditorAware(jdbcTemplate); - } } diff --git a/web/src/main/java/org/cmc/curtaincall/web/common/config/LoginMemberAuditorAware.java b/web/src/main/java/org/cmc/curtaincall/web/common/config/LoginMemberAuditorAware.java deleted file mode 100644 index 7dfb1faf..00000000 --- a/web/src/main/java/org/cmc/curtaincall/web/common/config/LoginMemberAuditorAware.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.cmc.curtaincall.web.common.config; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.cmc.curtaincall.domain.core.CreatorId; -import org.cmc.curtaincall.domain.member.MemberId; -import org.springframework.data.domain.AuditorAware; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; - -import java.util.Optional; - -@RequiredArgsConstructor -@Slf4j -public class LoginMemberAuditorAware implements AuditorAware { - - private final JdbcTemplate jdbcTemplate; - - @Override - public Optional getCurrentAuditor() { - return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication()) - .filter(Authentication::isAuthenticated) - .map(Authentication::getName) - .map(username -> { - try { - return jdbcTemplate.queryForObject(""" - select a.member_id - from account a - join member m on m.member_id = a.member_id - where a.username = ? and m.use_yn - """, Long.class, username); - } catch (Exception e) { - return null; - } - }) - .map(MemberId::new) - .map(CreatorId::new); - } -} diff --git a/web/src/main/java/org/cmc/curtaincall/web/controller/ImageController.java b/web/src/main/java/org/cmc/curtaincall/web/controller/ImageController.java index ace23ed8..682229ac 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/controller/ImageController.java +++ b/web/src/main/java/org/cmc/curtaincall/web/controller/ImageController.java @@ -1,8 +1,11 @@ package org.cmc.curtaincall.web.controller; import lombok.RequiredArgsConstructor; +import org.cmc.curtaincall.domain.core.CreatorId; +import org.cmc.curtaincall.domain.member.MemberId; import org.cmc.curtaincall.web.exception.InvalidImageException; import org.cmc.curtaincall.web.common.response.IdResult; +import org.cmc.curtaincall.web.security.config.LoginMemberId; import org.cmc.curtaincall.web.service.image.ImageService; import org.springframework.core.io.Resource; import org.springframework.web.bind.annotation.PostMapping; @@ -19,11 +22,10 @@ public class ImageController { private final ImageService imageService; @PostMapping("/images") - public IdResult saveImage(@RequestPart MultipartFile image) { + public IdResult saveImage(@RequestPart MultipartFile image, @LoginMemberId MemberId memberId) { validateMultipartFileImage(image); Resource imageResource = image.getResource(); - IdResult idResult = imageService.saveImage(imageResource); - return idResult; + return imageService.saveImage(imageResource, new CreatorId(memberId)); } private void validateMultipartFileImage(MultipartFile image) { diff --git a/web/src/main/java/org/cmc/curtaincall/web/lostitem/LostItemController.java b/web/src/main/java/org/cmc/curtaincall/web/lostitem/LostItemController.java index 7d93986d..9a15b3e7 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/lostitem/LostItemController.java +++ b/web/src/main/java/org/cmc/curtaincall/web/lostitem/LostItemController.java @@ -32,7 +32,7 @@ public IdResult createLostItem( throw new EntityAccessDeniedException( "Member ID=" + memberId + ", Image ID=" + lostItemCreate.getImageId()); } - return new IdResult<>(lostItemService.create(lostItemCreate)); + return new IdResult<>(lostItemService.create(lostItemCreate, new CreatorId(memberId))); } @DeleteMapping("/lostItems/{lostItemId}") diff --git a/web/src/main/java/org/cmc/curtaincall/web/lostitem/LostItemService.java b/web/src/main/java/org/cmc/curtaincall/web/lostitem/LostItemService.java index fb24baf8..d7a6905a 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/lostitem/LostItemService.java +++ b/web/src/main/java/org/cmc/curtaincall/web/lostitem/LostItemService.java @@ -1,6 +1,7 @@ package org.cmc.curtaincall.web.lostitem; import lombok.RequiredArgsConstructor; +import org.cmc.curtaincall.domain.core.CreatorId; import org.cmc.curtaincall.domain.image.Image; import org.cmc.curtaincall.domain.image.repository.ImageRepository; import org.cmc.curtaincall.domain.lostitem.LostItem; @@ -28,7 +29,7 @@ public class LostItemService { private final LostItemFacilityValidator lostItemFacilityValidator; @Transactional - public LostItemId create(final LostItemCreate lostItemCreate) { + public LostItemId create(final LostItemCreate lostItemCreate, final CreatorId createdBy) { FacilityId facilityId = lostItemCreate.getFacilityId(); lostItemFacilityValidator.validate(facilityId); Image image = getImageById(lostItemCreate.getImageId()); @@ -41,6 +42,7 @@ public LostItemId create(final LostItemCreate lostItemCreate) { .foundDate(lostItemCreate.getFoundDate()) .foundTime(lostItemCreate.getFoundTime()) .particulars(lostItemCreate.getParticulars()) + .createdBy(createdBy) .build() ); return new LostItemId(lostItem.getId()); diff --git a/web/src/main/java/org/cmc/curtaincall/web/notice/NoticeService.java b/web/src/main/java/org/cmc/curtaincall/web/notice/NoticeService.java index 1a6f10fa..0e11ad4d 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/notice/NoticeService.java +++ b/web/src/main/java/org/cmc/curtaincall/web/notice/NoticeService.java @@ -3,8 +3,8 @@ import lombok.RequiredArgsConstructor; import org.cmc.curtaincall.domain.notice.Notice; import org.cmc.curtaincall.domain.notice.NoticeId; +import org.cmc.curtaincall.domain.notice.exception.NoticeNotFoundException; import org.cmc.curtaincall.domain.notice.repository.NoticeRepository; -import org.cmc.curtaincall.web.notice.exception.NoticeNotFoundException; import org.cmc.curtaincall.web.notice.response.NoticeDetailResponse; import org.cmc.curtaincall.web.notice.response.NoticeResponse; import org.springframework.data.domain.Pageable; diff --git a/web/src/main/java/org/cmc/curtaincall/web/notice/exception/NoticeNotFoundException.java b/web/src/main/java/org/cmc/curtaincall/web/notice/exception/NoticeNotFoundException.java deleted file mode 100644 index 3e0193a8..00000000 --- a/web/src/main/java/org/cmc/curtaincall/web/notice/exception/NoticeNotFoundException.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.cmc.curtaincall.web.notice.exception; - -import org.cmc.curtaincall.domain.core.DomainErrorCode; -import org.cmc.curtaincall.domain.core.DomainException; -import org.cmc.curtaincall.domain.notice.NoticeId; - -public class NoticeNotFoundException extends DomainException { - - public NoticeNotFoundException(NoticeId noticeId) { - super(DomainErrorCode.NOT_FOUND, "Notice.id=" + noticeId); - } - - @Override - public String getExternalMessage() { - return "공지사항이 존재하지 않음"; - } -} diff --git a/web/src/main/java/org/cmc/curtaincall/web/party/PartyController.java b/web/src/main/java/org/cmc/curtaincall/web/party/PartyController.java index 056ec7b8..7308c15d 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/party/PartyController.java +++ b/web/src/main/java/org/cmc/curtaincall/web/party/PartyController.java @@ -22,8 +22,10 @@ public class PartyController { private final PartyCreatorValidator partyCreatorValidator; @PostMapping("/parties") - public IdResult createParty(@RequestBody @Validated PartyCreate partyCreate) { - return new IdResult<>(partyService.create(partyCreate)); + public IdResult createParty( + @RequestBody @Validated PartyCreate partyCreate, @LoginMemberId MemberId memberId + ) { + return new IdResult<>(partyService.create(partyCreate, new CreatorId(memberId))); } @InitBinder("partyCreate") diff --git a/web/src/main/java/org/cmc/curtaincall/web/party/PartyService.java b/web/src/main/java/org/cmc/curtaincall/web/party/PartyService.java index 1011d9b2..81e29542 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/party/PartyService.java +++ b/web/src/main/java/org/cmc/curtaincall/web/party/PartyService.java @@ -1,6 +1,7 @@ package org.cmc.curtaincall.web.party; import lombok.RequiredArgsConstructor; +import org.cmc.curtaincall.domain.core.CreatorId; import org.cmc.curtaincall.domain.core.OptimisticLock; import org.cmc.curtaincall.domain.member.MemberId; import org.cmc.curtaincall.domain.party.Party; @@ -28,7 +29,7 @@ public class PartyService { private final PartyShowIdValidator showIdValidator; @Transactional - public PartyId create(PartyCreate partyCreate) { + public PartyId create(final PartyCreate partyCreate, final CreatorId createdBy) { ShowId showId = partyCreate.getShowId(); showIdValidator.validate(showId); Party party = partyRepository.save(Party.builder() @@ -38,6 +39,7 @@ public PartyId create(PartyCreate partyCreate) { .content(partyCreate.getContent()) .maxMemberNum(partyCreate.getMaxMemberNum()) .category(partyCreate.getCategory()) + .createdBy(createdBy) .build() ); diff --git a/web/src/main/java/org/cmc/curtaincall/web/report/ReportController.java b/web/src/main/java/org/cmc/curtaincall/web/report/ReportController.java index bf6cb083..9fb75149 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/report/ReportController.java +++ b/web/src/main/java/org/cmc/curtaincall/web/report/ReportController.java @@ -1,7 +1,10 @@ package org.cmc.curtaincall.web.report; import lombok.RequiredArgsConstructor; +import org.cmc.curtaincall.domain.core.CreatorId; +import org.cmc.curtaincall.domain.member.MemberId; import org.cmc.curtaincall.web.report.request.ReportCreate; +import org.cmc.curtaincall.web.security.config.LoginMemberId; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -14,7 +17,7 @@ public class ReportController { private final ReportService reportService; @PostMapping("/reports") - public void createReport(@RequestBody @Validated ReportCreate reportCreate) { - reportService.create(reportCreate); + public void createReport(@RequestBody @Validated ReportCreate reportCreate, @LoginMemberId MemberId memberId) { + reportService.create(reportCreate, new CreatorId(memberId)); } } diff --git a/web/src/main/java/org/cmc/curtaincall/web/report/ReportService.java b/web/src/main/java/org/cmc/curtaincall/web/report/ReportService.java index 363750ac..8864e6d6 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/report/ReportService.java +++ b/web/src/main/java/org/cmc/curtaincall/web/report/ReportService.java @@ -1,6 +1,7 @@ package org.cmc.curtaincall.web.report; import lombok.RequiredArgsConstructor; +import org.cmc.curtaincall.domain.core.CreatorId; import org.cmc.curtaincall.domain.report.Report; import org.cmc.curtaincall.domain.report.repository.ReportRepository; import org.cmc.curtaincall.web.common.response.IdResult; @@ -16,12 +17,13 @@ public class ReportService { private final ReportRepository reportRepository; @Transactional - public IdResult create(ReportCreate reportCreate) { + public IdResult create(ReportCreate reportCreate, CreatorId createdBy) { Report report = reportRepository.save(Report.builder() .content(reportCreate.getContent()) .reportedId(reportCreate.getIdToReport()) .type(reportCreate.getType()) .reason(reportCreate.getReason()) + .createdBy(createdBy) .build()); return new IdResult<>(report.getId()); } diff --git a/web/src/main/java/org/cmc/curtaincall/web/review/ShowReviewController.java b/web/src/main/java/org/cmc/curtaincall/web/review/ShowReviewController.java index c913f993..6ca60b75 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/review/ShowReviewController.java +++ b/web/src/main/java/org/cmc/curtaincall/web/review/ShowReviewController.java @@ -5,10 +5,8 @@ import org.cmc.curtaincall.domain.member.MemberId; import org.cmc.curtaincall.domain.review.ShowReviewId; import org.cmc.curtaincall.domain.review.validation.ShowReviewCreatorValidator; -import org.cmc.curtaincall.domain.show.ShowId; import org.cmc.curtaincall.web.common.response.IdResult; import org.cmc.curtaincall.web.review.request.ShowReviewCreate; -import org.cmc.curtaincall.web.review.request.ShowReviewCreateDepr; import org.cmc.curtaincall.web.review.request.ShowReviewEdit; import org.cmc.curtaincall.web.security.config.LoginMemberId; import org.springframework.validation.annotation.Validated; @@ -35,13 +33,6 @@ public IdResult create( return new IdResult<>(showReviewService.create(showReviewCreate, new CreatorId(memberId))); } - @PostMapping("/shows/{showId}/reviews") - public IdResult createShowReview( - @PathVariable ShowId showId, @Validated @RequestBody ShowReviewCreateDepr showReviewCreate) { - ShowReviewId showReviewId = showReviewService.create(showId, showReviewCreate); - return new IdResult<>(showReviewId); - } - @DeleteMapping("/reviews/{reviewId}") public void delete(@PathVariable ShowReviewId reviewId, @LoginMemberId MemberId memberId) { showReviewCreatorValidator.validate(reviewId, new CreatorId(memberId)); diff --git a/web/src/main/java/org/cmc/curtaincall/web/review/ShowReviewService.java b/web/src/main/java/org/cmc/curtaincall/web/review/ShowReviewService.java index 782817f3..0677a82d 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/review/ShowReviewService.java +++ b/web/src/main/java/org/cmc/curtaincall/web/review/ShowReviewService.java @@ -12,7 +12,6 @@ import org.cmc.curtaincall.domain.review.validation.ShowReviewShowValidator; import org.cmc.curtaincall.domain.show.ShowId; import org.cmc.curtaincall.web.review.request.ShowReviewCreate; -import org.cmc.curtaincall.web.review.request.ShowReviewCreateDepr; import org.cmc.curtaincall.web.review.request.ShowReviewEdit; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -39,18 +38,7 @@ public ShowReviewId create(final ShowReviewCreate showReviewCreate, final Creato .showId(showId) .grade(showReviewCreate.getGrade()) .content(showReviewCreate.getContent()) - .build()); - showReviewGradeApplyService.apply(showReview); - return new ShowReviewId(showReview.getId()); - } - - @Deprecated(since = "2023-11-04", forRemoval = true) - @Transactional - public ShowReviewId create(ShowId showId, ShowReviewCreateDepr showReviewCreate) { - ShowReview showReview = showReviewRepository.save(ShowReview.builder() - .showId(showId) - .grade(showReviewCreate.getGrade()) - .content(showReviewCreate.getContent()) + .createdBy(creatorId) .build()); showReviewGradeApplyService.apply(showReview); return new ShowReviewId(showReview.getId()); diff --git a/web/src/main/java/org/cmc/curtaincall/web/service/image/ImageService.java b/web/src/main/java/org/cmc/curtaincall/web/service/image/ImageService.java index 52f015e3..7bb400a2 100644 --- a/web/src/main/java/org/cmc/curtaincall/web/service/image/ImageService.java +++ b/web/src/main/java/org/cmc/curtaincall/web/service/image/ImageService.java @@ -1,6 +1,7 @@ package org.cmc.curtaincall.web.service.image; import lombok.RequiredArgsConstructor; +import org.cmc.curtaincall.domain.core.CreatorId; import org.cmc.curtaincall.domain.image.Image; import org.cmc.curtaincall.domain.image.repository.ImageRepository; import org.cmc.curtaincall.web.exception.EntityNotFoundException; @@ -27,7 +28,7 @@ public class ImageService { private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyMMddHHmmss"); @Transactional - public IdResult saveImage(Resource imageResource) { + public IdResult saveImage(Resource imageResource, CreatorId createdBy) { String originName = imageResource.getFilename(); String storedName = createStoredName(originName); String url = imageStore.store(imageResource, storedName); @@ -36,6 +37,7 @@ public IdResult saveImage(Resource imageResource) { .originName(originName) .storedName(storedName) .url(url) + .createdBy(createdBy) .build() ); diff --git a/web/src/test/java/org/cmc/curtaincall/web/controller/ImageControllerDocsTest.java b/web/src/test/java/org/cmc/curtaincall/web/controller/ImageControllerDocsTest.java index e7402ea5..b34b97f7 100644 --- a/web/src/test/java/org/cmc/curtaincall/web/controller/ImageControllerDocsTest.java +++ b/web/src/test/java/org/cmc/curtaincall/web/controller/ImageControllerDocsTest.java @@ -33,7 +33,7 @@ void saveImage_Docs() throws Exception { // given MockMultipartFile image = new MockMultipartFile("image", "test-image1.jpg", MediaType.IMAGE_JPEG_VALUE, "test-image1-content".getBytes()); - given(imageService.saveImage(any())).willReturn(new IdResult<>(10L)); + given(imageService.saveImage(any(), any())).willReturn(new IdResult<>(10L)); // expected mockMvc.perform(multipart("/images") diff --git a/web/src/test/java/org/cmc/curtaincall/web/lostitem/LostItemControllerDocsTest.java b/web/src/test/java/org/cmc/curtaincall/web/lostitem/LostItemControllerDocsTest.java index 1b26100c..ab5d49dd 100644 --- a/web/src/test/java/org/cmc/curtaincall/web/lostitem/LostItemControllerDocsTest.java +++ b/web/src/test/java/org/cmc/curtaincall/web/lostitem/LostItemControllerDocsTest.java @@ -63,7 +63,7 @@ void createLostItem_Docs() throws Exception { .imageId(1L) .build(); given(imageService.isOwnedByMember(LOGIN_MEMBER_ID.getId(), 1L)).willReturn(true); - given(lostItemService.create(lostItemCreate)).willReturn(new LostItemId(10L)); + given(lostItemService.create(lostItemCreate, new CreatorId(LOGIN_MEMBER_ID))).willReturn(new LostItemId(10L)); // expected mockMvc.perform(post("/lostItems") diff --git a/web/src/test/java/org/cmc/curtaincall/web/party/PartyControllerDocsTest.java b/web/src/test/java/org/cmc/curtaincall/web/party/PartyControllerDocsTest.java index 623f5e7f..57c6e108 100644 --- a/web/src/test/java/org/cmc/curtaincall/web/party/PartyControllerDocsTest.java +++ b/web/src/test/java/org/cmc/curtaincall/web/party/PartyControllerDocsTest.java @@ -58,7 +58,7 @@ void createParty_Docs() throws Exception { .maxMemberNum(5) .category(PartyCategory.WATCHING) .build(); - given(partyService.create(partyCreate)).willReturn(new PartyId(10L)); + given(partyService.create(partyCreate, new CreatorId(LOGIN_MEMBER_ID))).willReturn(new PartyId(10L)); // expected mockMvc.perform(post("/parties") diff --git a/web/src/test/java/org/cmc/curtaincall/web/party/PartyControllerTest.java b/web/src/test/java/org/cmc/curtaincall/web/party/PartyControllerTest.java index c643c767..13185f35 100644 --- a/web/src/test/java/org/cmc/curtaincall/web/party/PartyControllerTest.java +++ b/web/src/test/java/org/cmc/curtaincall/web/party/PartyControllerTest.java @@ -42,7 +42,7 @@ void createParty_when_NotEtcCategory_then_showIdNotNull() throws Exception { .maxMemberNum(5) .category(PartyCategory.WATCHING) .build(); - given(partyService.create(any())).willReturn(new PartyId(10L)); + given(partyService.create(any(), any())).willReturn(new PartyId(10L)); // expected mockMvc.perform(post("/parties") @@ -67,7 +67,7 @@ void createParty_when_NotEtcCategory_then_showAtNotNull() throws Exception { .maxMemberNum(5) .category(PartyCategory.WATCHING) .build(); - given(partyService.create(any())).willReturn(new PartyId(10L)); + given(partyService.create(any(), any())).willReturn(new PartyId(10L)); // expected mockMvc.perform(post("/parties") @@ -92,7 +92,7 @@ void createParty_when_NotEtcCategory_then_maxMemberNumLessOrEqual10() throws Exc .maxMemberNum(101) .category(PartyCategory.WATCHING) .build(); - given(partyService.create(any())).willReturn(new PartyId(10L)); + given(partyService.create(any(), any())).willReturn(new PartyId(10L)); // expected mockMvc.perform(post("/parties") @@ -117,7 +117,7 @@ void createParty_when_EtcCategory() throws Exception { .maxMemberNum(11) .category(PartyCategory.ETC) .build(); - given(partyService.create(any())).willReturn(new PartyId(10L)); + given(partyService.create(any(), any())).willReturn(new PartyId(10L)); // expected mockMvc.perform(post("/parties") diff --git a/web/src/test/java/org/cmc/curtaincall/web/review/ShowReviewControllerDocsTest.java b/web/src/test/java/org/cmc/curtaincall/web/review/ShowReviewControllerDocsTest.java index 4476cb96..1ea31b39 100644 --- a/web/src/test/java/org/cmc/curtaincall/web/review/ShowReviewControllerDocsTest.java +++ b/web/src/test/java/org/cmc/curtaincall/web/review/ShowReviewControllerDocsTest.java @@ -6,7 +6,6 @@ import org.cmc.curtaincall.domain.show.ShowId; import org.cmc.curtaincall.web.common.AbstractWebTest; import org.cmc.curtaincall.web.review.request.ShowReviewCreate; -import org.cmc.curtaincall.web.review.request.ShowReviewCreateDepr; import org.cmc.curtaincall.web.review.request.ShowReviewEdit; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -16,7 +15,6 @@ import org.springframework.http.MediaType; import static org.cmc.curtaincall.web.common.RestDocsAttribute.constraint; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.inOrder; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; @@ -43,43 +41,6 @@ class ShowReviewControllerDocsTest extends AbstractWebTest { @MockBean private ShowReviewCreatorValidator showReviewCreatorValidator; - @Test - void createShowReview_Docs() throws Exception { - // given - ShowReviewCreateDepr showReviewCreate = ShowReviewCreateDepr.builder() - .grade(5) - .content("조아유~~") - .build(); - given(showReviewService.create(any(ShowId.class), any())).willReturn(new ShowReviewId(10L)); - - // expected - mockMvc.perform(post("/shows/{showId}/reviews", "PF220846") - .header(HttpHeaders.AUTHORIZATION, "Bearer ACCESS_TOKEN") - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(showReviewCreate)) - ) - .andDo(print()) - .andExpect(status().isOk()) - .andDo(document("showreview-create-show-review", - requestHeaders( - headerWithName(HttpHeaders.AUTHORIZATION).description("인증 필요") - ), - pathParameters( - parameterWithName("showId").description("공연 아이디") - ), - requestFields( - fieldWithPath("grade").description("평점") - .attributes(constraint("PositiveOrZero, max=5")), - fieldWithPath("content").description("내용") - .attributes(constraint("max=200")) - ), - responseFields( - fieldWithPath("id").description("공연 리뷰 ID") - ) - )); - } - @Test void create_Docs() throws Exception { // given