-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminNotificationController.java
More file actions
59 lines (53 loc) · 2.63 KB
/
AdminNotificationController.java
File metadata and controls
59 lines (53 loc) · 2.63 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
package Gotcha.domain.notification.controller;
import Gotcha.domain.notification.api.AdminNotificationApi;
import Gotcha.domain.notification.service.AdminNotificationService;
import gotcha_domain.auth.SecurityUserDetails;
import gotcha_common.dto.SuccessRes;
import gotcha_domain.notification.NotificationReq;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
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;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/admin/notification")
public class AdminNotificationController implements AdminNotificationApi {
private final AdminNotificationService adminNotificationService;
@Override
@PostMapping
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<?> createNotification(
@Valid @RequestBody NotificationReq notificationReq,
@AuthenticationPrincipal SecurityUserDetails userDetails){
adminNotificationService.createNotification(notificationReq, userDetails.getId());
return ResponseEntity.ok(SuccessRes.from("공지사항 생성에 성공했습니다."));
}
@Override
@PutMapping("/{notificationId}")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<?> updateNotification(
@PathVariable(value = "notificationId") Long notificationId,
@Valid @RequestBody NotificationReq notificationReq,
@AuthenticationPrincipal SecurityUserDetails userDetails){
adminNotificationService.updateNotification(notificationReq, notificationId);
return ResponseEntity.ok(SuccessRes.from("공지사항 수정에 성공했습니다."));
}
@Override
@DeleteMapping("/{notificationId}")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<?> deleteNotification(
@PathVariable(value = "notificationId") Long notificationId,
@AuthenticationPrincipal SecurityUserDetails userDetails){
adminNotificationService.deleteNotification(notificationId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}