-
Notifications
You must be signed in to change notification settings - Fork 2
/
GroupParticipation.java
62 lines (51 loc) · 1.87 KB
/
GroupParticipation.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
package com.amorgakco.backend.groupparticipation.domain;
import com.amorgakco.backend.global.BaseTime;
import com.amorgakco.backend.global.exception.IllegalAccessException;
import com.amorgakco.backend.group.domain.Group;
import com.amorgakco.backend.member.domain.Member;
import com.amorgakco.backend.participant.domain.Participant;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class GroupParticipation extends BaseTime {
@Id @GeneratedValue private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
private Group group;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
private Member participant;
@Enumerated(EnumType.STRING)
private ParticipationStatus participationStatus;
@Builder
public GroupParticipation(final Group group, final Member member) {
this.group = group;
this.participant = member;
this.participationStatus = ParticipationStatus.PENDING;
}
public void approve(final Member host) {
if (group.isNotGroupHost(host.getId())) {
throw IllegalAccessException.noAuthorityForGroup();
}
participationStatus = ParticipationStatus.APPROVED;
group.addParticipants(new Participant(participant));
}
public void reject(final Member host) {
if (group.isNotGroupHost(host.getId())) {
throw IllegalAccessException.noAuthorityForGroup();
}
participationStatus = ParticipationStatus.REJECTED;
}
}