Initial commit with basic CRUD functionality:
* GET all properties * GET one property by id * CREATE one property * DELETE one property by id
This commit is contained in:
@@ -3,6 +3,7 @@ package de.iwomm.propify_api.controller;
|
||||
import de.iwomm.propify_api.entity.Property;
|
||||
import de.iwomm.propify_api.service.PropertyService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -18,24 +19,34 @@ public class PropertyController {
|
||||
this.propertyService = propertyService;
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
public String infoEndpoint() {
|
||||
return "Hello, you are authenticated!";
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_USER')")
|
||||
public List<Property> getAllProperties() {
|
||||
return propertyService.findAll();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN', 'USER')")
|
||||
public Property getPropertyById(@PathVariable UUID id) {
|
||||
return propertyService.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public Property createProperty(@RequestBody Property property) {
|
||||
return propertyService.save(property);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public void deleteProperty(@PathVariable UUID id) {
|
||||
Optional<Property> property = propertyService.findById(id);
|
||||
if (property.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user