-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHomeFacade.java
More file actions
executable file
ยท198 lines (175 loc) ยท 8.85 KB
/
HomeFacade.java
File metadata and controls
executable file
ยท198 lines (175 loc) ยท 8.85 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package org.sopt.app.facade;
import static org.sopt.app.common.utils.HtmlTagWrapper.wrapWithTag;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.sopt.app.application.appservice.AppServiceBadgeService;
import org.sopt.app.application.appservice.AppServiceName;
import org.sopt.app.application.appservice.AppServiceService;
import org.sopt.app.application.appservice.OperationConfigService;
import org.sopt.app.application.appservice.dto.AppServiceEntryStatusResponse;
import org.sopt.app.application.appservice.dto.AppServiceInfo;
import org.sopt.app.application.description.DescriptionService;
import org.sopt.app.application.meeting.MeetingResponse;
import org.sopt.app.application.meeting.MeetingService;
import org.sopt.app.application.platform.PlatformService;
import org.sopt.app.application.platform.dto.PlatformUserInfoResponse;
import org.sopt.app.application.playground.PlaygroundAuthService;
import org.sopt.app.application.playground.dto.PlaygroundPopularPost;
import org.sopt.app.application.playground.dto.PlaygroundRecentPost;
import org.sopt.app.application.soptamp.SoptampUserService;
import org.sopt.app.common.config.OperationConfig;
import org.sopt.app.common.config.OperationConfigCategory;
import org.sopt.app.common.utils.ActivityDurationCalculator;
import org.sopt.app.domain.enums.UserStatus;
import org.sopt.app.presentation.home.MeetingParamRequest;
import org.sopt.app.presentation.home.response.FloatingButtonResponse;
import org.sopt.app.presentation.home.response.HomeDescriptionResponse;
import org.sopt.app.presentation.home.response.ReviewFormResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
public class HomeFacade {
private final DescriptionService descriptionService;
private final PlaygroundAuthService playgroundAuthService;
private final AppServiceService appServiceService;
private final AppServiceBadgeService appServiceBadgeService;
private final MeetingService meetingService;
private final OperationConfigService operationConfigService;
private final PlatformService platformService;
private final SoptampUserService soptampUserService;
// TODO : deprecated ๋๊ฒ์ผ๋ก ์ธ์ง
// @Transactional(readOnly = true)
// @Deprecated
// public MainDescription getMainDescriptionForUser(User user) {
// val userActiveInfo = playgroundAuthService.getPlaygroundUserActiveInfo(user.getPlaygroundToken(),
// user.getPlaygroundId());
// return descriptionService.getMainDescription(userActiveInfo.status());
// }
@Transactional(readOnly = true)
public HomeDescriptionResponse getHomeMainDescription(Long userId) {
int duration = ActivityDurationCalculator.calculate(platformService.getMemberGenerationList(userId));
return HomeDescriptionResponse.of(
wrapWithTag(platformService.getPlatformUserInfoResponse(userId).name(), "b"),
duration
);
}
@Transactional
public List<AppServiceEntryStatusResponse> checkAppServiceEntryStatus(Long userId) {
if(userId == null){
return this.getOnlyAppServiceInfo();
}
// TODO : ์ถํ ์ ์ ์์ฑ api response ๋ณ๊ฒฝํด ์์ฑ api ์ชฝ์์ soptamp user upsert ํ๋๋ก ๋ณ๊ฒฝ
PlatformUserInfoResponse platformUserInfo = platformService.getPlatformUserInfoResponse(userId);
UserStatus status = platformService.getStatus(platformUserInfo);
List<AppServiceEntryStatusResponse> appServiceEntryStatusResponses = appServiceService.getAllAppService().stream()
.filter(appServiceInfo -> isServiceVisibleToUser(appServiceInfo, status))
.map(appServiceInfo -> appServiceBadgeService.getAppServiceEntryStatusResponse(
appServiceInfo, userId
))
.toList();
soptampUserService.upsertSoptampUser(platformUserInfo, userId);
return appServiceEntryStatusResponses;
}
private List<AppServiceEntryStatusResponse> getOnlyAppServiceInfo() {
return appServiceService.getAllAppService().stream()
.map(AppServiceEntryStatusResponse::createOnlyAppServiceInfo)
.toList();
}
private boolean isServiceVisibleToUser(AppServiceInfo appServiceInfo, UserStatus status) {
if (appServiceInfo == null || status == null) return false;
if (status == UserStatus.ACTIVE) {
return appServiceInfo.getActiveUser();
}
if (status == UserStatus.INACTIVE) {
return appServiceInfo.getInactiveUser();
}
return false;
}
// public List<RecentPostsResponse> getRecentPosts(Long userId) {
//
// return playgroundAuthService.getRecentPostsWithMemberInfo(user.getPlaygroundToken());
// }
// public List<EmploymentPostResponse> getHomeEmploymentPost(User user) {
// return playgroundAuthService.getPlaygroundEmploymentPostWithMemberInfo(user.getPlaygroundToken());
// }
//
// @Transactional(readOnly = true)
// public List<CoffeeChatResponse> getCoffeeChatList(User user) {
// return playgroundAuthService.getCoffeeChatList(user.getPlaygroundToken());
// }
public List<MeetingResponse> getAllMeetings(MeetingParamRequest request) {
return meetingService.getAllMeetings(request)
.meetings().stream()
.filter(crewMeeting -> !crewMeeting.isBlockedMeeting())
.map(MeetingResponse::of)
.toList();
}
@Transactional(readOnly = true)
public FloatingButtonResponse getFloatingButtonInfo(Long userId) {
boolean isActive = false;
if (userId != null) {
UserStatus userStatus = platformService.getStatus(userId);
isActive = userStatus == UserStatus.ACTIVE ?
appServiceService.getAppService(AppServiceName.FLOATING_BUTTON.getServiceName()).getActiveUser() :
appServiceService.getAppService(AppServiceName.FLOATING_BUTTON.getServiceName()).getInactiveUser();
}
Map<String, String> operationConfigMap = operationConfigService.getOperationConfigByOperationConfigType(OperationConfigCategory.FLOATING_BUTTON).stream()
.collect(Collectors.toMap(OperationConfig::getKey, OperationConfig::getValue));
return FloatingButtonResponse.of(
operationConfigMap.get("imageUrl"),
operationConfigMap.get("title"),
operationConfigMap.get("expandedSubTitle"),
operationConfigMap.get("collapsedSubtitle"),
operationConfigMap.get("actionButtonName"),
operationConfigMap.get("linkUrl"),
isActive
);
}
@Transactional(readOnly = true)
public ReviewFormResponse getReviewFormInfo(Long userId) {
boolean isActive = false;
if (userId != null) {
UserStatus userStatus = platformService.getStatus(userId);
isActive = userStatus == UserStatus.ACTIVE ?
appServiceService.getAppService(AppServiceName.REVIEW_FORM.getServiceName()).getActiveUser() :
appServiceService.getAppService(AppServiceName.REVIEW_FORM.getServiceName()).getInactiveUser();
}
Map<String, String> operationConfigMap = operationConfigService
.getOperationConfigByOperationConfigType(OperationConfigCategory.REVIEW_FORM).stream()
.collect(Collectors.toMap(OperationConfig::getKey, OperationConfig::getValue));
return ReviewFormResponse.of(
operationConfigMap.get("title"),
operationConfigMap.get("subTitle"),
operationConfigMap.get("actionButtonName"),
operationConfigMap.get("linkUrl"),
isActive
);
}
@Transactional(readOnly = true)
public List<PlaygroundRecentPost> getPlaygroundRecentPosts(Long userId) {
List<OperationConfig> configList = operationConfigService.getOperationConfigByOperationConfigType(OperationConfigCategory.PLAYGROUND_POST);
Map<String, String> imageConfigMap = PlaygroundRecentPost.toImageConfigMap(configList);
return playgroundAuthService.getPlaygroundRecentPosts().stream()
.map(post -> PlaygroundRecentPost.from(
post.playgroundPostId(),
post.userId(),
post.profileImage(),
post.name(),
post.generationAndPart(),
post.category(),
post.title(),
post.content(),
post.webLink(),
post.createdAt(),
imageConfigMap
))
.toList();
}
@Transactional(readOnly = true)
public List<PlaygroundPopularPost> getPlaygroundPopularPosts(Long userId) {
return playgroundAuthService.getPlaygroundPopularPosts();
}
}