| 1 | package com.nikola.web3ednevnikbackend.controller;
|
|---|
| 2 |
|
|---|
| 3 | import com.nikola.web3ednevnikbackend.dto.attendance.PrisustvoRequestDTO;
|
|---|
| 4 | import com.nikola.web3ednevnikbackend.dto.attendance.PrisustvoResponseDTO;
|
|---|
| 5 |
|
|---|
| 6 | import com.nikola.web3ednevnikbackend.service.attendance.PrisustvoService;
|
|---|
| 7 | import jakarta.validation.Valid;
|
|---|
| 8 | import org.springframework.http.HttpStatus;
|
|---|
| 9 | import org.springframework.http.ResponseEntity;
|
|---|
| 10 | import org.springframework.security.access.prepost.PreAuthorize;
|
|---|
| 11 |
|
|---|
| 12 | import org.springframework.web.bind.annotation.*;
|
|---|
| 13 |
|
|---|
| 14 | import java.util.List;
|
|---|
| 15 | import java.util.UUID;
|
|---|
| 16 |
|
|---|
| 17 | @RestController
|
|---|
| 18 |
|
|---|
| 19 | @RequestMapping("/api/prisustvo")
|
|---|
| 20 | public class AttendanceController {
|
|---|
| 21 | private final PrisustvoService prisustvoService;
|
|---|
| 22 |
|
|---|
| 23 | public AttendanceController(PrisustvoService prisustvoService) {
|
|---|
| 24 | this.prisustvoService = prisustvoService;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | @PreAuthorize("hasAnyRole('KLASEN_RAKOVODITEL','DIREKTOR_ADMIN', 'PREDMETEN_NASTAVNIK', 'RODITEL')")
|
|---|
| 28 | @GetMapping
|
|---|
| 29 | public ResponseEntity<List<PrisustvoResponseDTO>> getAllPrisustva(){
|
|---|
| 30 | List<PrisustvoResponseDTO> prisustva =this.prisustvoService.getAllPrisustva();
|
|---|
| 31 | return new ResponseEntity<>(prisustva, HttpStatus.OK);
|
|---|
| 32 | }
|
|---|
| 33 | @PreAuthorize("hasAnyRole('KLASEN_RAKOVODITEL','DIREKTOR_ADMIN', 'PREDMETEN_NASTAVNIK', 'RODITEL')")
|
|---|
| 34 | @GetMapping("/{id}")
|
|---|
| 35 | public ResponseEntity<PrisustvoResponseDTO> getPrisustvoById(@PathVariable UUID id){
|
|---|
| 36 | PrisustvoResponseDTO prisustvo = this.prisustvoService.getPrisustvoById(id);
|
|---|
| 37 | return new ResponseEntity<>(prisustvo, HttpStatus.OK);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | // POST /api/attendance
|
|---|
| 41 | @PreAuthorize("hasAnyRole('KLASEN_RAKOVODITEL', 'PREDMETEN_NASTAVNIK')")
|
|---|
| 42 | @PostMapping
|
|---|
| 43 | public ResponseEntity<PrisustvoResponseDTO> createPrisustvo(@Valid @RequestBody PrisustvoRequestDTO prisustvoRequestDTO) {
|
|---|
| 44 | System.out.println(prisustvoRequestDTO.toString());
|
|---|
| 45 | return new ResponseEntity<>( this.prisustvoService.createPrisustvo(prisustvoRequestDTO), HttpStatus.CREATED);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | }
|
|---|