diff --git a/api/src/main/java/fr/gameovergne/api/controller/app/BrandController.java b/api/src/main/java/fr/gameovergne/api/controller/app/BrandController.java new file mode 100644 index 0000000..d3e9734 --- /dev/null +++ b/api/src/main/java/fr/gameovergne/api/controller/app/BrandController.java @@ -0,0 +1,54 @@ +package fr.gameovergne.api.controller.app; + +import fr.gameovergne.api.model.app.Brand; +import fr.gameovergne.api.service.app.BrandService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/brands") +public class BrandController { + + private final BrandService brandService; + + @Autowired + public BrandController(BrandService brandService) { + this.brandService = brandService; + } + + @GetMapping + public List getAllBrands() { + return brandService.getAllBrands(); + } + + @GetMapping("/{id}") + public ResponseEntity getBrandById(@PathVariable Long id) { + return brandService.getBrandById(id) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); + } + + @PostMapping + public void saveBrand(@RequestBody Brand brand) { + brandService.saveBrand(brand); + } + + @PutMapping("/{id}") + public ResponseEntity updateBrand(@PathVariable Long id, @RequestBody Brand brand) { + return brandService.getBrandById(id) + .map(existingBrand -> brandService.updateBrand(brand) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build())) + .orElse(ResponseEntity.notFound().build()); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteBrandById(@PathVariable Long id) { + return brandService.deleteBrandById(id) + .map(brand -> ResponseEntity.ok().body(brand)) + .orElse(ResponseEntity.notFound().build()); + } +} diff --git a/api/src/main/java/fr/gameovergne/api/controller/user/UserController.java b/api/src/main/java/fr/gameovergne/api/controller/user/UserController.java index d09c3c8..9742d93 100644 --- a/api/src/main/java/fr/gameovergne/api/controller/user/UserController.java +++ b/api/src/main/java/fr/gameovergne/api/controller/user/UserController.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/users") +@RequestMapping("/api/users") public class UserController { private final UserService userService;