| 1 | package com.nikola.web3ednevnikbackend.controller;
|
|---|
| 2 |
|
|---|
| 3 | import com.nikola.web3ednevnikbackend.dto.annoucements.SoopstenieRequestDTO;
|
|---|
| 4 | import com.nikola.web3ednevnikbackend.dto.annoucements.SoopstenieResponseDTO;
|
|---|
| 5 |
|
|---|
| 6 | import com.nikola.web3ednevnikbackend.service.annoucements.SoopstenieService;
|
|---|
| 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 | import org.springframework.web.bind.annotation.*;
|
|---|
| 12 |
|
|---|
| 13 | import java.util.List;
|
|---|
| 14 | import java.util.UUID;
|
|---|
| 15 |
|
|---|
| 16 | @RestController
|
|---|
| 17 | @RequestMapping("/api/soopstenie")
|
|---|
| 18 | public class AnnouncementController {
|
|---|
| 19 | private final SoopstenieService soopstenieService;
|
|---|
| 20 |
|
|---|
| 21 | public AnnouncementController(SoopstenieService soopstenieService) {
|
|---|
| 22 | this.soopstenieService = soopstenieService;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | @PreAuthorize("hasAnyRole('KLASEN_RAKOVODITEL','DIREKTOR_ADMIN', 'PREDMETEN_NASTAVNIK', 'RODITEL')")
|
|---|
| 26 | @GetMapping
|
|---|
| 27 | public ResponseEntity<List<SoopstenieResponseDTO>> getAllSoopstenija(){
|
|---|
| 28 | List<SoopstenieResponseDTO> soopstenija =this.soopstenieService.getAllSoopstenija();
|
|---|
| 29 | return new ResponseEntity<>(soopstenija, HttpStatus.OK);
|
|---|
| 30 | }
|
|---|
| 31 | @GetMapping("/{id}")
|
|---|
| 32 | public ResponseEntity <SoopstenieResponseDTO> getSoopstenieById(@PathVariable("id") UUID id){
|
|---|
| 33 | SoopstenieResponseDTO soopstenieResponseDTO =this.soopstenieService.getSoopstenieById(id);
|
|---|
| 34 | return new ResponseEntity<>(soopstenieResponseDTO, HttpStatus.OK);
|
|---|
| 35 | }
|
|---|
| 36 | @PreAuthorize("hasAnyRole('KLASEN_RAKOVODITEL', 'PREDMETEN_NASTAVNIK')")
|
|---|
| 37 | @PostMapping
|
|---|
| 38 | public ResponseEntity <Void> createSoopstenie(@Valid @RequestBody SoopstenieRequestDTO soopstenieRequestDTO){
|
|---|
| 39 | this.soopstenieService.createSoopstenie(soopstenieRequestDTO);
|
|---|
| 40 | return new ResponseEntity<>(HttpStatus.CREATED);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | @PreAuthorize("hasAnyRole('KLASEN_RAKOVODITEL','DIREKTOR_ADMIN', 'PREDMETEN_NASTAVNIK')")
|
|---|
| 44 | @DeleteMapping("/{id}")
|
|---|
| 45 | public ResponseEntity <Void> deleteSoopstenie(@PathVariable("id") UUID id){
|
|---|
| 46 | this.soopstenieService.deleteSoopstenie(id);
|
|---|
| 47 | return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | }
|
|---|