-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBadgeController.java
More file actions
90 lines (80 loc) · 3.35 KB
/
BadgeController.java
File metadata and controls
90 lines (80 loc) · 3.35 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
package com.gpt.geumpumtabackend.badge.controller;
import com.gpt.geumpumtabackend.badge.api.BadgeApi;
import com.gpt.geumpumtabackend.badge.dto.request.BadgeCreateRequest;
import com.gpt.geumpumtabackend.badge.dto.request.RepresentativeBadgeRequest;
import com.gpt.geumpumtabackend.badge.dto.response.BadgeCreateResponse;
import com.gpt.geumpumtabackend.badge.dto.response.BadgeResponse;
import com.gpt.geumpumtabackend.badge.dto.response.MyBadgeResponse;
import com.gpt.geumpumtabackend.badge.dto.response.MyBadgeStatusResponse;
import com.gpt.geumpumtabackend.badge.dto.response.RepresentativeBadgeResponse;
import com.gpt.geumpumtabackend.badge.service.BadgeService;
import com.gpt.geumpumtabackend.global.aop.AssignUserId;
import com.gpt.geumpumtabackend.global.response.ResponseBody;
import com.gpt.geumpumtabackend.global.response.ResponseUtil;
import lombok.RequiredArgsConstructor;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/badge")
public class BadgeController implements BadgeApi {
private final BadgeService badgeService;
@PostMapping
@PreAuthorize("isAuthenticated() and hasRole('ADMIN')")
public ResponseEntity<ResponseBody<BadgeCreateResponse>> createBadge(
@RequestBody @Valid BadgeCreateRequest request
){
return ResponseEntity.ok(ResponseUtil.createSuccessResponse(
badgeService.createBadge(request)
));
}
@GetMapping
@PreAuthorize("isAuthenticated() and hasRole('ADMIN')")
public ResponseEntity<ResponseBody<List<BadgeResponse>>> getAllBadges() {
return ResponseEntity.ok(ResponseUtil.createSuccessResponse(
badgeService.getAllBadges()
));
}
@DeleteMapping("/{badgeId}")
@PreAuthorize("isAuthenticated() and hasRole('ADMIN')")
public ResponseEntity<ResponseBody<Void>> deleteBadge(
@PathVariable Long badgeId
) {
badgeService.deleteBadge(badgeId);
return ResponseEntity.ok(ResponseUtil.createSuccessResponse());
}
@GetMapping("/me")
@AssignUserId
@PreAuthorize("isAuthenticated() and hasRole('USER')")
public ResponseEntity<ResponseBody<List<MyBadgeStatusResponse>>> getMyBadges(
Long userId
){
return ResponseEntity.ok(ResponseUtil.createSuccessResponse(
badgeService.getMyBadges(userId)
));
}
@PostMapping("/me/representative-badge")
@AssignUserId
@PreAuthorize("isAuthenticated() and hasRole('USER')")
public ResponseEntity<ResponseBody<RepresentativeBadgeResponse>> setRepresentativeBadge(
@RequestBody RepresentativeBadgeRequest request,
Long userId
){
return ResponseEntity.ok(ResponseUtil.createSuccessResponse(
badgeService.setRepresentativeBadge(request, userId)
));
}
@GetMapping("/unnotified")
@AssignUserId
@PreAuthorize("isAuthenticated() and hasRole('USER')")
public ResponseEntity<ResponseBody<List<MyBadgeResponse>>> getUnnotifiedBadges(
Long userId
){
return ResponseEntity.ok(ResponseUtil.createSuccessResponse(
badgeService.getUnnotifiedBadges(userId)
));
}
}