-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGroupEntryController.java
More file actions
120 lines (100 loc) · 5.19 KB
/
GroupEntryController.java
File metadata and controls
120 lines (100 loc) · 5.19 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
package com.studypals.domain.groupManage.api;
import java.net.URI;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Size;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import com.studypals.domain.groupManage.dto.*;
import com.studypals.domain.groupManage.service.GroupEntryService;
import com.studypals.global.annotations.CursorDefault;
import com.studypals.global.request.Cursor;
import com.studypals.global.request.DateSortType;
import com.studypals.global.responses.CommonResponse;
import com.studypals.global.responses.CursorResponse;
import com.studypals.global.responses.Response;
import com.studypals.global.responses.ResponseCode;
/**
* 그룹 가입 관리에 대한 컨트롤러입니다. 담당하는 엔드포인트는 다음과 같습니다.
*
* <pre>
* - POST /groups/{groupId}/entry-code : 그룹 초대 코드 생성
* - GET /groups/summary : 그룹 대표 정보 조회
* - POST /groups/join : 공개 그룹에 가입
* - POST /groups/entry-requests : 비공개 그룹 가입 요청
* - GET /groups/{groupId}/entry-requests : 그룹 가입 요청 목록 조회
* - POST /groups/entry-requests/{requestId}/accept : 그룹 가입 요청 승인
* - DELETE /groups/entry-requests/{requestId} : 그룹 가입 요청 거절
*
* - GET /groups : 멤버가 속한 그룹 정보 요청
* - GET /groups/{groupId} : 멤버가 속한 특정 그룹에 대한 정보 요청
* </pre>
*
* @author s0o0bn
* @since 2025-04-25
*/
@RestController
@RequestMapping("/groups")
@RequiredArgsConstructor
public class GroupEntryController {
private final GroupEntryService groupEntryService;
@PostMapping("/{groupId}/entry-code")
public ResponseEntity<Response<GroupEntryCodeRes>> generateEntryCode(
@AuthenticationPrincipal Long userId, @PathVariable Long groupId) {
GroupEntryCodeRes codeResponse = groupEntryService.getOrCreateEntryCode(userId, groupId);
Response<GroupEntryCodeRes> response = CommonResponse.success(ResponseCode.GROUP_ENTRY_CODE, codeResponse);
return ResponseEntity.created(URI.create("/groups/" + groupId + "/entry-code/" + codeResponse.code()))
.body(response);
}
@PatchMapping("/{groupId}/entry-code")
public ResponseEntity<Void> increaseCodeExpire(
@AuthenticationPrincipal Long userId,
@PathVariable Long groupId,
@Valid @RequestBody UpdateEntryCodeReq req) {
groupEntryService.changeEntryCodeSetting(userId, groupId, req.day());
return ResponseEntity.noContent().build();
}
@GetMapping("/summary")
public ResponseEntity<Response<GroupSummaryRes>> getGroupSummary(
@RequestParam(required = true)
@Size(min = 6, max = 6, message = "entry code must be exactly 6 characters long.")
String entryCode) {
GroupSummaryRes response = groupEntryService.getGroupSummary(entryCode);
return ResponseEntity.ok(CommonResponse.success(ResponseCode.GROUP_SUMMARY, response));
}
@PostMapping("/join")
public ResponseEntity<Void> joinGroup(@AuthenticationPrincipal Long userId, @Valid @RequestBody GroupEntryReq req) {
Long joinId = groupEntryService.joinGroup(userId, req);
return ResponseEntity.created(URI.create(String.format("/groups/%d/members/%d", req.groupId(), joinId)))
.build();
}
@PostMapping("/entry-requests")
public ResponseEntity<Void> requestGroupParticipant(
@AuthenticationPrincipal Long userId, @Valid @RequestBody GroupEntryReq req) {
Long requestId = groupEntryService.requestParticipant(userId, req);
return ResponseEntity.created(URI.create(String.format("/groups/%d/requests/%d", req.groupId(), requestId)))
.build();
}
@GetMapping("/{groupId}/entry-requests")
public ResponseEntity<CursorResponse<GroupEntryRequestDto>> getEntryRequests(
@AuthenticationPrincipal Long userId,
@PathVariable Long groupId,
@CursorDefault(sortType = DateSortType.class) Cursor cursor) {
CursorResponse.Content<GroupEntryRequestDto> response =
groupEntryService.getEntryRequests(userId, groupId, cursor);
return ResponseEntity.ok(CursorResponse.success(ResponseCode.GROUP_ENTRY_REQUEST_LIST, response));
}
@PostMapping("/entry-requests/{requestId}/accept")
public ResponseEntity<Void> acceptEntryRequest(@AuthenticationPrincipal Long userId, @PathVariable Long requestId) {
AcceptEntryRes response = groupEntryService.acceptEntryRequest(userId, requestId);
return ResponseEntity.created(
URI.create(String.format("/groups/%d/members/%d", response.groupId(), response.memberId())))
.build();
}
@DeleteMapping("/entry-requests/{requestId}")
public ResponseEntity<Void> refuseEntryRequest(@AuthenticationPrincipal Long userId, @PathVariable Long requestId) {
groupEntryService.refuseEntryRequest(userId, requestId);
return ResponseEntity.noContent().build();
}
}