|
| 1 | +package org.layer.admin.popup.controller; |
| 2 | + |
| 3 | +import org.layer.admin.popup.controller.dto.AdminPopupRequest.CreatePopupRequest; |
| 4 | +import org.layer.admin.popup.controller.dto.AdminPopupRequest.UpdatePopupActiveRequest; |
| 5 | +import org.layer.admin.popup.controller.dto.AdminPopupRequest.UpdatePopupRequest; |
| 6 | +import org.layer.admin.popup.controller.dto.AdminPopupResponse.PopupCreateResponse; |
| 7 | +import org.layer.admin.popup.controller.dto.AdminPopupResponse.PopupDetail; |
| 8 | +import org.layer.admin.popup.controller.dto.AdminPopupResponse.PopupPage; |
| 9 | +import org.layer.admin.popup.service.AdminPopupService; |
| 10 | +import org.springframework.http.ResponseEntity; |
| 11 | +import org.springframework.web.bind.annotation.GetMapping; |
| 12 | +import org.springframework.web.bind.annotation.PatchMapping; |
| 13 | +import org.springframework.web.bind.annotation.PathVariable; |
| 14 | +import org.springframework.web.bind.annotation.PostMapping; |
| 15 | +import org.springframework.web.bind.annotation.PutMapping; |
| 16 | +import org.springframework.web.bind.annotation.RequestBody; |
| 17 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 18 | +import org.springframework.web.bind.annotation.RequestParam; |
| 19 | +import org.springframework.web.bind.annotation.RestController; |
| 20 | + |
| 21 | +import jakarta.validation.Valid; |
| 22 | +import lombok.RequiredArgsConstructor; |
| 23 | + |
| 24 | +@RestController |
| 25 | +@RequiredArgsConstructor |
| 26 | +@RequestMapping("/admin/popup") |
| 27 | +public class AdminPopupController { |
| 28 | + |
| 29 | + private final AdminPopupService adminPopupService; |
| 30 | + |
| 31 | + @GetMapping("") |
| 32 | + public ResponseEntity<PopupPage> getPopups( |
| 33 | + @RequestParam(defaultValue = "0") int page, |
| 34 | + @RequestParam(defaultValue = "20") int size) { |
| 35 | + return ResponseEntity.ok(adminPopupService.getPopups(page, size)); |
| 36 | + } |
| 37 | + |
| 38 | + @GetMapping("/{popupId}") |
| 39 | + public ResponseEntity<PopupDetail> getPopup(@PathVariable Long popupId) { |
| 40 | + return ResponseEntity.ok(adminPopupService.getPopup(popupId)); |
| 41 | + } |
| 42 | + |
| 43 | + @PostMapping("") |
| 44 | + public ResponseEntity<PopupCreateResponse> createPopup(@RequestBody @Valid CreatePopupRequest request) { |
| 45 | + Long popupId = adminPopupService.createPopup(request); |
| 46 | + return ResponseEntity.ok(PopupCreateResponse.builder().popupId(popupId).build()); |
| 47 | + } |
| 48 | + |
| 49 | + @PutMapping("/{popupId}") |
| 50 | + public ResponseEntity<Void> updatePopup(@PathVariable Long popupId, |
| 51 | + @RequestBody @Valid UpdatePopupRequest request) { |
| 52 | + adminPopupService.updatePopup(popupId, request); |
| 53 | + return ResponseEntity.ok().build(); |
| 54 | + } |
| 55 | + |
| 56 | + @PatchMapping("/{popupId}/active") |
| 57 | + public ResponseEntity<Void> updatePopupActive(@PathVariable Long popupId, |
| 58 | + @RequestBody @Valid UpdatePopupActiveRequest request) { |
| 59 | + adminPopupService.updatePopupActive(popupId, request); |
| 60 | + return ResponseEntity.ok().build(); |
| 61 | + } |
| 62 | +} |
0 commit comments