Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 엔티티를 개선한다. #22

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions src/main/java/com/clova/anifriends/domain/animal/Animal.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.clova.anifriends.domain.animal;

import com.clova.anifriends.domain.animal.wrapper.Active;
import com.clova.anifriends.domain.animal.wrapper.Breed;
import com.clova.anifriends.domain.animal.wrapper.Gender;
import com.clova.anifriends.domain.animal.wrapper.Information;
import com.clova.anifriends.domain.animal.wrapper.IsNeutered;
import com.clova.anifriends.domain.animal.wrapper.Name;
import com.clova.anifriends.domain.animal.wrapper.Type;
import com.clova.anifriends.domain.animal.wrapper.Weight;
import com.clova.anifriends.domain.animal.wrapper.AnimalActive;
import com.clova.anifriends.domain.animal.wrapper.AnimalBreed;
import com.clova.anifriends.domain.animal.wrapper.AnimalGender;
import com.clova.anifriends.domain.animal.wrapper.AnimalInformation;
import com.clova.anifriends.domain.animal.wrapper.AnimalName;
import com.clova.anifriends.domain.animal.wrapper.AnimalNeutered;
import com.clova.anifriends.domain.animal.wrapper.AnimalType;
import com.clova.anifriends.domain.animal.wrapper.AnimalWeight;
import com.clova.anifriends.domain.common.BaseTimeEntity;
import com.clova.anifriends.domain.shelter.Shelter;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -38,33 +38,33 @@ public class Animal extends BaseTimeEntity {
private Shelter shelter;

@Embedded
private Name name;
private AnimalName name;

@Column(name = "birth_date")
private LocalDate birthDate;

@Enumerated(EnumType.STRING)
@Column(name = "type")
private Type type;
private AnimalType type;

@Embedded
private Breed breed;
private AnimalBreed breed;

@Embedded
private Gender gender;
private AnimalGender gender;

@Embedded
private IsNeutered isNeutered;
private AnimalNeutered neutered;

@Enumerated(EnumType.STRING)
@Column(name = "active")
private Active active;
private AnimalActive active;

@Embedded
private Weight weight;
private AnimalWeight weight;

@Embedded
private Information information;
private AnimalInformation information;

protected Animal() {
}
Expand All @@ -82,14 +82,22 @@ public Animal(
String information
) {
this.shelter = shelter;
this.name = new Name(name);
this.name = new AnimalName(name);
this.birthDate = birthDate;
this.type = Type.valueOf(type);
this.breed = new Breed(breed);
this.gender = Gender.valueOf(gender);
this.isNeutered = new IsNeutered(isNeutered);
this.active = Active.valueOf(active);
this.weight = new Weight(weight);
this.information = new Information(information);
this.type = AnimalType.valueOf(type);
this.breed = new AnimalBreed(breed);
this.gender = AnimalGender.valueOf(gender);
this.neutered = new AnimalNeutered(isNeutered);
this.active = AnimalActive.valueOf(active);
this.weight = new AnimalWeight(weight);
this.information = new AnimalInformation(information);
}

public String getName() {
return this.name.getName();
}

public boolean isNeutered() {
return this.neutered.getIsNeutered();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clova.anifriends.domain.animal.wrapper;

public enum Active {
public enum AnimalActive {

QUIET,
NORMAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import jakarta.persistence.Embeddable;

@Embeddable
public class Breed {
public class AnimalBreed {

@Column(name = "breed")
private String breed;

protected Breed() {
protected AnimalBreed() {
}

public Breed(String value) {
public AnimalBreed(String value) {
this.breed = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.clova.anifriends.EnumType;

public enum Gender implements EnumType {
public enum AnimalGender implements EnumType {

MALE,
FEMALE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import jakarta.persistence.Embeddable;

@Embeddable
public class Information {
public class AnimalInformation {

@Column(name = "information")
private String information;

protected Information() {
protected AnimalInformation() {
}

public Information(String value) {
public AnimalInformation(String value) {
this.information = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.Getter;

@Getter
@Embeddable
public class Name {
public class AnimalName {

@Column(name = "name")
private String name;

protected Name() {
protected AnimalName() {
}

public Name(String value) {
public AnimalName(String value) {
this.name = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.Getter;

@Getter
@Embeddable
public class IsNeutered {
public class AnimalNeutered {

@Column(name = "isNeutered")
@Column(name = "is_neutered")
private Boolean isNeutered;

protected IsNeutered() {
protected AnimalNeutered() {
}

public IsNeutered(boolean value) {
public AnimalNeutered(boolean value) {
this.isNeutered = value;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clova.anifriends.domain.animal.wrapper;

public enum Type {
public enum AnimalType {

DOG,
CAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import jakarta.persistence.Embeddable;

@Embeddable
public class Weight {
public class AnimalWeight {

@Column(name = "weight")
private Double weight;

protected Weight() {
protected AnimalWeight() {
}

public Weight(double value) {
public AnimalWeight(double value) {
this.weight = value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clova.anifriends.domain.applicant;

import com.clova.anifriends.domain.applicant.wrapper.Status;
import com.clova.anifriends.domain.applicant.wrapper.ApplicantStatus;
import com.clova.anifriends.domain.common.BaseTimeEntity;
import com.clova.anifriends.domain.recruitment.Recruitment;
import com.clova.anifriends.domain.volunteer.Volunteer;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class Applicant extends BaseTimeEntity {

@Enumerated(EnumType.STRING)
@Column(name = "status")
private Status status;
private ApplicantStatus status;

protected Applicant() {
}
Expand All @@ -47,6 +47,6 @@ public Applicant(
) {
this.recruitment = recruitment;
this.volunteer = volunteer;
this.status = Status.valueOf(status);
this.status = ApplicantStatus.valueOf(status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.clova.anifriends.EnumType;

public enum Status implements EnumType {
public enum ApplicantStatus implements EnumType {

PENDING,
REFUSED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.clova.anifriends.domain.recruitment;

import com.clova.anifriends.domain.common.BaseTimeEntity;
import com.clova.anifriends.domain.recruitment.wrapper.Capacity;
import com.clova.anifriends.domain.recruitment.wrapper.Content;
import com.clova.anifriends.domain.recruitment.wrapper.IsClosed;
import com.clova.anifriends.domain.recruitment.wrapper.Title;
import com.clova.anifriends.domain.recruitment.wrapper.RecruitmentContent;
import com.clova.anifriends.domain.recruitment.wrapper.RecruitmentDeadlineInfo;
import com.clova.anifriends.domain.recruitment.wrapper.RecruitmentTime;
import com.clova.anifriends.domain.recruitment.wrapper.RecruitmentTitle;
import com.clova.anifriends.domain.shelter.Shelter;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
Expand Down Expand Up @@ -33,25 +33,16 @@ public class Recruitment extends BaseTimeEntity {
private Shelter shelter;

@Embedded
private Title title;
private RecruitmentTitle title;

@Embedded
private Capacity capacity;
private RecruitmentContent content;

@Embedded
private Content content;
private RecruitmentTime time;

@Embedded
private IsClosed isClosed;

@Column(name = "startTime")
private LocalDateTime startTime;

@Column(name = "endTime")
private LocalDateTime endTime;

@Column(name = "deadline")
private LocalDateTime deadline;
private RecruitmentDeadlineInfo deadlineInfo;

@LastModifiedDate
@Column(name = "updated_at")
Expand All @@ -71,12 +62,9 @@ public Recruitment(
LocalDateTime deadline
) {
this.shelter = shelter;
this.title = new Title(title);
this.capacity = new Capacity(capacity);
this.content = new Content(content);
this.isClosed = new IsClosed(isClosed);
this.startTime = startTime;
this.endTime = endTime;
this.deadline = deadline;
this.title = new RecruitmentTitle(title);
this.content = new RecruitmentContent(content);
this.time = new RecruitmentTime(startTime, endTime);
this.deadlineInfo = new RecruitmentDeadlineInfo(deadline, isClosed, capacity);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import jakarta.persistence.Embeddable;

@Embeddable
public class Content {
public class RecruitmentContent {

@Column(name = "content")
private String content;

protected Content() {
protected RecruitmentContent() {
}

public Content(String value) {
public RecruitmentContent(String value) {
this.content = value;
}

Expand Down
Loading
Loading