Skip to content

Commit

Permalink
E-commerce
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecpedro committed Sep 15, 2022
1 parent 8a4d96b commit 59e4733
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@ public CategoryDTO getById(@PathVariable int id) {
public CategoryDTO getByName(@RequestParam(value = "name") String name) {
return categoryService.getByName(name);
}
@PutMapping
public CategoryDTO update(@RequestBody CategoryDTO categoryDTO) {
return categoryService.update(categoryDTO);
}

@DeleteMapping("/{id}")
public String delete(@RequestParam(value = "id") int id) {
return categoryService.delete(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public List<ProductDTO> getAll() {
}

@PutMapping("/{id}")
public ProductDTO update(@RequestBody ProductDTO productDTO, @PathVariable int id) {
return productService.update(productDTO, id);
public ProductDTO update(@RequestBody ProductDTO productDTO) {
return productService.update(productDTO);
}

@DeleteMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public interface ICommerceService<T> {
T getById(int id);
List<T> getAll();
String delete(int id);
T update(T t, int id);
T update(T t);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public List<ProductDTO> getProductsByCategory(int id) {
CategoryEntity category = categoryRepository.findById(id).get();
List<ProductEntity> productEntities = category.getProductEntities();


return null;
}

Expand All @@ -51,12 +50,15 @@ public List<CategoryDTO> getAll() {

@Override
public String delete(int id) {
return null;
categoryRepository.deleteById(id);
return "Successfully deleted";
}

@Override
public CategoryDTO update(CategoryDTO categoryDTO, int id) {
return null;
public CategoryDTO update(CategoryDTO categoryDTO) {
CategoryEntity categoryEntity = new CategoryEntity(categoryDTO);
categoryRepository.saveAndFlush(categoryEntity);
return categoryDTO;
}

public boolean ifCategoryExists(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String delete(int id) {
}

@Override
public ProductDTO update(ProductDTO productDTO, int id) {
public ProductDTO update(ProductDTO productDTO) {
// ProductEntity productEntity = mapperDTOToEntity(productDTO);
// productEntity.setCategory(categoryService.getByName(productDTO.getCategory()));
// productEntity.setId(id);
Expand Down

0 comments on commit 59e4733

Please sign in to comment.