-
Notifications
You must be signed in to change notification settings - Fork 3
/
Pet.java
100 lines (77 loc) · 2.89 KB
/
Pet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.daggle.animory.domain.pet.entity;
import com.daggle.animory.common.entity.BaseEntity;
import com.daggle.animory.domain.pet.dto.request.PetUpdateRequestDto;
import com.daggle.animory.domain.pet.util.PetAgeToBirthDateConverter;
import com.daggle.animory.domain.shelter.entity.Shelter;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
@Getter
@Entity
@Builder
@AllArgsConstructor
@Table(name = "pet")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Pet extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@NotNull
private String name;
@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
private LocalDate birthDate;
@NotNull
@Enumerated(EnumType.STRING)
private PetType type;
@NotNull
@Enumerated(EnumType.STRING)
private Sex sex;
private float weight;
@Column(length = 1000)
private String description;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate protectionExpirationDate;
private String vaccinationStatus;
@Enumerated(EnumType.STRING)
private NeutralizationStatus neutralizationStatus;
@NotNull
@Enumerated(EnumType.STRING)
private AdoptionStatus adoptionStatus;
@NotNull
private String profileImageUrl;
@NotNull
private String profileShortFormUrl;
private String size;
@Embedded
private PetPolygonProfile petPolygonProfile;
@ManyToOne
@JoinColumn(name = "shelter_id")
private Shelter shelter;
public void updateImage(final String imageUrl) {
this.profileImageUrl = imageUrl;
}
public void updateVideo(final String videoUrl) {
this.profileShortFormUrl = videoUrl;
}
public void setAdopted() {
this.adoptionStatus = AdoptionStatus.YES;
this.protectionExpirationDate = null;
}
public void updateInfo(final PetUpdateRequestDto petUpdateRequestDto) {
this.name = petUpdateRequestDto.name();
this.birthDate = PetAgeToBirthDateConverter.ageToBirthDate(petUpdateRequestDto.age());
this.type = petUpdateRequestDto.type();
this.weight = petUpdateRequestDto.weight();
this.size = petUpdateRequestDto.size();
this.sex = petUpdateRequestDto.sex();
this.vaccinationStatus = petUpdateRequestDto.vaccinationStatus();
this.neutralizationStatus = petUpdateRequestDto.neutralizationStatus();
this.adoptionStatus = petUpdateRequestDto.adoptionStatus();
this.protectionExpirationDate = petUpdateRequestDto.protectionExpirationDate();
this.petPolygonProfile = petUpdateRequestDto.petPolygonProfileDto().toEntity();
this.description = petUpdateRequestDto.description();
}
}