|
| 1 | +package apptive.team5.alarm.controller; |
| 2 | + |
| 3 | +import apptive.team5.alarm.dto.AlarmResponse; |
| 4 | +import apptive.team5.alarm.service.AlarmService; |
| 5 | +import lombok.RequiredArgsConstructor; |
| 6 | +import org.springframework.data.domain.Page; |
| 7 | +import org.springframework.data.domain.PageRequest; |
| 8 | +import org.springframework.data.domain.Pageable; |
| 9 | +import org.springframework.data.domain.Sort; |
| 10 | +import org.springframework.http.HttpStatus; |
| 11 | +import org.springframework.http.MediaType; |
| 12 | +import org.springframework.http.ResponseEntity; |
| 13 | +import org.springframework.security.core.annotation.AuthenticationPrincipal; |
| 14 | +import org.springframework.web.bind.annotation.GetMapping; |
| 15 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 16 | +import org.springframework.web.bind.annotation.RequestParam; |
| 17 | +import org.springframework.web.bind.annotation.RestController; |
| 18 | + |
| 19 | +@RestController |
| 20 | +@RequestMapping("/api/alarms") |
| 21 | +@RequiredArgsConstructor |
| 22 | +public class AlarmController { |
| 23 | + |
| 24 | + private final AlarmService alarmService; |
| 25 | + |
| 26 | + @GetMapping |
| 27 | + public ResponseEntity<Page<AlarmResponse>> getAlarms( |
| 28 | + @RequestParam(name = "page", defaultValue = "0") int page, |
| 29 | + @RequestParam(name = "size", defaultValue = "5") int size, |
| 30 | + @AuthenticationPrincipal Long userId |
| 31 | + ) { |
| 32 | + Pageable pageable = PageRequest.of( |
| 33 | + page, |
| 34 | + size, |
| 35 | + Sort.by( |
| 36 | + Sort.Order.desc("createDateTime"), |
| 37 | + Sort.Order.desc("id") |
| 38 | + ) |
| 39 | + ); |
| 40 | + Page<AlarmResponse> alarms = alarmService.getAlarms(userId, pageable); |
| 41 | + |
| 42 | + return ResponseEntity.status(HttpStatus.OK).body(alarms); |
| 43 | + } |
| 44 | +} |
0 commit comments