-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupCardSetController.java
More file actions
91 lines (77 loc) · 3.5 KB
/
GroupCardSetController.java
File metadata and controls
91 lines (77 loc) · 3.5 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
package project.flipnote.cardset.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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.ModelAttribute;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import project.flipnote.cardset.controller.docs.GroupCardSetControllerDocs;
import project.flipnote.cardset.model.CardSetDetailResponse;
import project.flipnote.cardset.model.CardSetSearchRequest;
import project.flipnote.cardset.model.CardSetSummaryResponse;
import project.flipnote.cardset.model.CardSetUpdateRequest;
import project.flipnote.cardset.model.CreateCardSetRequest;
import project.flipnote.cardset.model.CreateCardSetResponse;
import project.flipnote.cardset.service.CardSetService;
import project.flipnote.common.model.response.IdResponse;
import project.flipnote.common.model.response.PagingResponse;
import project.flipnote.common.security.dto.AuthPrinciple;
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/groups/{groupId}/card-sets")
public class GroupCardSetController implements GroupCardSetControllerDocs {
private final CardSetService cardSetService;
@PostMapping("")
public ResponseEntity<CreateCardSetResponse> createCardSet(
@AuthenticationPrincipal AuthPrinciple authPrinciple,
@PathVariable("groupId") Long groupId,
@RequestBody @Valid CreateCardSetRequest req
) {
CreateCardSetResponse res = cardSetService.createCardSet(groupId, authPrinciple, req);
return ResponseEntity.status(HttpStatus.CREATED).body(res);
}
@GetMapping("/{cardSetId}")
public ResponseEntity<CardSetDetailResponse> getCardSet(
@PathVariable("groupId") Long groupId,
@PathVariable("cardSetId") Long cardSetId,
@AuthenticationPrincipal AuthPrinciple authPrinciple
) {
CardSetDetailResponse res = cardSetService.getCardSet(authPrinciple.userId(), groupId, cardSetId);
return ResponseEntity.ok(res);
}
@PutMapping("/{cardSetId}")
public ResponseEntity<CardSetDetailResponse> updateCardSet(
@PathVariable("groupId") Long groupId,
@PathVariable("cardSetId") Long cardSetId,
@Valid @RequestBody CardSetUpdateRequest req,
@AuthenticationPrincipal AuthPrinciple authPrinciple
) {
CardSetDetailResponse res = cardSetService.updateCardSet(authPrinciple.userId(), groupId, cardSetId, req);
return ResponseEntity.ok(res);
}
@GetMapping
public ResponseEntity<PagingResponse<CardSetSummaryResponse>> getCardSets(
@PathVariable("groupId") Long groupId,
@Valid @ModelAttribute CardSetSearchRequest req
) {
PagingResponse<CardSetSummaryResponse> res = cardSetService.getCardSets(groupId, req);
return ResponseEntity.ok(res);
}
@DeleteMapping("/{cardSetId}")
public ResponseEntity<IdResponse> deleteCardSet(
@PathVariable("groupId") Long groupId,
@PathVariable("cardSetId") Long cardSetId,
@AuthenticationPrincipal AuthPrinciple authPrinciple
) {
IdResponse res = cardSetService.deleteCardSet(authPrinciple.userId(), groupId, cardSetId);
return ResponseEntity.ok(res);
}
}