source: backend/web3-Ednevnik-Backend/src/main/java/com/nikola/web3ednevnikbackend/controller/AnnouncementController.java

Last change on this file was 81cdf2d, checked in by Nikola Janev <nikolajanev57@…>, 9 days ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1package com.nikola.web3ednevnikbackend.controller;
2
3import com.nikola.web3ednevnikbackend.dto.annoucements.SoopstenieRequestDTO;
4import com.nikola.web3ednevnikbackend.dto.annoucements.SoopstenieResponseDTO;
5
6import com.nikola.web3ednevnikbackend.service.annoucements.SoopstenieService;
7import jakarta.validation.Valid;
8import org.springframework.http.HttpStatus;
9import org.springframework.http.ResponseEntity;
10import org.springframework.security.access.prepost.PreAuthorize;
11import org.springframework.web.bind.annotation.*;
12
13import java.util.List;
14import java.util.UUID;
15
16@RestController
17@RequestMapping("/api/soopstenie")
18public 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}
Note: See TracBrowser for help on using the repository browser.