diff --git a/Procfile b/Procfile index 70642c8..4eeee09 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: java -jar -Dspring.profiles.active=prod -Dserver.port=$PORT target/financial-java-api-2.0.0-SNAPSHOT.jar \ No newline at end of file +web: java -jar -Dspring.profiles.active=prod -Dserver.port=$PORT target/financial-java-api-2.0.1-SNAPSHOT.jar \ No newline at end of file diff --git a/README.md b/README.md index 37e1bc2..a2d365b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ This endpoint is called to create a new transaction. **Body:** - +```json { "nsu": "123456", "authorizationNumber": "010203", @@ -34,7 +34,7 @@ This endpoint is called to create a new transaction. "transactionDate": "2020-04-05T09:59:51.312Z", "type": "CARD", } - +``` **Where:** @@ -68,7 +68,7 @@ This endpoint is called to update a transaction. **Body:** - +```json { "id": 1, "nsu": "123456", @@ -77,12 +77,12 @@ This endpoint is called to update a transaction. "transactionDate": "2020-04-05T09:59:51.312Z", "type": "CARD" } - +``` Must be submitted the object that will be modified. Must return a transaction specified by ID and all fields recorded above, including links and the one that was updated. - +```json { "data": { "id": 1, @@ -99,7 +99,7 @@ the one that was updated. ] } } - +``` `GET/financial/v1/transactions` @@ -119,7 +119,7 @@ This endpoint returns the statistics based on the transactions created. **Returns:** - +```json { "data": { "sum": "150.06", @@ -135,7 +135,7 @@ This endpoint returns the statistics based on the transactions created. ] } } - +``` **Where:** @@ -151,7 +151,7 @@ This endpoint returns the statistics based on the transactions created. `links` - self-linking URL for the statistic. It is automatically generated. -All BigDecimal values always contain exactly two decimal places, eg: 15.385 is returned as 15.39. +All `BigDecimal` values always contain exactly two decimal places, eg: `15.385` is returned as `15.39`. ### Technologies used @@ -160,33 +160,36 @@ This project was developed with: * **Java 11 (Java Development Kit - JDK: 11.0.3)** * **Spring Boot 2.2.6** * **Spring Framework 2.2.6** +* **Maven** * **JUnit 5** -* **PostgreSQL 9.6.17** +* **Surfire** +* **PostgreSQL 12** * **Flyway 6.0.8** * **Swagger 2.9.2** +* **Model Mapper 2.3.6** * **Heroku** ### Compile and Package -The API also was developed to run with an jar. In order to generate this jar, you should run: +The API also was developed to run with an `jar`. In order to generate this `jar`, you should run: -``` +```bash mvn package ``` -It will clean, compile and generate a jar at target directory, e.g. `financial-java-api-2.0.0-SNAPSHOT.jar` +It will clean, compile and generate a `jar` at target directory, e.g. `financial-java-api-2.0.1-SNAPSHOT.jar` ### Execution You need to have **PostgreSQL 9.6.17 or above** installed on your machine to run the API on `dev` profile. After installed, on the `pgAdmin` create a database named `financial`. If you don't have `pgAdmin` installed you can run on the `psql` console the follow command: -``` +```sql CREATE database financial; ``` After creating the API database, you need to add your **Postgres** root `username` and `password` in the `application.properties` file on `src/main/resource`. The lines that must be modified are as follows: -``` +```properties spring.datasource.username= spring.datasource.password= ``` @@ -197,13 +200,13 @@ When the application is running **Flyway** will create the necessary tables for * For unit test phase, you can run: -``` +```bash mvn test ``` * To run all tests (including Integration Tests): -``` +```bash mvn integration-test ``` @@ -211,13 +214,13 @@ mvn integration-test In order to run the API, run the jar simply as following: -``` -java -jar financial-java-api-2.0.0-SNAPSHOT.jar --spring.profiles.active=prod +```bash +java -jar financial-java-api-2.0.1-SNAPSHOT.jar --spring.profiles.active=prod ``` or -``` +```bash mvn spring-boot:run -Dspring.profiles.active=prod ``` diff --git a/pom.xml b/pom.xml index f4b198f..0d6f441 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.github.mariazevedo88 financial-java-api - 2.0.0-SNAPSHOT + 2.0.1-SNAPSHOT jar financial-java-api diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/model/statistic/StatisticDTO.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/model/statistic/StatisticDTO.java index 3848f22..616fe16 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/model/statistic/StatisticDTO.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/model/statistic/StatisticDTO.java @@ -17,36 +17,26 @@ * @author Mariana Azevedo * @since 01/04/2020 */ +@Getter +@Setter @NoArgsConstructor @EqualsAndHashCode(callSuper = false) public class StatisticDTO extends RepresentationModel { - @Getter - @Setter private Long id; - @Getter - @Setter @NotNull(message="Sum cannot be null") private BigDecimal sum; - @Getter - @Setter @NotNull(message="Avg cannot be null") private BigDecimal avg; - @Getter - @Setter @NotNull(message="Max cannot be null") private BigDecimal max; - @Getter - @Setter @NotNull(message="Min cannot be null") private BigDecimal min; - @Getter - @Setter @NotNull(message="Count cannot be null") private long count; } diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/model/transaction/TransactionDTO.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/model/transaction/TransactionDTO.java index cfb9825..82b1f31 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/model/transaction/TransactionDTO.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/model/transaction/TransactionDTO.java @@ -23,37 +23,27 @@ * @author Mariana Azevedo * @since 01/04/2020 */ +@Getter +@Setter @EqualsAndHashCode(callSuper = false) public class TransactionDTO extends RepresentationModel { - @Getter - @Setter private Long id; - @Getter - @Setter @NotNull(message="Nsu cannot be null") @Length(min=6, message="Nsu must contain at least 6 characters") private String nsu; - @Getter - @Setter private String authorizationNumber; - @Getter - @Setter @DateTimeFormat(iso = ISO.DATE_TIME) @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @NotNull(message="TransactionDate cannot be null") private Date transactionDate; - @Getter - @Setter @NotNull(message="Amount cannot be null") private BigDecimal amount; - @Getter - @Setter @NotNull(message="Type cannot be null") private TransactionTypeEnum type; diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/response/Response.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/response/Response.java index 1fca33b..1ca08a7 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/response/Response.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/response/Response.java @@ -16,16 +16,14 @@ * * @param */ +@Getter +@Setter @NoArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) public class Response { - @Getter - @Setter private T data; - @Getter - @Setter private Object errors; /** diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/response/ResponseError.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/response/ResponseError.java index 00fce7d..b36e6fc 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/response/ResponseError.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/dto/response/ResponseError.java @@ -15,17 +15,15 @@ * @author Mariana Azevedo * @since 01/04/2020 */ +@Getter +@Setter @Accessors(chain = true) @NoArgsConstructor public class ResponseError { - @Getter - @Setter @NotNull(message="Timestamp cannot be null") private LocalDateTime timestamp; - @Getter - @Setter @NotNull(message="Details cannot be null") private String details; diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/model/statistic/Statistic.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/model/statistic/Statistic.java index db558c8..6d13601 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/model/statistic/Statistic.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/model/statistic/Statistic.java @@ -22,6 +22,8 @@ * @since 01/04/2020 */ @Entity +@Getter +@Setter @Table(name = "statistics") @NoArgsConstructor @AllArgsConstructor @@ -30,33 +32,21 @@ public class Statistic implements Serializable { private static final long serialVersionUID = -7804600023031651840L; @Id - @Getter - @Setter @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Getter - @Setter @Column(name = "transactions_sum") private BigDecimal sum; - @Getter - @Setter @Column(name = "transactions_avg") private BigDecimal avg; - @Getter - @Setter @Column(name = "transactions_max") private BigDecimal max; - @Getter - @Setter @Column(name = "transactions_min") private BigDecimal min; - @Getter - @Setter @Column(name = "transactions_count") private long count; diff --git a/src/main/java/io/github/mariazevedo88/financialjavaapi/model/transaction/Transaction.java b/src/main/java/io/github/mariazevedo88/financialjavaapi/model/transaction/Transaction.java index 7048466..93b7402 100644 --- a/src/main/java/io/github/mariazevedo88/financialjavaapi/model/transaction/Transaction.java +++ b/src/main/java/io/github/mariazevedo88/financialjavaapi/model/transaction/Transaction.java @@ -31,42 +31,32 @@ * @since 01/04/2020 */ @Entity -@Table(name = "transaction") +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor +@Table(name = "transaction") public class Transaction implements Serializable { private static final long serialVersionUID = -3656431259068389491L; @Id - @Getter - @Setter @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Getter - @Setter @NotNull private String nsu; - @Getter - @Setter private String authorizationNumber; - @Getter - @Setter @NotNull @DateTimeFormat(iso = ISO.DATE_TIME) @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") private Date transactionDate; - @Getter - @Setter @NotNull private BigDecimal amount; - @Getter - @Setter @NotNull @Enumerated(EnumType.STRING) private TransactionTypeEnum type;