-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupController.java
More file actions
114 lines (97 loc) · 3.31 KB
/
GroupController.java
File metadata and controls
114 lines (97 loc) · 3.31 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
package flipnote.group.adapter.in.web;
import org.springframework.http.ResponseEntity;
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.FindGroupUseCase;
import flipnote.group.application.port.in.command.ChangeGroupCommand;
import flipnote.group.application.port.in.command.CreateGroupCommand;
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;
/**
* 그룹 생성 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);
}
}