add entities for Brand, Category, Condition, Image, Platform, and Product with relationships

This commit is contained in:
Vincent Guillet
2025-10-14 14:50:21 +02:00
parent de1df47474
commit 611eb685a8
2 changed files with 55 additions and 1 deletions

View File

@@ -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<Brand> getAllBrands() {
return brandService.getAllBrands();
}
@GetMapping("/{id}")
public ResponseEntity<Brand> 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<Brand> 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<Brand> deleteBrandById(@PathVariable Long id) {
return brandService.deleteBrandById(id)
.map(brand -> ResponseEntity.ok().body(brand))
.orElse(ResponseEntity.notFound().build());
}
}

View File

@@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/users") @RequestMapping("/api/users")
public class UserController { public class UserController {
private final UserService userService; private final UserService userService;