-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMember.java
More file actions
145 lines (122 loc) · 4.69 KB
/
Member.java
File metadata and controls
145 lines (122 loc) · 4.69 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package clap.server.domain.model.member;
import clap.server.adapter.outbound.persistense.entity.member.constant.MemberRole;
import clap.server.adapter.outbound.persistense.entity.member.constant.MemberStatus;
import clap.server.domain.model.common.BaseTime;
import clap.server.domain.model.task.Task;
import clap.server.exception.DomainException;
import clap.server.exception.code.MemberErrorCode;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.Objects;
@Getter
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Member extends BaseTime {
private Long memberId;
private MemberInfo memberInfo;
private Member admin;
private Boolean kakaoworkNotificationEnabled;
private Boolean agitNotificationEnabled;
private Boolean emailNotificationEnabled;
private String imageUrl;
private MemberStatus status;
private String password;
private Department department;
public Member(MemberInfo memberInfo, Boolean agitNotificationEnabled, Boolean emailNotificationEnabled, Boolean kakaoworkNotificationEnabled,
Member admin, String imageUrl, MemberStatus status, String password) {
this.memberInfo = memberInfo;
this.agitNotificationEnabled = agitNotificationEnabled;
this.emailNotificationEnabled = emailNotificationEnabled;
this.kakaoworkNotificationEnabled = kakaoworkNotificationEnabled;
this.admin = admin;
this.imageUrl = imageUrl;
this.status = status;
this.password = password;
}
public static Member createMember(Member admin, MemberInfo memberInfo) {
return Member.builder()
.memberInfo(memberInfo)
.agitNotificationEnabled(false)
.emailNotificationEnabled(false)
.kakaoworkNotificationEnabled(false)
.admin(admin)
.imageUrl(null)
.status(MemberStatus.PENDING)
.password(null)
.build();
}
public void resetPassword(String newEncodedPassword) {
this.password = newEncodedPassword;
}
public void resetPasswordAndActivateMember(String newEncodedPassword) {
this.password = newEncodedPassword;
this.status = MemberStatus.ACTIVE;
this.agitNotificationEnabled = true;
this.emailNotificationEnabled = true;
this.kakaoworkNotificationEnabled = true;
}
public String getNickname() {
return memberInfo != null ? memberInfo.getNickname() : null;
}
public boolean isReviewer() {
return this.memberInfo != null && this.memberInfo.isReviewer();
}
public void changeToApproveRequested() {
this.status = MemberStatus.APPROVAL_REQUEST;
}
public void updateMemberInfo(String name, Boolean agitNotificationEnabled, Boolean emailNotificationEnabled, Boolean kakaoWorkNotificationEnabled) {
this.memberInfo.updateName(name);
this.agitNotificationEnabled = agitNotificationEnabled;
this.emailNotificationEnabled = emailNotificationEnabled;
this.kakaoworkNotificationEnabled = kakaoWorkNotificationEnabled;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public void setStatusDeleted() {
this.status = MemberStatus.DELETED;
}
public void updateKaKaoEnabled() {
if (!this.kakaoworkNotificationEnabled) {
this.kakaoworkNotificationEnabled = true;
}
else {
this.kakaoworkNotificationEnabled = false;
}
}
public void updateAgitEnabled() {
if (!this.agitNotificationEnabled) {
this.agitNotificationEnabled = true;
}
else {
this.agitNotificationEnabled = false;
}
}
public void updateEmailEnabled() {
if (!this.emailNotificationEnabled) {
this.emailNotificationEnabled = true;
}
else {
this.emailNotificationEnabled = false;
}
}
public static Boolean checkCommenter(Task task, Member member) {
// 일반 회원일 경우 => 요청자인지 확인
if ((member.getMemberInfo().getRole() == MemberRole.ROLE_USER)
&& !(Objects.equals(member.getMemberId(), task.getRequester().getMemberId()))) {
throw new DomainException(MemberErrorCode.NOT_A_COMMENTER);
}
else {
return true;
}
}
public void verifyPassword(String encodedPassword) {
if(!encodedPassword.equals(this.password)) {
throw new DomainException(MemberErrorCode.PASSWORD_VERIFY_FAILED);
}
}
public void register(Member admin) {
this.admin = admin;
}
}