-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShop.java
More file actions
131 lines (103 loc) ยท 3.77 KB
/
Shop.java
File metadata and controls
131 lines (103 loc) ยท 3.77 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
package com.nextroom.nextRoomServer.domain;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import com.nextroom.nextRoomServer.dto.AuthDto;
import com.nextroom.nextRoomServer.enums.UserStatus;
import com.nextroom.nextRoomServer.exceptions.CustomException;
import com.nextroom.nextRoomServer.security.SecurityUtil;
import org.hibernate.annotations.Comment;
import com.nextroom.nextRoomServer.util.Timestamped;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import static com.nextroom.nextRoomServer.exceptions.StatusCode.NOT_PERMITTED;
import static com.nextroom.nextRoomServer.exceptions.StatusCode.SUBSCRIPTION_NOT_PERMITTED;
@Entity
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Shop extends Timestamped {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "shop_id", nullable = false)
private Long id;
@Column
private String email;
@Column
private String googleSub;
@Column(nullable = false, length = 5)
private String adminCode;
@Column
private String password;
@Column
private String name;
@Comment(value = "1: ์น(ํํ์ด์ง)์์ PC๋ก ๋ค์ด์จ ์ ์ , 2: ์น(ํํ์ด์ง)์์ ๋ชจ๋ฐ์ผ๋ก ๋ค์ด์จ ์ ์ , 3: ์ฑ์์ ๋ค์ด์จ ์ ์ ")
@Column
private Integer type;
@Column
private String signupSource;
@Column
private String comment;
@Column
private Boolean adsConsent;
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Authority authority;
@Column
private LocalDateTime lastLoginAt;
@OneToMany(mappedBy = "shop", cascade = CascadeType.ALL, orphanRemoval = true)
@Builder.Default
private List<Theme> themes = new ArrayList<>();
@OneToMany(mappedBy = "shop", cascade = CascadeType.ALL, orphanRemoval = true)
@Builder.Default
private List<Payment> payments = new ArrayList<>();
@OneToOne(mappedBy = "shop", cascade = CascadeType.ALL, orphanRemoval = true)
private Subscription subscription;
public void updateLastLoginAt() {
this.lastLoginAt = LocalDateTime.now();
}
public void checkAuthorized() {
if (!Objects.equals(this.id, SecurityUtil.getCurrentShopId())) {
throw new CustomException(NOT_PERMITTED);
}
}
public boolean isSubscription() {
return this.subscription.getStatus() == UserStatus.SUBSCRIPTION;
}
public void validateSubscriptionInNeed(boolean needed) {
if (!needed) { return; }
if (this.subscription == null || !this.isSubscription()) {
throw new CustomException(SUBSCRIPTION_NOT_PERMITTED);
}
}
public void setAllUseTimerUrl(boolean active) {
this.themes.forEach(theme -> Optional.ofNullable(theme.getTimerImageUrl())
.ifPresent(it -> theme.setUseTimerUrl(active)));
}
public boolean isCompleteSignUp() {
return this.name != null && !this.name.isEmpty();
}
public void updateShopInfo(AuthDto.ShopUpdateRequestDto request) {
this.name = request.getName();
this.signupSource = request.getSignupSource();
this.comment = request.getComment();
this.type = request.getType();
this.adsConsent = request.getAdsConsent();
this.lastLoginAt = LocalDateTime.now();
}
}