Skip to content

Commit

Permalink
Task 24 : Add Java Doc information underneath product package
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapter1990 committed Jul 9, 2024
1 parent 3de5845 commit dec2519
Show file tree
Hide file tree
Showing 26 changed files with 298 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Main class named {@link RolepermissionexampleApplication} to start the Role Permission example application.
*/
@SpringBootApplication
public class RolepermissionexampleApplication {

/**
* Main method to start the Spring Boot application.
*
* @param args the command line arguments
*/
public static void main(String[] args) {
SpringApplication.run(RolepermissionexampleApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
* Controller class named {@link ProductController} for handling product-related CRUD operations.
* Exposes endpoints under "/api/v1/products".
*/
@RestController
@RequestMapping("/api/v1/products")
@RequiredArgsConstructor
Expand All @@ -37,6 +41,12 @@ public class ProductController {
private final CustomPageToCustomPagingResponseMapper customPageToCustomPagingResponseMapper =
CustomPageToCustomPagingResponseMapper.initialize();

/**
* Creates a new product.
*
* @param productCreateRequest the request body containing product creation details
* @return a CustomResponse with the ID of the created product upon successful creation
*/
@PostMapping
@PreAuthorize("hasAnyAuthority('admin:create')")
public CustomResponse<String> createProduct(@RequestBody @Valid final ProductCreateRequest productCreateRequest) {
Expand All @@ -47,6 +57,12 @@ public CustomResponse<String> createProduct(@RequestBody @Valid final ProductCre
return CustomResponse.successOf(createdProduct.getId());
}

/**
* Retrieves a product by its ID.
*
* @param productId the ID of the product to retrieve
* @return a CustomResponse containing the product details
*/
@GetMapping("/{productId}")
@PreAuthorize("hasAnyAuthority('admin:get', 'user:get')")
public CustomResponse<ProductResponse> getProductById(@PathVariable @UUID final String productId) {
Expand All @@ -59,6 +75,12 @@ public CustomResponse<ProductResponse> getProductById(@PathVariable @UUID final

}

/**
* Retrieves a list of products based on pagination criteria.
*
* @param productPagingRequest the request body containing pagination parameters
* @return a CustomResponse with paginated product details
*/
@GetMapping
@PreAuthorize("hasAnyAuthority('admin:get', 'user:get')")
public CustomResponse<CustomPagingResponse<ProductResponse>> getProducts(
Expand All @@ -73,6 +95,13 @@ public CustomResponse<CustomPagingResponse<ProductResponse>> getProducts(

}

/**
* Updates an existing product by its ID.
*
* @param productUpdateRequest the request body containing updated product details
* @param productId the ID of the product to update
* @return a CustomResponse with updated product details
*/
@PutMapping("/{productId}")
@PreAuthorize("hasAnyAuthority('admin:update')")
public CustomResponse<ProductResponse> updatedProductById(
Expand All @@ -86,6 +115,12 @@ public CustomResponse<ProductResponse> updatedProductById(
return CustomResponse.successOf(productResponse);
}

/**
* Deletes a product by its ID.
*
* @param productId the ID of the product to delete
* @return a CustomResponse indicating the success of the deletion operation
*/
@DeleteMapping("/{productId}")
@PreAuthorize("hasAnyAuthority('admin:delete')")
public CustomResponse<Void> deleteProductById(@PathVariable @UUID final String productId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.io.Serial;

/**
* Exception class named {@link ProductAlreadyExistException} thrown when attempting to create a product that already exists.
*/
public class ProductAlreadyExistException extends RuntimeException{

@Serial
Expand All @@ -11,10 +14,18 @@ public class ProductAlreadyExistException extends RuntimeException{
Product already exist!
""";

/**
* Constructs a new ProductAlreadyExistException with a default message.
*/
public ProductAlreadyExistException() {
super(DEFAULT_MESSAGE);
}

/**
* Constructs a new ProductAlreadyExistException with a custom message appended to the default message.
*
* @param message the custom message indicating details about the exception
*/
public ProductAlreadyExistException(final String message) {
super(DEFAULT_MESSAGE + " " + message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.io.Serial;

/**
* Exception class named {@link ProductNotFoundException} thrown when a requested product cannot be found.
*/
public class ProductNotFoundException extends RuntimeException {

@Serial
Expand All @@ -11,10 +14,18 @@ public class ProductNotFoundException extends RuntimeException {
Product not found!
""";

/**
* Constructs a new ProductNotFoundException with a default message.
*/
public ProductNotFoundException() {
super(DEFAULT_MESSAGE);
}

/**
* Constructs a new ProductNotFoundException with a custom message appended to the default message.
*
* @param message the custom message indicating details about the exception
*/
public ProductNotFoundException(final String message) {
super(DEFAULT_MESSAGE + " " + message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import java.math.BigDecimal;

/**
* Represents a domain model for a product as {@link Product}.
*/
@Getter
@Setter
@SuperBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import java.math.BigDecimal;


/**
* Represents a request object for creating a new product as {@link ProductCreateRequest}.
*/
@Getter
@Setter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import lombok.*;
import lombok.experimental.SuperBuilder;

/**
* Represents a paging request object for retrieving products as {@link ProductPagingRequest}.
*/
@Getter
@Setter
@SuperBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.math.BigDecimal;

/**
* Represents a request object for updating an existing product as {@link ProductUpdateRequest}.
*/
@Getter
@Setter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import java.math.BigDecimal;

/**
* Represents a response object containing product details as {@link ProductResponse}.
*/
@Getter
@Setter
@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import java.math.BigDecimal;

/**
* Represents a persistent entity for a product as {@link ProductEntity}.
*/
@Getter
@Setter
@SuperBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
import java.util.List;
import java.util.stream.Collectors;

/**
* Mapper interface named {@link CustomPageToCustomPagingResponseMapper} for converting {@link CustomPage<Product>} to {@link CustomPagingResponse<ProductResponse>}.
*/
@Mapper
public interface CustomPageToCustomPagingResponseMapper {

ProductToProductResponseMapper productToProductResponseMapper = Mappers.getMapper(ProductToProductResponseMapper.class);

/**
* Converts a CustomPage<Product> object to CustomPagingResponse<ProductResponse>.
*
* @param productPage The CustomPage<Product> object to convert.
* @return CustomPagingResponse<ProductResponse> object containing mapped data.
*/
default CustomPagingResponse<ProductResponse> toPagingResponse(CustomPage<Product> productPage) {

if (productPage == null) {
Expand All @@ -31,6 +40,12 @@ default CustomPagingResponse<ProductResponse> toPagingResponse(CustomPage<Produc

}

/**
* Converts a list of Product objects to a list of ProductResponse objects.
*
* @param products The list of Product objects to convert.
* @return List of ProductResponse objects containing mapped data.
*/
default List<ProductResponse> toProductResponseList(List<Product> products) {

if (products == null) {
Expand All @@ -43,6 +58,11 @@ default List<ProductResponse> toProductResponseList(List<Product> products) {

}

/**
* Initializes and returns an instance of CustomPageToCustomPagingResponseMapper.
*
* @return Initialized CustomPageToCustomPagingResponseMapper instance.
*/
static CustomPageToCustomPagingResponseMapper initialize() {
return Mappers.getMapper(CustomPageToCustomPagingResponseMapper.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
import java.util.List;
import java.util.stream.Collectors;

/**
* Mapper interface named {@link ListProductEntityToListProductMapper} for converting {@link List<ProductEntity>} to {@link List<Product>}.
*/
@Mapper
public interface ListProductEntityToListProductMapper {

ProductEntityToProductMapper productEntityToProductMapper = Mappers.getMapper(ProductEntityToProductMapper.class);

/**
* Converts a list of ProductEntity objects to a list of Product objects.
*
* @param productEntities The list of ProductEntity objects to convert.
* @return List of Product objects containing mapped data.
*/
default List<Product> toProductList(List<ProductEntity> productEntities) {

if (productEntities == null) {
Expand All @@ -25,7 +34,11 @@ default List<Product> toProductList(List<ProductEntity> productEntities) {

}


/**
* Initializes and returns an instance of ListProductEntityToListProductMapper.
*
* @return Initialized ListProductEntityToListProductMapper instance.
*/
static ListProductEntityToListProductMapper initialize() {
return Mappers.getMapper(ListProductEntityToListProductMapper.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

/**
* Mapper interface named {@link ProductCreateRequestToProductEntityMapper} for converting {@link ProductCreateRequest} to {@link ProductEntity}.
*/
@Mapper
public interface ProductCreateRequestToProductEntityMapper extends BaseMapper<ProductCreateRequest, ProductEntity> {


/**
* Maps ProductCreateRequest to ProductEntity for saving purposes.
*
* @param productCreateRequest The ProductCreateRequest object to map.
* @return ProductEntity object containing mapped data.
*/
@Named("mapForSaving")
default ProductEntity mapForSaving(ProductCreateRequest productCreateRequest) {
return ProductEntity.builder()
Expand All @@ -20,6 +28,11 @@ default ProductEntity mapForSaving(ProductCreateRequest productCreateRequest) {
.build();
}

/**
* Initializes and returns an instance of ProductCreateRequestToProductEntityMapper.
*
* @return Initialized ProductCreateRequestToProductEntityMapper instance.
*/
static ProductCreateRequestToProductEntityMapper initialize() {
return Mappers.getMapper(ProductCreateRequestToProductEntityMapper.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
* Mapper interface named {@link ProductEntityToProductMapper} for converting {@link ProductEntity} to {@link Product}.
*/
@Mapper
public interface ProductEntityToProductMapper extends BaseMapper<ProductEntity, Product> {

/**
* Maps ProductEntity to Product.
*
* @param source The ProductEntity object to map.
* @return Product object containing mapped data.
*/
@Override
Product map(ProductEntity source);

/**
* Initializes and returns an instance of ProductEntityToProductMapper.
*
* @return Initialized ProductEntityToProductMapper instance.
*/
static ProductEntityToProductMapper initialize() {
return Mappers.getMapper(ProductEntityToProductMapper.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
* Mapper interface named {@link ProductToProductEntityMapper} for converting {@link Product} to {@link ProductEntity}.
*/
@Mapper
public interface ProductToProductEntityMapper extends BaseMapper<Product, ProductEntity> {

/**
* Maps Product to ProductEntity.
*
* @param source The Product object to map.
* @return ProductEntity object containing mapped data.
*/
@Override
ProductEntity map(Product source);

/**
* Initializes and returns an instance of ProductToProductEntityMapper.
*
* @return Initialized ProductToProductEntityMapper instance.
*/
static ProductToProductEntityMapper initialize() {
return Mappers.getMapper(ProductToProductEntityMapper.class);
}
Expand Down
Loading

0 comments on commit dec2519

Please sign in to comment.