Delete unused files
This commit is contained in:
@@ -1,64 +0,0 @@
|
|||||||
package fr.gameovergne.api.controller.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.BrandDTO;
|
|
||||||
import fr.gameovergne.api.mapper.app.BrandMapper;
|
|
||||||
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.MediaType;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/app/brands")
|
|
||||||
public class BrandController {
|
|
||||||
|
|
||||||
private final BrandService brandService;
|
|
||||||
private final BrandMapper brandMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public BrandController(BrandService brandService, BrandMapper brandMapper) {
|
|
||||||
this.brandService = brandService;
|
|
||||||
this.brandMapper = brandMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<BrandDTO> getAllBrands() {
|
|
||||||
return brandService.getAllBrands()
|
|
||||||
.stream()
|
|
||||||
.map(brandMapper::toDto)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 BrandDTO brandDTO) {
|
|
||||||
brandService.saveBrand(brandMapper.fromDto(brandDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ResponseEntity<Brand> updateBrand(@PathVariable Long id, @RequestBody BrandDTO brandDTO) {
|
|
||||||
Brand brand = brandMapper.fromDto(brandDTO);
|
|
||||||
brand.setId(id);
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package fr.gameovergne.api.controller.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.CategoryDTO;
|
|
||||||
import fr.gameovergne.api.mapper.app.CategoryMapper;
|
|
||||||
import fr.gameovergne.api.model.app.Category;
|
|
||||||
import fr.gameovergne.api.service.app.CategoryService;
|
|
||||||
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/app/categories")
|
|
||||||
public class CategoryController {
|
|
||||||
|
|
||||||
private final CategoryService categoryService;
|
|
||||||
private final CategoryMapper categoryMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public CategoryController(CategoryService categoryService, CategoryMapper categoryMapper) {
|
|
||||||
this.categoryService = categoryService;
|
|
||||||
this.categoryMapper = categoryMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<CategoryDTO> getAllCategories() {
|
|
||||||
return categoryService.getAllCategories()
|
|
||||||
.stream()
|
|
||||||
.map(categoryMapper::toDto)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ResponseEntity<Category> getCategoryById(@PathVariable Long id) {
|
|
||||||
return categoryService.getCategoryById(id)
|
|
||||||
.map(ResponseEntity::ok)
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public void saveCategory(@RequestBody CategoryDTO categoryDTO) {
|
|
||||||
categoryService.saveCategory(categoryMapper.fromDto(categoryDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ResponseEntity<Category> updateCategory(@PathVariable Long id, @RequestBody CategoryDTO categoryDTO) {
|
|
||||||
Category category = categoryMapper.fromDto(categoryDTO);
|
|
||||||
category.setId(id);
|
|
||||||
return categoryService.getCategoryById(id)
|
|
||||||
.map(existingCategory -> categoryService.updateCategory(category)
|
|
||||||
.map(ResponseEntity::ok)
|
|
||||||
.orElse(ResponseEntity.notFound().build()))
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ResponseEntity<Category> deleteCategoryById(@PathVariable Long id) {
|
|
||||||
return categoryService.deleteCategoryById(id)
|
|
||||||
.map(category -> ResponseEntity.ok().body(category))
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package fr.gameovergne.api.controller.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.ConditionDTO;
|
|
||||||
import fr.gameovergne.api.model.app.Condition;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/app/conditions")
|
|
||||||
public class ConditionController {
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<ConditionDTO> list() {
|
|
||||||
return Arrays.stream(Condition.values())
|
|
||||||
.map(condition -> new ConditionDTO(condition.name(), condition.getDisplayName()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package fr.gameovergne.api.controller.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.ImageDTO;
|
|
||||||
import fr.gameovergne.api.mapper.app.ImageMapper;
|
|
||||||
import fr.gameovergne.api.model.app.Image;
|
|
||||||
import fr.gameovergne.api.service.app.ImageService;
|
|
||||||
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/app/images")
|
|
||||||
public class ImageController {
|
|
||||||
|
|
||||||
private final ImageService imageService;
|
|
||||||
private final ImageMapper imageMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ImageController(ImageService imageService, ImageMapper imageMapper) {
|
|
||||||
this.imageService = imageService;
|
|
||||||
this.imageMapper = imageMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<ImageDTO> getAllImages() {
|
|
||||||
return imageService.getAllImages()
|
|
||||||
.stream()
|
|
||||||
.map(imageMapper::toDto)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ResponseEntity<Image> getImageById(@PathVariable Long id) {
|
|
||||||
return imageService.getImageById(id)
|
|
||||||
.map(ResponseEntity::ok)
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public void saveImage(@RequestBody ImageDTO imageDTO) {
|
|
||||||
imageService.saveImage(imageMapper.fromDto(imageDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ResponseEntity<Image> updateImage(@PathVariable Long id, @RequestBody ImageDTO imageDTO) {
|
|
||||||
Image image = imageMapper.fromDto(imageDTO);
|
|
||||||
image.setId(id);
|
|
||||||
return imageService.getImageById(id)
|
|
||||||
.map(existingImage -> imageService.updateImage(image)
|
|
||||||
.map(ResponseEntity::ok)
|
|
||||||
.orElse(ResponseEntity.notFound().build()))
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ResponseEntity<Image> deleteImageById(@PathVariable Long id) {
|
|
||||||
return imageService.deleteImageById(id)
|
|
||||||
.map(image -> ResponseEntity.ok().body(image))
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package fr.gameovergne.api.controller.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.PlatformDTO;
|
|
||||||
import fr.gameovergne.api.mapper.app.PlatformMapper;
|
|
||||||
import fr.gameovergne.api.model.app.Platform;
|
|
||||||
import fr.gameovergne.api.service.app.PlatformService;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/app/platforms")
|
|
||||||
public class PlatformController {
|
|
||||||
|
|
||||||
private final PlatformService platformService;
|
|
||||||
private final PlatformMapper platformMapper;
|
|
||||||
|
|
||||||
public PlatformController(PlatformService platformService, PlatformMapper platformMapper) {
|
|
||||||
this.platformService = platformService;
|
|
||||||
this.platformMapper = platformMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<PlatformDTO> getAllPlatforms() {
|
|
||||||
return platformService.getAllPlatforms()
|
|
||||||
.stream()
|
|
||||||
.map(platformMapper::toDto)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ResponseEntity<Platform> getPlatformById(@PathVariable Long id) {
|
|
||||||
return platformService.getPlatformById(id)
|
|
||||||
.map(ResponseEntity::ok)
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public void savePlatform(@RequestBody PlatformDTO platformDTO) {
|
|
||||||
platformService.savePlatform(platformMapper.fromDto(platformDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ResponseEntity<Platform> updatePlatform(@PathVariable Long id, @RequestBody PlatformDTO platformDTO) {
|
|
||||||
Platform platform = platformMapper.fromDto(platformDTO);
|
|
||||||
platform.setId(id);
|
|
||||||
return platformService.getPlatformById(id)
|
|
||||||
.map(existingPlatform -> platformService.updatePlatform(platform)
|
|
||||||
.map(ResponseEntity::ok)
|
|
||||||
.orElse(ResponseEntity.notFound().build()))
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ResponseEntity<Platform> deletePlatformById(@PathVariable Long id) {
|
|
||||||
return platformService.deletePlatformById(id)
|
|
||||||
.map(platform -> ResponseEntity.ok().body(platform))
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package fr.gameovergne.api.controller.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.ProductDTO;
|
|
||||||
import fr.gameovergne.api.mapper.app.ProductMapper;
|
|
||||||
import fr.gameovergne.api.model.app.Product;
|
|
||||||
import fr.gameovergne.api.service.app.ProductService;
|
|
||||||
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/app/products")
|
|
||||||
public class ProductController {
|
|
||||||
|
|
||||||
private final ProductService productService;
|
|
||||||
private final ProductMapper productMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ProductController(ProductService productService, ProductMapper productMapper) {
|
|
||||||
this.productService = productService;
|
|
||||||
this.productMapper = productMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public List<ProductDTO> getAllProducts() {
|
|
||||||
return productService.getAllProducts()
|
|
||||||
.stream()
|
|
||||||
.map(productMapper::toDto)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ResponseEntity<ProductDTO> getProductById(@PathVariable Long id) {
|
|
||||||
return productService.getProductById(id)
|
|
||||||
.stream()
|
|
||||||
.map(productMapper::toDto)
|
|
||||||
.findFirst()
|
|
||||||
.map(ResponseEntity::ok)
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public void saveProduct(@RequestBody ProductDTO productDTO) {
|
|
||||||
productService.saveProduct(productMapper.fromDto(productDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ResponseEntity<Product> updateProduct(@PathVariable Long id, @RequestBody ProductDTO productDTO) {
|
|
||||||
Product product = productMapper.fromDto(productDTO);
|
|
||||||
product.setId(id);
|
|
||||||
return productService.getProductById(id)
|
|
||||||
.map(existingProduct -> productService.updateProduct(product)
|
|
||||||
.map(ResponseEntity::ok)
|
|
||||||
.orElse(ResponseEntity.notFound().build()))
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ResponseEntity<Product> deleteProductById(@PathVariable Long id) {
|
|
||||||
return productService.deleteProductById(id)
|
|
||||||
.map(product -> ResponseEntity.ok().body(product))
|
|
||||||
.orElse(ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package fr.gameovergne.api.controller.app;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/app/products_images")
|
|
||||||
public class ProductImageController {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package fr.gameovergne.api.dto.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class BrandDTO {
|
|
||||||
|
|
||||||
@JsonProperty("id")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@JsonProperty("name")
|
|
||||||
private String name;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package fr.gameovergne.api.dto.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class CategoryDTO {
|
|
||||||
|
|
||||||
@JsonProperty("id")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@JsonProperty("name")
|
|
||||||
private String name;
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package fr.gameovergne.api.dto.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ConditionDTO {
|
|
||||||
|
|
||||||
@JsonProperty("name")
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
@JsonProperty("displayName")
|
|
||||||
private final String displayName;
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package fr.gameovergne.api.dto.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class ImageDTO {
|
|
||||||
|
|
||||||
@JsonProperty("id")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@JsonProperty("name")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@JsonProperty("url")
|
|
||||||
private String url;
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package fr.gameovergne.api.dto.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class PlatformDTO {
|
|
||||||
|
|
||||||
@JsonProperty("id")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@JsonProperty("name")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@JsonProperty("brand")
|
|
||||||
private BrandDTO brandDTO;
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package fr.gameovergne.api.dto.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class ProductDTO {
|
|
||||||
|
|
||||||
@JsonProperty("id")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@JsonProperty("title")
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
@JsonProperty("description")
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
@JsonProperty("price")
|
|
||||||
private double price;
|
|
||||||
|
|
||||||
@JsonProperty("quantity")
|
|
||||||
private int quantity;
|
|
||||||
|
|
||||||
@JsonProperty("complete")
|
|
||||||
private boolean complete = false;
|
|
||||||
|
|
||||||
@JsonProperty("manualIncluded")
|
|
||||||
private boolean manualIncluded = false;
|
|
||||||
|
|
||||||
@JsonProperty("category")
|
|
||||||
private CategoryDTO categoryDTO;
|
|
||||||
|
|
||||||
@JsonProperty("platform")
|
|
||||||
private PlatformDTO platformDTO;
|
|
||||||
|
|
||||||
@JsonProperty("condition")
|
|
||||||
private ConditionDTO conditionDTO;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package fr.gameovergne.api.mapper.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.BrandDTO;
|
|
||||||
import fr.gameovergne.api.model.app.Brand;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class BrandMapper {
|
|
||||||
|
|
||||||
public Brand fromDto(BrandDTO brandDTO) {
|
|
||||||
if (brandDTO == null) return null;
|
|
||||||
Brand brand = new Brand();
|
|
||||||
brand.setId(brandDTO.getId());
|
|
||||||
brand.setName(brandDTO.getName());
|
|
||||||
return brand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BrandDTO toDto(Brand brand) {
|
|
||||||
if (brand == null) return null;
|
|
||||||
BrandDTO brandDTO = new BrandDTO();
|
|
||||||
brandDTO.setId(brand.getId());
|
|
||||||
brandDTO.setName(brand.getName());
|
|
||||||
return brandDTO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package fr.gameovergne.api.mapper.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.CategoryDTO;
|
|
||||||
import fr.gameovergne.api.model.app.Category;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class CategoryMapper {
|
|
||||||
|
|
||||||
public Category fromDto(CategoryDTO categoryDTO) {
|
|
||||||
if (categoryDTO == null) return null;
|
|
||||||
Category category = new Category();
|
|
||||||
category.setId(categoryDTO.getId());
|
|
||||||
category.setName(categoryDTO.getName());
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CategoryDTO toDto(Category category) {
|
|
||||||
if (category == null) return null;
|
|
||||||
CategoryDTO categoryDTO = new CategoryDTO();
|
|
||||||
categoryDTO.setId(category.getId());
|
|
||||||
categoryDTO.setName(category.getName());
|
|
||||||
return categoryDTO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package fr.gameovergne.api.mapper.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.ImageDTO;
|
|
||||||
import fr.gameovergne.api.model.app.Image;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class ImageMapper {
|
|
||||||
|
|
||||||
public Image fromDto(ImageDTO imageDTO) {
|
|
||||||
if (imageDTO == null) return null;
|
|
||||||
Image image = new Image();
|
|
||||||
image.setId(imageDTO.getId());
|
|
||||||
image.setName(imageDTO.getName());
|
|
||||||
image.setUrl(imageDTO.getUrl());
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImageDTO toDto(Image image) {
|
|
||||||
if (image == null) return null;
|
|
||||||
ImageDTO imageDTO = new ImageDTO();
|
|
||||||
imageDTO.setId(image.getId());
|
|
||||||
imageDTO.setName(image.getName());
|
|
||||||
imageDTO.setUrl(image.getUrl());
|
|
||||||
return imageDTO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package fr.gameovergne.api.mapper.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.BrandDTO;
|
|
||||||
import fr.gameovergne.api.dto.app.PlatformDTO;
|
|
||||||
import fr.gameovergne.api.model.app.Platform;
|
|
||||||
import fr.gameovergne.api.service.app.BrandService;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class PlatformMapper {
|
|
||||||
|
|
||||||
private final BrandService brandService;
|
|
||||||
|
|
||||||
public PlatformMapper(BrandService brandService) {
|
|
||||||
this.brandService = brandService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Platform fromDto(PlatformDTO platformDTO) {
|
|
||||||
if (platformDTO == null) return null;
|
|
||||||
Platform platform = new Platform();
|
|
||||||
platform.setId(platformDTO.getId());
|
|
||||||
platform.setName(platformDTO.getName());
|
|
||||||
|
|
||||||
if (platformDTO.getBrandDTO() != null && platformDTO.getBrandDTO().getName() != null) {
|
|
||||||
platform.setBrand(this.brandService.getBrandByName(platformDTO.getBrandDTO().getName()).orElse(null));
|
|
||||||
} else {
|
|
||||||
platform.setBrand(null);
|
|
||||||
}
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlatformDTO toDto(Platform platform) {
|
|
||||||
if (platform == null) return null;
|
|
||||||
PlatformDTO platformDTO = new PlatformDTO();
|
|
||||||
platformDTO.setId(platform.getId());
|
|
||||||
platformDTO.setName(platform.getName());
|
|
||||||
if (platform.getBrand() != null) {
|
|
||||||
platformDTO.setBrandDTO(new BrandDTO(platform.getBrand().getId(), platform.getBrand().getName()));
|
|
||||||
} else {
|
|
||||||
platformDTO.setBrandDTO(null);
|
|
||||||
}
|
|
||||||
return platformDTO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
package fr.gameovergne.api.mapper.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.dto.app.*;
|
|
||||||
import fr.gameovergne.api.model.app.Brand;
|
|
||||||
import fr.gameovergne.api.model.app.Condition;
|
|
||||||
import fr.gameovergne.api.model.app.Platform;
|
|
||||||
import fr.gameovergne.api.model.app.Product;
|
|
||||||
import fr.gameovergne.api.service.app.BrandService;
|
|
||||||
import fr.gameovergne.api.service.app.CategoryService;
|
|
||||||
import fr.gameovergne.api.service.app.PlatformService;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class ProductMapper {
|
|
||||||
|
|
||||||
private final CategoryService categoryService;
|
|
||||||
private final BrandService brandService;
|
|
||||||
private final PlatformService platformService;
|
|
||||||
|
|
||||||
public ProductMapper(CategoryService categoryService, BrandService brandService, PlatformService platformService) {
|
|
||||||
this.categoryService = categoryService;
|
|
||||||
this.brandService = brandService;
|
|
||||||
this.platformService = platformService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Product fromDto(ProductDTO productDTO) {
|
|
||||||
if (productDTO == null) return null;
|
|
||||||
Product product = new Product();
|
|
||||||
product.setId(productDTO.getId());
|
|
||||||
product.setTitle(productDTO.getTitle());
|
|
||||||
product.setDescription(productDTO.getDescription());
|
|
||||||
product.setPrice(productDTO.getPrice());
|
|
||||||
product.setQuantity(productDTO.getQuantity());
|
|
||||||
product.setComplete(productDTO.isComplete());
|
|
||||||
product.setManualIncluded(productDTO.isManualIncluded());
|
|
||||||
|
|
||||||
if (productDTO.getCategoryDTO() != null && productDTO.getCategoryDTO().getName() != null) {
|
|
||||||
product.setCategory(this.categoryService.getCategoryByName(productDTO.getCategoryDTO().getName()).orElse(null));
|
|
||||||
} else {
|
|
||||||
product.setCategory(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (productDTO.getPlatformDTO() != null && productDTO.getPlatformDTO().getName() != null) {
|
|
||||||
String platformName = productDTO.getPlatformDTO().getName();
|
|
||||||
Platform platform = this.platformService.getPlatformByName(platformName)
|
|
||||||
.orElseGet(() -> {
|
|
||||||
Platform p = new Platform();
|
|
||||||
p.setName(platformName);
|
|
||||||
return p;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (productDTO.getPlatformDTO().getBrandDTO() != null && productDTO.getPlatformDTO().getBrandDTO().getName() != null) {
|
|
||||||
String brandName = productDTO.getPlatformDTO().getBrandDTO().getName();
|
|
||||||
Brand brand = this.brandService.getBrandByName(brandName)
|
|
||||||
.orElseGet(() -> {
|
|
||||||
Brand b = new Brand();
|
|
||||||
b.setName(brandName);
|
|
||||||
return b;
|
|
||||||
});
|
|
||||||
platform.setBrand(brand);
|
|
||||||
}
|
|
||||||
|
|
||||||
product.setPlatform(platform);
|
|
||||||
} else {
|
|
||||||
product.setPlatform(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (productDTO.getConditionDTO() != null && productDTO.getConditionDTO().getName() != null) {
|
|
||||||
try {
|
|
||||||
product.setCondition(Condition.valueOf(productDTO.getConditionDTO().getName()));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
product.setCondition(null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
product.setCondition(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return product;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductDTO toDto(Product product) {
|
|
||||||
if (product == null) return null;
|
|
||||||
ProductDTO productDTO = new ProductDTO();
|
|
||||||
productDTO.setId(product.getId());
|
|
||||||
productDTO.setTitle(product.getTitle());
|
|
||||||
productDTO.setDescription(product.getDescription());
|
|
||||||
productDTO.setPrice(product.getPrice());
|
|
||||||
productDTO.setQuantity(product.getQuantity());
|
|
||||||
productDTO.setComplete(product.isComplete());
|
|
||||||
productDTO.setManualIncluded(product.isManualIncluded());
|
|
||||||
|
|
||||||
if (product.getCategory() != null) {
|
|
||||||
productDTO.setCategoryDTO(new CategoryDTO(product.getCategory().getId(), product.getCategory().getName()));
|
|
||||||
} else {
|
|
||||||
productDTO.setCategoryDTO(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (product.getPlatform() != null) {
|
|
||||||
Platform platform = product.getPlatform();
|
|
||||||
PlatformDTO platformDTO = new PlatformDTO();
|
|
||||||
platformDTO.setId(platform.getId());
|
|
||||||
platformDTO.setName(platform.getName());
|
|
||||||
|
|
||||||
if (platform.getBrand() != null) {
|
|
||||||
platformDTO.setBrandDTO(new BrandDTO(platform.getBrand().getId(), platform.getBrand().getName()));
|
|
||||||
} else {
|
|
||||||
platformDTO.setBrandDTO(null);
|
|
||||||
}
|
|
||||||
productDTO.setPlatformDTO(platformDTO);
|
|
||||||
} else {
|
|
||||||
productDTO.setPlatformDTO(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (product.getCondition() != null) {
|
|
||||||
productDTO.setConditionDTO(new ConditionDTO(product.getCondition().name(), product.getCondition().getDisplayName()));
|
|
||||||
} else {
|
|
||||||
productDTO.setConditionDTO(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return productDTO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package fr.gameovergne.api.model.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
|
||||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
|
||||||
@Table(name = "brands")
|
|
||||||
public class Brand {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Column(name = "brand_name", length = 30, unique = true)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "brand", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
||||||
private List<Platform> platforms;
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package fr.gameovergne.api.model.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
|
||||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
|
||||||
@Table(name = "categories")
|
|
||||||
public class Category {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Column(name = "category_name", length = 30, unique = true, nullable = false)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
||||||
private List<Product> products;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package fr.gameovergne.api.model.app;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public enum Condition {
|
|
||||||
NEW("Neuf"),
|
|
||||||
VERY_GOOD("Très bon état"),
|
|
||||||
GOOD("Bon état"),
|
|
||||||
POOR("Mauvais état"),
|
|
||||||
VERY_POOR("Très mauvais état");
|
|
||||||
|
|
||||||
private final String displayName;
|
|
||||||
|
|
||||||
Condition(String displayName) {
|
|
||||||
this.displayName = displayName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package fr.gameovergne.api.model.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
|
||||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
|
||||||
import fr.gameovergne.api.model.user.User;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
|
||||||
@Table(name = "images")
|
|
||||||
public class Image {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(length = 120, unique = true, nullable = false)
|
|
||||||
@NotBlank
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Column(length = 255, unique = true, nullable = false)
|
|
||||||
@NotBlank
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
|
|
||||||
@JoinTable(
|
|
||||||
name = "users_images",
|
|
||||||
joinColumns = @JoinColumn(name = "image_id"),
|
|
||||||
inverseJoinColumns = @JoinColumn(name = "user_id")
|
|
||||||
)
|
|
||||||
private List<User> users;
|
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
|
|
||||||
@JoinTable(
|
|
||||||
name = "products_images",
|
|
||||||
joinColumns = @JoinColumn(name = "image_id"),
|
|
||||||
inverseJoinColumns = @JoinColumn(name = "product_id")
|
|
||||||
)
|
|
||||||
private List<Product> products;
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package fr.gameovergne.api.model.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
|
||||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
|
||||||
@Table(name = "platforms")
|
|
||||||
public class Platform {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Column(name = "platform_name", length = 30, unique = true, nullable = false)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "brand_id")
|
|
||||||
private Brand brand;
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "platform", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
||||||
private List<Product> products;
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package fr.gameovergne.api.model.app;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
|
||||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
|
||||||
@Table(name = "products")
|
|
||||||
public class Product {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Column(name = "product_title", length = 120, unique = true, nullable = false)
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
@Column(name = "product_description", length = 500)
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(name = "product_price")
|
|
||||||
private double price;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(name = "product_quantity")
|
|
||||||
private int quantity;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(name = "product_complete")
|
|
||||||
private boolean complete = false;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(name = "product_manual")
|
|
||||||
private boolean manualIncluded = false; // Notice
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "category_id")
|
|
||||||
private Category category;
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "platform_id")
|
|
||||||
private Platform platform;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
@Column(name = "product_condition")
|
|
||||||
private Condition condition;
|
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
|
|
||||||
@JoinTable(
|
|
||||||
name = "products_images",
|
|
||||||
joinColumns = @JoinColumn(name = "image_id"),
|
|
||||||
inverseJoinColumns = @JoinColumn(name = "product_id")
|
|
||||||
)
|
|
||||||
private List<Image> images;
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package fr.gameovergne.api.repository.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Brand;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface BrandRepository extends JpaRepository<Brand, Long> {
|
|
||||||
Optional<Brand> findByName(String name);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package fr.gameovergne.api.repository.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Category;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface CategoryRepository extends JpaRepository<Category, Long> {
|
|
||||||
Optional<Category> findByName(String name);
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package fr.gameovergne.api.repository.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Image;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface ImageRepository extends JpaRepository<Image, Long> {
|
|
||||||
Optional<Image> findByName(String name);
|
|
||||||
Optional<Image> findByUrl(String url);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package fr.gameovergne.api.repository.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Platform;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface PlatformRepository extends JpaRepository<Platform, Long> {
|
|
||||||
Optional<Platform> findByName(String name);
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package fr.gameovergne.api.repository.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.*;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface ProductRepository extends JpaRepository<Product, Long> {
|
|
||||||
Optional<Product> findByTitle(String title);
|
|
||||||
Optional<Product> findByCategory(Category category);
|
|
||||||
Optional<Product> findByPlatform(Platform platform);
|
|
||||||
Optional<Product> findByCondition(Condition condition);
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package fr.gameovergne.api.service.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Brand;
|
|
||||||
import fr.gameovergne.api.model.app.Platform;
|
|
||||||
import fr.gameovergne.api.repository.app.BrandRepository;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class BrandService {
|
|
||||||
|
|
||||||
private final BrandRepository brandRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public BrandService(BrandRepository brandRepository) {
|
|
||||||
this.brandRepository = brandRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void saveBrand(Brand brand) {
|
|
||||||
if (brand.getId() == null) {
|
|
||||||
brandRepository.save(brand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Brand> getAllBrands() {
|
|
||||||
return brandRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Brand> getBrandById(Long id) {
|
|
||||||
return brandRepository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Brand> getBrandByName(String name) {
|
|
||||||
return brandRepository.findByName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Brand> updateBrand(Brand brand) {
|
|
||||||
return brandRepository.findById(brand.getId()).map(existingBrand -> {
|
|
||||||
existingBrand.setName(brand.getName());
|
|
||||||
|
|
||||||
List<Platform> newPlatforms = brand.getPlatforms();
|
|
||||||
if (newPlatforms != null) {
|
|
||||||
if (existingBrand.getPlatforms() == null) {
|
|
||||||
existingBrand.setPlatforms(new ArrayList<>());
|
|
||||||
} else {
|
|
||||||
existingBrand.getPlatforms().clear();
|
|
||||||
}
|
|
||||||
for (Platform p : newPlatforms) {
|
|
||||||
p.setBrand(existingBrand);
|
|
||||||
existingBrand.getPlatforms().add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return brandRepository.save(existingBrand);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Brand> deleteBrandById(Long id) {
|
|
||||||
Optional<Brand> brand = brandRepository.findById(id);
|
|
||||||
brand.ifPresent(brandRepository::delete);
|
|
||||||
return brand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package fr.gameovergne.api.service.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Category;
|
|
||||||
import fr.gameovergne.api.repository.app.CategoryRepository;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CategoryService {
|
|
||||||
|
|
||||||
private final CategoryRepository categoryRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public CategoryService(CategoryRepository categoryRepository) {
|
|
||||||
this.categoryRepository = categoryRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void saveCategory(Category category) {
|
|
||||||
if (category.getId() == null) {
|
|
||||||
categoryRepository.save(category);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Category> getAllCategories() {
|
|
||||||
return categoryRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Category> getCategoryById(Long id) {
|
|
||||||
return categoryRepository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Category> getCategoryByName(String name) {
|
|
||||||
return categoryRepository.findByName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Category> updateCategory(Category category) {
|
|
||||||
return categoryRepository.findById(category.getId()).map(existingCategory -> {
|
|
||||||
existingCategory.setName(category.getName());
|
|
||||||
return categoryRepository.save(existingCategory);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Category> deleteCategoryById(Long id) {
|
|
||||||
Optional<Category> category = categoryRepository.findById(id);
|
|
||||||
category.ifPresent(categoryRepository::delete);
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package fr.gameovergne.api.service.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Image;
|
|
||||||
import fr.gameovergne.api.repository.app.ImageRepository;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ImageService {
|
|
||||||
|
|
||||||
private final ImageRepository imageRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ImageService(ImageRepository imageRepository) {
|
|
||||||
this.imageRepository = imageRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void saveImage(Image image) {
|
|
||||||
if (image.getId() == null) {
|
|
||||||
imageRepository.save(image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Image> getAllImages() {
|
|
||||||
return imageRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Image> getImageById(Long id) {
|
|
||||||
return imageRepository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Image> getImageByName(String name) {
|
|
||||||
return imageRepository.findByName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Image> getImageByUrl(String url) {
|
|
||||||
return imageRepository.findByUrl(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Image> updateImage(Image image) {
|
|
||||||
return imageRepository.findById(image.getId()).map(existingImage -> {
|
|
||||||
existingImage.setName(image.getName());
|
|
||||||
existingImage.setUrl(image.getUrl());
|
|
||||||
return imageRepository.save(existingImage);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Image> deleteImageById(Long id) {
|
|
||||||
Optional<Image> image = imageRepository.findById(id);
|
|
||||||
image.ifPresent(imageRepository::delete);
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package fr.gameovergne.api.service.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Platform;
|
|
||||||
import fr.gameovergne.api.model.app.Product;
|
|
||||||
import fr.gameovergne.api.repository.app.PlatformRepository;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class PlatformService {
|
|
||||||
|
|
||||||
private final PlatformRepository platformRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public PlatformService(PlatformRepository platformRepository) {
|
|
||||||
this.platformRepository = platformRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void savePlatform(Platform platform) {
|
|
||||||
if (platform.getId() == null) {
|
|
||||||
platformRepository.save(platform);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Platform> getAllPlatforms() {
|
|
||||||
return platformRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Platform> getPlatformById(Long id) {
|
|
||||||
return platformRepository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Platform> getPlatformByName(String name) {
|
|
||||||
return platformRepository.findByName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Platform> updatePlatform(Platform platform) {
|
|
||||||
return platformRepository.findById(platform.getId()).map(existingPlatform -> {
|
|
||||||
existingPlatform.setName(platform.getName());
|
|
||||||
existingPlatform.setBrand(platform.getBrand());
|
|
||||||
List<Product> newProducts = platform.getProducts();
|
|
||||||
if (newProducts != null) {
|
|
||||||
if (existingPlatform.getProducts() == null) {
|
|
||||||
existingPlatform.setProducts(new ArrayList<>());
|
|
||||||
} else {
|
|
||||||
existingPlatform.getProducts().clear();
|
|
||||||
}
|
|
||||||
for (Product p : newProducts) {
|
|
||||||
p.setPlatform(existingPlatform);
|
|
||||||
existingPlatform.getProducts().add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return platformRepository.save(existingPlatform);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Platform> deletePlatformById(Long id) {
|
|
||||||
Optional<Platform> platform = platformRepository.findById(id);
|
|
||||||
platform.ifPresent(platformRepository::delete);
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package fr.gameovergne.api.service.app;
|
|
||||||
|
|
||||||
import fr.gameovergne.api.model.app.Product;
|
|
||||||
import fr.gameovergne.api.model.app.Platform;
|
|
||||||
import fr.gameovergne.api.repository.app.ProductRepository;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ProductService {
|
|
||||||
|
|
||||||
private final ProductRepository productRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ProductService(ProductRepository productRepository) {
|
|
||||||
this.productRepository = productRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void saveProduct(Product product) {
|
|
||||||
if (product.getId() == null) {
|
|
||||||
productRepository.save(product);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Product> getAllProducts() {
|
|
||||||
return productRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Product> getProductById(Long id) {
|
|
||||||
return productRepository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Product> getProductByName(String name) {
|
|
||||||
return productRepository.findByTitle(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Product> updateProduct(Product product) {
|
|
||||||
return productRepository.findById(product.getId()).map(existingProduct -> {
|
|
||||||
existingProduct.setTitle(product.getTitle());
|
|
||||||
existingProduct.setDescription(product.getDescription());
|
|
||||||
existingProduct.setPrice(product.getPrice());
|
|
||||||
existingProduct.setQuantity(product.getQuantity());
|
|
||||||
existingProduct.setComplete(product.isComplete());
|
|
||||||
existingProduct.setManualIncluded(product.isManualIncluded());
|
|
||||||
existingProduct.setCategory(product.getCategory());
|
|
||||||
existingProduct.setPlatform(product.getPlatform());
|
|
||||||
existingProduct.setCondition(product.getCondition());
|
|
||||||
return productRepository.save(existingProduct);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Optional<Product> deleteProductById(Long id) {
|
|
||||||
Optional<Product> product = productRepository.findById(id);
|
|
||||||
product.ifPresent(productRepository::delete);
|
|
||||||
return product;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user