-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupController.java
More file actions
148 lines (122 loc) · 4.17 KB
/
GroupController.java
File metadata and controls
148 lines (122 loc) · 4.17 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
package flipnote.group.adapter.in.web;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import flipnote.group.api.dto.request.ChangeGroupRequestDto;
import flipnote.group.api.dto.request.CreateGroupRequestDto;
import flipnote.group.api.dto.response.ChangeGroupResponseDto;
import flipnote.group.api.dto.response.CreateGroupResponseDto;
import flipnote.group.api.dto.response.FindGroupResponseDto;
import flipnote.group.application.port.in.ChangeGroupUseCase;
import flipnote.group.application.port.in.CreateGroupUseCase;
import flipnote.group.application.port.in.DeleteGroupUseCase;
import flipnote.group.application.port.in.FindGroupUseCase;
import flipnote.group.application.port.in.command.ChangeGroupCommand;
import flipnote.group.application.port.in.command.CreateGroupCommand;
import flipnote.group.application.port.in.command.DeleteGroupCommand;
import flipnote.group.application.port.in.command.FindGroupCommand;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/groups")
public class GroupController {
private final CreateGroupUseCase createGroupUseCase;
private final ChangeGroupUseCase changeGroupUseCase;
private final FindGroupUseCase findGroupUseCase;
private final DeleteGroupUseCase deleteGroupUseCase;
/**
* 그룹 생성 API
* @param userId
* @param req
* @return
*/
@PostMapping("")
public ResponseEntity<CreateGroupResponseDto> createGroup(
@RequestHeader("X-USER-ID") Long userId,
@RequestBody @Valid CreateGroupRequestDto req) {
CreateGroupCommand cmd = new CreateGroupCommand(
userId,
req.name(),
req.category(),
req.description(),
req.joinPolicy(),
req.visibility(),
req.maxMember(),
req.imageRefId()
);
var result = createGroupUseCase.create(cmd);
CreateGroupResponseDto res = CreateGroupResponseDto.from(result.groupId());
return ResponseEntity.ok(res);
}
/**
* 그룹 수정 API
* @param userId
* @param groupId
* @param req
* @return
*/
@PutMapping("/{groupId}")
public ResponseEntity<ChangeGroupResponseDto> changeGroup(
@RequestHeader("X-USER-ID") Long userId,
@PathVariable Long groupId,
@RequestBody @Valid ChangeGroupRequestDto req) {
ChangeGroupCommand cmd = new ChangeGroupCommand(
groupId,
userId,
req.name(),
req.category(),
req.description(),
req.joinPolicy(),
req.visibility(),
req.maxMember(),
req.imageRefId()
);
var result = changeGroupUseCase.change(cmd);
ChangeGroupResponseDto res = ChangeGroupResponseDto.from(result);
return ResponseEntity.ok(res);
}
/**
* 그룹 상세 조회 API
* @param userId
* @param groupId
* @return
*/
@GetMapping("/{groupId}")
public ResponseEntity<FindGroupResponseDto> findGroup(
@RequestHeader("X-USER-ID") Long userId,
@PathVariable("groupId") Long groupId) {
FindGroupCommand cmd = new FindGroupCommand(userId, groupId);
var result = findGroupUseCase.findGroup(cmd);
FindGroupResponseDto res = FindGroupResponseDto.from(result);
return ResponseEntity.ok(res);
}
/**
* 그룹 삭제
* todo 추후 권한 체크 후 권한 확인 후 삭제
* @param userId
* @param groupId
* @return
*/
@DeleteMapping("/{groupId}")
public ResponseEntity<Void> deleteGroup(
@RequestHeader("X-USER-ID") Long userId,
@PathVariable("groupId") Long groupId
) {
DeleteGroupCommand cmd = new DeleteGroupCommand(userId, groupId);
deleteGroupUseCase.deleteGroup(cmd);
return ResponseEntity.noContent().build();
}
//todo 그룹 내 멤버 조회
//todo 그룹 전체 조회
//todo 내 그룹 전체 조회
//todo 내가 생성한 그룹 전체 조회
//todo 하위 권한 수정
}