-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserController.java
More file actions
226 lines (206 loc) Β· 13.1 KB
/
Copy pathUserController.java
File metadata and controls
226 lines (206 loc) Β· 13.1 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package ssu.eatssu.domain.user.presentation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ssu.eatssu.domain.auth.security.CustomUserDetails;
import ssu.eatssu.domain.partnership.dto.PartnershipResponse;
import ssu.eatssu.domain.partnership.service.PartnershipService;
import ssu.eatssu.domain.review.service.ReviewServiceV2;
import ssu.eatssu.domain.slice.dto.SliceResponse;
import ssu.eatssu.domain.slice.service.SliceService;
import ssu.eatssu.domain.user.dto.DepartmentResponse;
import ssu.eatssu.domain.user.dto.GetCollegeResponse;
import ssu.eatssu.domain.user.dto.GetDepartmentResponse;
import ssu.eatssu.domain.user.dto.MyMealReviewResponse;
import ssu.eatssu.domain.user.dto.MyPageResponse;
import ssu.eatssu.domain.user.dto.MyReviewDetail;
import ssu.eatssu.domain.user.dto.NicknameUpdateRequest;
import ssu.eatssu.domain.user.dto.UpdateDepartmentRequest;
import ssu.eatssu.domain.user.service.UserService;
import ssu.eatssu.global.handler.response.BaseResponse;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/users")
@Tag(name = "User", description = "μ μ API")
public class UserController {
private final UserService userService;
private final SliceService sliceService;
private final PartnershipService partnershipService;
private final ReviewServiceV2 reviewServiceV2;
@Operation(summary = "μ΄λ©μΌ μ€λ³΅ 체ν¬", description = """
μ΄λ©μΌ μ€λ³΅ μ²΄ν¬ API μ
λλ€.<br><br>
μ€λ³΅λμ§ μμ μ΄λ©μΌμ΄λ©΄ true λ₯Ό λ°νν©λλ€
""")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μ€λ³΅λμ§ μμ μ΄λ©μΌ")
})
@PostMapping("/validate/email/{email}") //todo: μ€λ³΅μΈ κ²½μ° error throw, μ€λ³΅ μλλ©΄ ApiReposne return
public BaseResponse<Boolean> validateDuplicatedEmail(
@Parameter(description = "μ΄λ©μΌ") @PathVariable String email) {
return BaseResponse.success(userService.validateDuplicatedEmail(email));
}
@Operation(summary = "λλ€μ μ€λ³΅ 체ν¬", description = """
λλ€μ μ€λ³΅ μ²΄ν¬ API μ
λλ€.<br><br>
μ€λ³΅λμ§ μμ λλ€μμ΄λ©΄ true λ₯Ό λ°νν©λλ€
""")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μ€λ³΅λμ§ μμ λλ€μ")
})
@GetMapping("/validate/nickname")
public BaseResponse<Boolean> validateDuplicatedNickname(@Parameter(description = "λλ€μ")
@RequestParam(value = "nickname") String nickname) {
return BaseResponse.success(userService.validateDuplicatedNickname(nickname));
}
@Operation(summary = "λλ€μ μμ ", description = "λλ€μ μμ API μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "λλ€μ μμ μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
@PatchMapping("/nickname")
public BaseResponse<?> updateNickname(
@Valid @RequestBody NicknameUpdateRequest updateNicknameRequest,
@AuthenticationPrincipal CustomUserDetails userDetails) {
userService.updateNickname(userDetails, updateNicknameRequest);
return BaseResponse.success();
}
@Operation(summary = "μ μ νν΄", description = "μ μ νν΄ API μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μ μ νν΄ μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
@DeleteMapping("")
public BaseResponse<Boolean> withdraw(@AuthenticationPrincipal CustomUserDetails userDetails) {
return BaseResponse.success(userService.withdraw(userDetails));
}
@Operation(summary = "λ΄κ° μ΄ λ¦¬λ·° 리μ€νΈ μ‘°ν", description = "λ΄κ° μ΄ λ¦¬λ·° 리μ€νΈλ₯Ό μ‘°ννλ API μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "λ΄κ° μ΄ λ¦¬λ·° 리μ€νΈ μ‘°ν μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
@GetMapping("/reviews")
public BaseResponse<SliceResponse<MyReviewDetail>> getMyReviewList(
@Parameter(description = "λ§μ§λ§μΌλ‘ μ‘°νλ reviewIdκ°(첫 μ‘°νμ κ° νμ μμ)", in = ParameterIn.QUERY) @RequestParam(required = false) Long lastReviewId,
@ParameterObject @PageableDefault(size = 20, sort = "date", direction = Sort.Direction.DESC) Pageable pageable,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
SliceResponse<MyReviewDetail> myReviews = sliceService.findMyReviews(customUserDetails,
pageable,
lastReviewId);
return BaseResponse.success(myReviews);
}
@Operation(summary = "λ§μ΄νμ΄μ§ μ 보 μ‘°ν", description = "λ§μ΄νμ΄μ§ μ 보λ₯Ό μ‘°ννλ API μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "λ§μ΄νμ΄μ§ μ 보 μ‘°ν μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
@GetMapping("/mypage")
public BaseResponse<MyPageResponse> getMyPage(
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
return BaseResponse.success(userService.findMyPage(customUserDetails));
}
@Operation(summary = "μ μ κ° μ°ν μ ν΄ μ‘°ν", description = "μ μ κ° μ°ν μ ν΄λ₯Ό μ‘°ννλ API μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μ μ κ° μ°ν μ ν΄ μ‘°ν μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema =
@Schema(implementation = BaseResponse.class))),
})
@GetMapping("/partnerships")
public BaseResponse<List<PartnershipResponse>> getUserLikedPartnerships(
@AuthenticationPrincipal CustomUserDetails userDetails) {
return BaseResponse.success(partnershipService.getUserLikedPartnerships(userDetails));
}
@Operation(summary = "μ μ μ νκ³Ό λ±λ‘", description = "μ μ μ νκ³Όλ₯Ό λ±λ‘νλ API μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μ μ μ νκ³Ό λ±λ‘ μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema =
@Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ νκ³Ό", content = @Content(schema =
@Schema(implementation = BaseResponse.class))),
})
@PostMapping("/department")
public BaseResponse<?> registerDepartment(@RequestBody UpdateDepartmentRequest request,
@AuthenticationPrincipal CustomUserDetails userDetails) {
userService.registerDepartment(request, userDetails);
return BaseResponse.success();
}
@Operation(summary = "μ μ μ λ¨κ³Όλ/νκ³Ό μ ν΄ μ‘°ν", description = "μ μ μ λ¨κ³Όλ/νκ³Ό μ ν΄λ₯Ό μ‘°ννλ API μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μ μ μ λ¨κ³Όλ/νκ³Ό μ ν΄ μ‘°ν μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema =
@Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "400", description = "μ μ μ νκ³Ό μ λ³΄κ° λ±λ‘λμ§ μμ", content = @Content(schema =
@Schema(implementation = BaseResponse.class))),
})
@GetMapping("/department/partnerships")
public BaseResponse<List<PartnershipResponse>> getUserDepartmentPartnerships(
@AuthenticationPrincipal CustomUserDetails userDetails) {
return BaseResponse.success(partnershipService.getUserDepartmentPartnerships(userDetails));
}
@Operation(summary = "μ μ μ νκ³Ό μ‘°ν", description = "μ μ μ νκ³Όλ₯Ό μ‘°ννλ API μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "μ μ μ νκ³Ό μ‘°ν μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema =
@Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "400", description = "μ μ μ νκ³Ό μ λ³΄κ° λ±λ‘λμ§ μμ", content = @Content(schema =
@Schema(implementation = BaseResponse.class))),
})
@GetMapping("/department")
public BaseResponse<DepartmentResponse> getDepartment(@AuthenticationPrincipal CustomUserDetails userDetails) {
return BaseResponse.success(userService.getDepartment(userDetails));
}
@Operation(summary = "λ΄κ° μ΄ λ¦¬λ·° 리μ€νΈ μ‘°ν", description = "λ΄κ° μ΄ λ¦¬λ·° 리μ€νΈλ₯Ό μ‘°ννλ API V2 μ
λλ€.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "λ΄κ° μ΄ λ¦¬λ·° 리μ€νΈ μ‘°ν μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ μ μ ", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
@GetMapping("/v2/reviews")
public BaseResponse<SliceResponse<MyMealReviewResponse>> getMyReviews(
@Parameter(description = "λ§μ§λ§μΌλ‘ μ‘°νλ reviewIdκ°(첫 μ‘°νμ κ° νμ μμ)", in = ParameterIn.QUERY) @RequestParam(required = false) Long lastReviewId,
@ParameterObject @PageableDefault(size = 20, sort = "date", direction = Sort.Direction.DESC) Pageable pageable,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
SliceResponse<MyMealReviewResponse> myReviews = reviewServiceV2.findMyReviews(customUserDetails,
lastReviewId,
pageable);
return BaseResponse.success(myReviews);
}
@Operation(summary = "λ¨κ³Όλ μ‘°ν", description = "μμ€λνκ΅ λ¨κ³Όλν λ€μ μ‘°ννλ APIμ
λλ€.(ν ν° λΆνμ)")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "λ¨κ³Όλ 리μ€νΈ μ‘°ν μ±κ³΅"),
@ApiResponse(responseCode = "404", description = "μ‘΄μ¬νμ§ μλ λ¨κ³Όλ", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
@GetMapping("/lookup/colleges")
public BaseResponse<List<GetCollegeResponse>> getColleges() {
List<GetCollegeResponse> getCollegeResponses = userService.getCollegeList();
return BaseResponse.success(getCollegeResponses);
}
@Operation(summary = "λ¨κ³Όλμ λ°λ₯Έ νκ³Ό μ‘°ν", description = "λ¨κ³Όλνμ μ
λ ₯νλ©΄ λ¨κ³Όλμ μν μμ€λνκ΅ νκ³Όλ₯Ό μ‘°ννλ APIμ
λλ€.(ν ν° λΆνμ)")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "λ¨κ³Όλ 리μ€νΈ μ‘°ν μ±κ³΅"),
})
@GetMapping("/lookup/departments")
public BaseResponse<List<GetDepartmentResponse>> getDepartments(@RequestParam Long collegeId) {
List<GetDepartmentResponse> getCollegeResponses = userService.getDepartmentList(collegeId);
return BaseResponse.success(getCollegeResponses);
}
}