Skip to content

Commit

Permalink
Feature/#143 remove auditor aware (#144)
Browse files Browse the repository at this point in the history
* feat: Notice 도메인 에러 적용

* prune: 불필요한 도메인 클래스 제거

* fix: CreatorId JoinColumn 제거

* feat: Image 생성자 Creator 추가

* feat: LostItem Creator 생성자에 추가

* feat: Party 생성자 CreatorId 추가

* feat: Report 생성자 CreatorId 추가

* feat: Review 생성자 CreatorId 추가

* feat: AuditorAware 제거
  • Loading branch information
Cho-D-YoungRae authored Dec 7, 2023
1 parent f848d71 commit 0515233
Show file tree
Hide file tree
Showing 37 changed files with 136 additions and 308 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
}

This file was deleted.

This file was deleted.

12 changes: 8 additions & 4 deletions domain/src/main/java/org/cmc/curtaincall/domain/image/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -83,6 +86,7 @@ public LostItem(
this.foundDate = foundDate;
this.foundTime = foundTime;
this.particulars = particulars;
this.createdBy = createdBy;
}

public LostItemEditor.LostItemEditorBuilder toEditor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
16 changes: 10 additions & 6 deletions domain/src/main/java/org/cmc/curtaincall/domain/party/Party.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,14 +53,15 @@ 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);
}
this.showId = showId;
this.grade = grade;
this.content = content;
this.likeCount = 0;
this.createdBy = createdBy;
}

private boolean isInGradeRange(int grade) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +13,4 @@ public abstract class AbstractDataJpaTest {

@Autowired
protected EntityManager em;

@MockBean
protected AuditorAware<CreatorId> auditorProvider;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand All @@ -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);

Expand All @@ -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))
Expand All @@ -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);

Expand All @@ -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))
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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();

Expand Down
Loading

0 comments on commit 0515233

Please sign in to comment.