Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 72 product in organization #103

Merged
merged 33 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
832f625
[feature-70-BE-Expose-Organization-destruction] - changes after review
berki0 Mar 24, 2024
f90569e
[feature-72-BE-products-in-organization] CRUD
berki0 Mar 25, 2024
3281bb8
[feature-72-BE-products-in-organization] add deleting method
berki0 Mar 25, 2024
b2af645
[feature-72-BE-products-in-organization] add deleting method
berki0 Mar 25, 2024
f6ff5c1
update product, entity fetcher
ignatIgnatov Mar 26, 2024
4f6732e
[feature-72-BE-products-in-organization] add tests
berki0 Mar 26, 2024
f42a518
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
b108aae
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
76b0db8
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
3f9fc72
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
283f2bb
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
c7df993
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
9d1a46e
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
5842c84
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
34484b6
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
89c3c5a
[feature-72-BE-products-in-organization] add tests
berki0 Mar 27, 2024
851ccf0
[feature-72-BE-products-in-organization] add tests
berki0 Mar 28, 2024
2577835
[feature-72-BE-products-in-organization] add tests
berki0 Mar 28, 2024
18f7185
[feature-72-BE-products-in-organization] add tests
berki0 Mar 28, 2024
6025974
[feature-72-BE-products-in-organization] add tests
berki0 Mar 28, 2024
a434678
working create and update integration tests
ignatIgnatov Mar 29, 2024
d47aede
refactoring
ignatIgnatov Mar 29, 2024
935639a
working delete integration test
ignatIgnatov Mar 29, 2024
0d9e089
[feature-72-BE-products-in-organization] add tests
berki0 Apr 1, 2024
b8d8606
[feature-72-BE-products-in-organization] changes after review
berki0 Apr 2, 2024
fb0fb2d
[feature-72-BE-products-in-organization] changes after review
berki0 Apr 2, 2024
9e9bbe6
[feature-72-BE-products-in-organization] changes after review
berki0 Apr 2, 2024
4346fad
[feature-72-BE-products-in-organization] changes after review
berki0 Apr 2, 2024
2063c21
[feature-72-BE-products-in-organization] changes after review
berki0 Apr 3, 2024
a43b3d9
fix delete method
berki0 Apr 3, 2024
ecc5794
fix delete method
berki0 Apr 3, 2024
650aacd
fix delete method
berki0 Apr 3, 2024
6cf44ed
[feature-72-BE-products-in-organization] changes after review
berki0 Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package jewellery.inventory.controller;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import java.util.UUID;
import jewellery.inventory.dto.request.ProductRequestDto;
import jewellery.inventory.dto.response.ProductsInOrganizationResponseDto;
import jewellery.inventory.service.ProductInOrganizationService;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/organizations")
@AllArgsConstructor
public class ProductInOrganizationController {
private final ProductInOrganizationService productInOrganizationService;

@Operation(summary = "Get all products in organization")
@ResponseStatus(HttpStatus.OK)
@GetMapping("/{organizationId}/products")
public ProductsInOrganizationResponseDto getAllProductsInOrganization(
@PathVariable UUID organizationId) {
return productInOrganizationService.getProductsInOrganization(organizationId);
}

@Operation(summary = "Create a new product in organization")
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/products")
public ProductsInOrganizationResponseDto createProductInOrganization(
@RequestBody @Valid ProductRequestDto productRequestDto) {
return productInOrganizationService.createProductInOrganization(productRequestDto);
}

@Operation(summary = "Delete a new product in organization")
@ResponseStatus(HttpStatus.NO_CONTENT)
@DeleteMapping("/products/{productId}")
public void deleteProductInOrganization(
@PathVariable("productId") UUID productId) {
productInOrganizationService.deleteProductInOrganization(productId);
}

@Operation(summary = "Update a product in organization")
@ResponseStatus(HttpStatus.OK)
@PutMapping("/products/{productId}")
public ProductsInOrganizationResponseDto updateProduct(
@PathVariable("productId") UUID productId,
@Valid @RequestBody ProductRequestDto productRequestDto) {
return productInOrganizationService.updateProduct(productId, productRequestDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package jewellery.inventory.dto.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;

@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class ProductsInOrganizationResponseDto {
private OrganizationResponseDto organization;
private List<ProductResponseDto> products;
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public ResponseEntity<Object> handleBadDataExceptions(RuntimeException ex) {
UserIsNotPartOfOrganizationException.class,
UserIsPartOfOrganizationException.class,
OrphanResourcesInOrganizationException.class,
OrphanProductsInOrganizationException.class
OrphanProductsInOrganizationException.class,
OrganizationNotOwnerException.class,
ProductIsNotPartOfOrganizationException.class
})
public ResponseEntity<Object> handleEntityConstraintConflict(RuntimeException ex) {
return createErrorResponse(HttpStatus.CONFLICT, ex.getMessage(), ex);
Expand All @@ -111,7 +113,7 @@ private ResponseEntity<Object> createErrorResponse(
String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT_PATTERN));
body.put(TIMESTAMP_KEY, date);
body.put(ERROR_KEY, error);
logger.error("Error occurred: " + ex.getMessage(), ex);
logger.error("Error occurred: {} " , ex.getMessage(), ex);
return new ResponseEntity<>(body, status);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package jewellery.inventory.exception.organization;


import java.util.UUID;

public class OrganizationNotOwnerException extends RuntimeException {
public OrganizationNotOwnerException(UUID organizationId, UUID productId) {
super("Organization with id " + organizationId + " is not the owner of a product with id " + productId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package jewellery.inventory.exception.organization;

import java.util.UUID;

public class ProductIsNotPartOfOrganizationException extends RuntimeException {
public ProductIsNotPartOfOrganizationException(UUID productId) {
super("The Product with id " + productId + "is not owned of Organization");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package jewellery.inventory.mapper;

import jewellery.inventory.dto.response.ProductResponseDto;
import jewellery.inventory.dto.response.ProductsInOrganizationResponseDto;
import jewellery.inventory.model.Organization;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class ProductInOrganizationMapper {
private final OrganizationMapper organizationMapper;

public ProductsInOrganizationResponseDto mapToProductsInOrganizationResponseDto(
Organization organization, List<ProductResponseDto> products) {
ProductsInOrganizationResponseDto productsInOrganizationResponseDto =
new ProductsInOrganizationResponseDto();

productsInOrganizationResponseDto.setOrganization(organizationMapper.toResponse(organization));
productsInOrganizationResponseDto.setProducts(products);
return productsInOrganizationResponseDto;
}
}
5 changes: 4 additions & 1 deletion src/main/java/jewellery/inventory/model/EventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ public enum EventType {
ORGANIZATION_USER_DELETE,
ORGANIZATION_USER_UPDATE,
ORGANIZATION_ADD_RESOURCE_QUANTITY,
ORGANIZATION_REMOVE_RESOURCE_QUANTITY
ORGANIZATION_REMOVE_RESOURCE_QUANTITY,
ORGANIZATION_PRODUCT_CREATE,
ORGANIZATION_PRODUCT_UPDATE,
ORGANIZATION_PRODUCT_DISASSEMBLY
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obsolete change?

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package jewellery.inventory.model.resource;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;

import java.math.BigDecimal;
import java.util.UUID;
import jewellery.inventory.model.Product;
Expand Down
Loading
Loading