-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFamily.java
112 lines (87 loc) · 2.98 KB
/
Family.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
101
102
103
104
105
106
107
108
109
110
111
112
package com.oing.domain;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.security.InvalidParameterException;
@Entity(name = "family")
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@AllArgsConstructor
@Getter
public class Family extends BaseEntity {
@Id
@Column(name = "family_id", columnDefinition = "CHAR(26)", nullable = false)
private String id;
@Column(name = "family_name", columnDefinition = "CHAR(10)")
private String familyName;
@Column(name = "family_name_editor_id", columnDefinition = "CHAR(26)")
private String familyNameEditorId;
@Column(name = "score", nullable = false)
private Integer score = 0;
public Family(String id, String familyName, String familyNameEditorId) {
this.id = id;
this.familyName = familyName;
this.familyNameEditorId = familyNameEditorId;
}
public static final int NEW_POST_SCORE = 20;
public static final int ALL_FAMILY_MEMBERS_POSTS_UPLOADED_SCORE = 50;
public static final int NEW_COMMENT_SCORE = 5;
public static final int NEW_REACTION_SCORE = 1;
public static final int NEW_REAL_EMOJI_SCORE = 3;
public void addNewPostScore() {
addScore(NEW_POST_SCORE);
}
public void subtractNewPostScore() {
subtractScore(NEW_POST_SCORE);
}
public void addAllFamilyMembersPostsUploadedScore() {
addScore(ALL_FAMILY_MEMBERS_POSTS_UPLOADED_SCORE);
}
public void subtractAllFamilyMembersPostsUploadedScore() {
subtractScore(ALL_FAMILY_MEMBERS_POSTS_UPLOADED_SCORE);
}
public void addNewCommentScore() {
addScore(NEW_COMMENT_SCORE);
}
public void subtractNewCommentScore() {
subtractScore(NEW_COMMENT_SCORE);
}
public void addNewReactionScore() {
addScore(NEW_REACTION_SCORE);
}
public void subtractNewReactionScore() {
subtractScore(NEW_REACTION_SCORE);
}
public void addNewRealEmojiScore() {
addScore(NEW_REAL_EMOJI_SCORE);
}
public void subtractNewRealEmojiScore() {
subtractScore(NEW_REAL_EMOJI_SCORE);
}
public void addScore(int score) {
this.score += score;
}
public void subtractScore(int score) {
this.score -= score;
}
public void resetScore() {
this.score = 0;
}
public void updateFamilyName(String familyName, String loginFamilyId) {
if (familyName == null) {
this.familyName = null;
this.familyNameEditorId = null;
} else {
validateFamilyName(familyName);
this.familyName = familyName;
this.familyNameEditorId = loginFamilyId;
}
}
private void validateFamilyName(String familyName) {
if ((familyName.codePoints().count() > 10) || familyName.isBlank()) {
throw new InvalidParameterException();
}
}
}