Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelPelegrina committed Apr 19, 2024
2 parents 76c8c34 + e18180f commit 0bb4a87
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17-jdk-alpine
FROM openjdk:23-ea-17-jdk-oraclelinux8

COPY ./target/online_store-0.0.1-SNAPSHOT.jar ./app.jar

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Build Status](https://github.com/MiguelPelegrina/java_school_online_store_api/actions/workflows/ci.yml/badge.svg)

# JavaSchoolFinalTask2
Final Task
Online store information system.
Expand Down
32 changes: 22 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.4</version>
<version>3.2.4</version>
<relativePath/>
</parent>
<groupId>com.javaSchool</groupId>
Expand Down Expand Up @@ -36,6 +36,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.3</version>
<scope>runtime</scope>
</dependency>

Expand All @@ -54,30 +55,31 @@
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>

<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.2</version>
<version>3.6.3</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>3.1.4</version>
<version>3.2.4</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
<version>2.4.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>3.2.4</version>
</dependency>

<dependency>
Expand All @@ -89,22 +91,22 @@
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
<version>2.3.1</version>
</dependency>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<scope>provided</scope>
<classifier>jakarta</classifier>
<version>5.0.0</version>
<version>5.1.0</version>
</dependency>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<classifier>jakarta</classifier>
<version>5.0.0</version>
<version>5.1.0</version>
</dependency>

<dependency>
Expand All @@ -116,7 +118,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.8</version>
<version>1.8.0</version>
</dependency>

<dependency>
Expand All @@ -139,7 +141,17 @@
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>1.3.26</version>
<version>1.4.1</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for setting up JPAQueryFactory bean.
* Provides bean definitions for creating and configuring JPAQueryFactory instances.
*/
@Configuration
public class JPAQueryFactoryConfig {
/**
* Configures and provides a JPAQueryFactory bean.
*
* @param entityManager The EntityManager instance to be injected into the JPAQueryFactory.
* @return JPAQueryFactory A configured bean of JPAQueryFactory that integrates with JPA.
*/
@Bean
public JPAQueryFactory jpaQueryFactory(@Autowired EntityManager entityManager) {
return new JPAQueryFactory(entityManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;

/**
* Configuration class for Thymeleaf template engine setup.
* Provides bean definitions for configuring Thymeleaf template resolution and processing.
*/
@Configuration
public class ThymeleafConfig {
/**
* Configures and provides a ClassLoaderTemplateResolver bean for Thymeleaf.
*
* @return ClassLoaderTemplateResolver A configured template resolver for resolving templates from the classpath.
*/
@Bean
public ClassLoaderTemplateResolver templateResolver() {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
Expand All @@ -18,6 +27,11 @@ public ClassLoaderTemplateResolver templateResolver() {
return templateResolver;
}

/**
* Configures and provides a SpringTemplateEngine bean for Thymeleaf.
*
* @return SpringTemplateEngine A configured template engine that integrates with Spring and Thymeleaf.
*/
@Bean
public SpringTemplateEngine templateEngine() {
var templateEngine = new SpringTemplateEngine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ public interface OrderRestController {
*/
ResponseEntity<BigDecimal> calculateTotalRevenue(LocalDate startDate, LocalDate endDate);

/**
* Calculates the revenue of a year from January to December based on the provided date.
*
* @param date The date to calculate the revenue for, formatted as "dd-MM-yyyy".
* @return A ResponseEntity containing an array of BigDecimal representing the revenue for each month of the year.
*/
ResponseEntity<BigDecimal[]> calculateRevenuesOfYearByMonths(LocalDate date);

/**
* Calculates the revenue of the last 12 months.
*
* @param date The date to calculate the revenue from, formatted as "dd-MM-yyyy".
* @return A ResponseEntity containing an array of BigDecimal representing the revenue for each of the last 12 months.
*/
ResponseEntity<BigDecimal[]> calculateRevenuesOfLast12Months(LocalDate date);

/**
* Submits a POST request with a {@link SaveOrderDTO} to create an order instance in the database.
*
Expand All @@ -38,4 +54,6 @@ public interface OrderRestController {
* If successful, the code is 200 created successfully, 204 otherwise.
*/
ResponseEntity<OrderDTO> saveInstance(SaveOrderDTO saveOrderDTO);


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
* the object(s) of the entity {@link OrderEntity} as {@link OrderDTO} to the {@link OrderRestControllerImpl}.
*/
public interface OrderService {
/**
* Calculates the revenue for a specified year or the last 12 months.
*
* @param year The year for which the revenue should be calculated.
* @param isLast12Months A boolean flag indicating whether to calculate the revenue for the last 12 months from the current date.
* @return An array of BigDecimal representing the revenue for each month within the specified year or for the last 12 months.
*/
BigDecimal[] calculateRevenueOfYearByMonths(LocalDate year, boolean isLast12Months);

/**
* Retrieves a page of {@link OrderDTO}s from the database based on {@link OrderRequestDTO}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ResponseEntity<Page<OrderDTO>> getAllInstances(
}

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Calculated the revenue",
@ApiResponse(responseCode = "200", description = "Calculate the total revenue",
content = {@Content(mediaType = "application/json", schema = @Schema)}),
@ApiResponse(responseCode = "401", description = "Not authorized", content = @Content),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content)
Expand All @@ -73,6 +73,32 @@ public ResponseEntity<BigDecimal> calculateTotalRevenue(
return ResponseEntity.ok(this.service.calculateTotalRevenue(startDate, endDate));
}

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Calculate the revenue of a year from january to december",
content = {@Content(mediaType = "application/json", schema = @Schema)}),
@ApiResponse(responseCode = "401", description = "Not authorized", content = @Content),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content)
})
@GetMapping("/revenueOfYearByMonths")
@Override
public ResponseEntity<BigDecimal[]> calculateRevenuesOfYearByMonths(
@RequestParam("date") @DateTimeFormat(pattern = "dd-MM-yyyy") LocalDate date) {
return ResponseEntity.ok(this.service.calculateRevenueOfYearByMonths(date, false));
}

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Calculate the revenue of the last 12 months",
content = {@Content(mediaType = "application/json", schema = @Schema)}),
@ApiResponse(responseCode = "401", description = "Not authorized", content = @Content),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content)
})
@GetMapping("/revenueOfLast12Months")
@Override
public ResponseEntity<BigDecimal[]> calculateRevenuesOfLast12Months(
@RequestParam("date") @DateTimeFormat(pattern = "dd-MM-yyyy") LocalDate date) {
return ResponseEntity.ok(this.service.calculateRevenueOfYearByMonths(date, true));
}

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Saved the order",
content = {@Content(mediaType = "application/json", schema = @Schema)}),
Expand Down
Loading

0 comments on commit 0bb4a87

Please sign in to comment.