├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── src ├── main │ ├── java │ │ └── com │ │ │ └── ecommercebd │ │ │ ├── payment │ │ │ ├── Status.java │ │ │ ├── Type.java │ │ │ └── Payment.java │ │ │ ├── user │ │ │ ├── domain │ │ │ │ ├── Role.java │ │ │ │ ├── UserRepository.java │ │ │ │ └── User.java │ │ │ ├── infra │ │ │ │ └── UserJpaRepository.java │ │ │ └── application │ │ │ │ ├── UserId.java │ │ │ │ ├── UserResponse.java │ │ │ │ ├── UpdateUserPasswordRequest.java │ │ │ │ ├── NewPublicUserRequest.java │ │ │ │ ├── NewUserRequest.java │ │ │ │ ├── MyUserController.java │ │ │ │ └── UserController.java │ │ │ ├── mapper │ │ │ └── Mapper.java │ │ │ ├── product │ │ │ ├── application │ │ │ │ ├── ProductResponse.java │ │ │ │ ├── NewProductRequest.java │ │ │ │ └── ProductController.java │ │ │ ├── infra │ │ │ │ └── ProductJpaRepository.java │ │ │ └── domain │ │ │ │ ├── ProductRepository.java │ │ │ │ └── Product.java │ │ │ ├── plan │ │ │ ├── domain │ │ │ │ ├── PlanRepository.java │ │ │ │ └── Plan.java │ │ │ ├── infra │ │ │ │ └── PlanJpaRepository.java │ │ │ └── application │ │ │ │ ├── ProductId.java │ │ │ │ ├── BusinessException.java │ │ │ │ ├── PlanResponse.java │ │ │ │ ├── NewPlanRequest.java │ │ │ │ └── PlanController.java │ │ │ ├── EcommerceBdApplication.java │ │ │ ├── order │ │ │ ├── application │ │ │ │ ├── PlanId.java │ │ │ │ ├── OrderResponse.java │ │ │ │ ├── NewMyOrderRequest.java │ │ │ │ ├── NewOrderRequest.java │ │ │ │ ├── MyOrderController.java │ │ │ │ └── OrderController.java │ │ │ ├── domain │ │ │ │ ├── OrderRepository.java │ │ │ │ └── Order.java │ │ │ └── infra │ │ │ │ └── OrderJpaRepository.java │ │ │ ├── exception │ │ │ └── NotFoundException.java │ │ │ ├── security │ │ │ ├── IsAdmin.java │ │ │ ├── IsClient.java │ │ │ ├── IsClientOrAdmin.java │ │ │ ├── JPAUserDetailsService.java │ │ │ └── CustomWebSecurityConfigurerAdapter.java │ │ │ ├── database │ │ │ └── DataBase.java │ │ │ └── config │ │ │ └── ModelMapperConfig.java │ └── resources │ │ └── application.properties └── test │ └── java │ └── com │ └── ecommercebd │ └── EcommerceBdApplicationTests.java ├── .gitignore ├── README.md ├── docs ├── Ecomerce de BD.postman_collection.json ├── openAPI.yml ├── useCaseDiagram.svg └── classDiagram.svg ├── pom.xml ├── mvnw.cmd └── mvnw /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariasantosdev/e-commerce-database/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/payment/Status.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.payment; 2 | 3 | public enum Status { 4 | REGULAR, REIMBURSED; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/domain/Role.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.domain; 2 | 3 | public enum Role { 4 | ADMIN, CLIENT; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/payment/Type.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.payment; 2 | 3 | public enum Type { 4 | CREDIT_CARD, DEBIT_CARD, BANK_SLIP; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/mapper/Mapper.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.mapper; 2 | 3 | public interface Mapper { 4 | 5 | D map(Object source, Class destinationType); 6 | 7 | void map(Object source, Object destination); 8 | } 9 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/product/application/ProductResponse.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.product.application; 2 | 3 | import lombok.*; 4 | 5 | @Getter 6 | @Setter 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | public class ProductResponse { 10 | private Long id; 11 | private String name; 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/ecommercebd/EcommerceBdApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class EcommerceBdApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/plan/domain/PlanRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.plan.domain; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | public interface PlanRepository { 7 | 8 | List findAll(); 9 | Plan save(Plan entity); 10 | Optional findById(Long id); 11 | void delete(Plan entity); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/plan/infra/PlanJpaRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.plan.infra; 2 | 3 | import com.ecommercebd.plan.domain.Plan; 4 | import com.ecommercebd.plan.domain.PlanRepository; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | interface PlanJpaRepository extends JpaRepository, PlanRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/infra/UserJpaRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.infra; 2 | 3 | import com.ecommercebd.user.domain.User; 4 | import com.ecommercebd.user.domain.UserRepository; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | public interface UserJpaRepository extends JpaRepository, UserRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/product/infra/ProductJpaRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.product.infra; 2 | 3 | import com.ecommercebd.product.domain.ProductRepository; 4 | import com.ecommercebd.product.domain.Product; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | interface ProductJpaRepository extends JpaRepository, ProductRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/domain/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.domain; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | public interface UserRepository { 7 | List findAll(); 8 | User save(User entity); 9 | Optional findById(Long id); 10 | void delete(User entity); 11 | Optional findByEmail(String email); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/EcommerceBdApplication.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class EcommerceBdApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(EcommerceBdApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/product/domain/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.product.domain; 2 | 3 | import com.ecommercebd.product.domain.Product; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface ProductRepository { 9 | 10 | List findAll(); 11 | Product save(Product entity); 12 | Optional findById(Long id); 13 | void delete(Product entity); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/application/UserId.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.application; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import javax.validation.constraints.NotNull; 9 | 10 | @Getter 11 | @Setter 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class UserId { 15 | @NotNull 16 | private Long id; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/application/UserResponse.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.application; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @Getter 9 | @Setter 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class UserResponse { 13 | private Long id; 14 | private String email; 15 | private String phone; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/application/PlanId.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.application; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import javax.validation.constraints.NotNull; 9 | 10 | @Getter 11 | @Setter 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class PlanId { 15 | @NotNull 16 | private Long id; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/plan/application/ProductId.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.plan.application; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import javax.validation.constraints.NotNull; 9 | 10 | @Getter 11 | @Setter 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class ProductId { 15 | @NotNull 16 | private Long id; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | ##datasource 2 | spring.datasource.url=jdbc:mysql://localhost/ecommerce-bd?createDatabaseIfNotExist=true&serverTimezone=UTC 3 | spring.datasource.username= root 4 | spring.datasource.password= 5 | spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver 6 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect 7 | 8 | ##jpa 9 | spring.jpa.hibernate.ddl-auto=update 10 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/product/application/NewProductRequest.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.product.application; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import javax.validation.constraints.NotBlank; 9 | 10 | @Getter 11 | @Setter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | class NewProductRequest { 15 | 16 | @NotBlank 17 | private String name; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/exception/NotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.exception; 2 | 3 | import lombok.NoArgsConstructor; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.web.bind.annotation.ResponseStatus; 6 | 7 | @ResponseStatus(HttpStatus.NOT_FOUND) 8 | @NoArgsConstructor 9 | public class NotFoundException extends RuntimeException { 10 | 11 | public NotFoundException(String message) { 12 | super(message); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/payment/Payment.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.payment; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | @Entity 9 | public class Payment { 10 | @Id 11 | @GeneratedValue(strategy = GenerationType.IDENTITY) 12 | private Long id; 13 | private Type type; 14 | private Status status; 15 | private String obs; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/application/UpdateUserPasswordRequest.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.application; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import javax.validation.constraints.NotBlank; 9 | 10 | @Getter 11 | @Setter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class UpdateUserPasswordRequest { 15 | 16 | @NotBlank 17 | private String password; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/domain/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.domain; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | public interface OrderRepository { 7 | 8 | List findAll(); 9 | Order save(Order entity); 10 | Optional findById(Long id); 11 | 12 | List findAllByCustomerEmail(String email); 13 | 14 | Optional findByIdAndCustomerEmail(Long id, String email); 15 | void delete(Order entity); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/plan/application/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.plan.application; 2 | 3 | import lombok.NoArgsConstructor; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.web.bind.annotation.ResponseStatus; 6 | 7 | @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) 8 | @NoArgsConstructor 9 | public class BusinessException extends RuntimeException { 10 | 11 | public BusinessException(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/security/IsAdmin.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.security; 2 | 3 | 4 | import org.springframework.security.access.prepost.PreAuthorize; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Target({ ElementType.METHOD, ElementType.TYPE }) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @PreAuthorize("hasRole('ADMIN')") 14 | public @interface IsAdmin { 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/security/IsClient.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.security; 2 | 3 | 4 | import org.springframework.security.access.prepost.PreAuthorize; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Target({ ElementType.METHOD, ElementType.TYPE }) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @PreAuthorize("hasRole('CLIENT')") 14 | public @interface IsClient { 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/security/IsClientOrAdmin.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.security; 2 | 3 | 4 | import org.springframework.security.access.prepost.PreAuthorize; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Target({ ElementType.METHOD, ElementType.TYPE }) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @PreAuthorize("hasAnyRole('ADMIN','CLIENT')") 14 | public @interface IsClientOrAdmin { 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/database/DataBase.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.database; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | @Entity 9 | public class DataBase { 10 | @Id 11 | @GeneratedValue(strategy = GenerationType.IDENTITY) 12 | private Long id; 13 | private String name; 14 | private int port; 15 | private String password; 16 | private String username; 17 | private String timeZone; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/infra/OrderJpaRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.infra; 2 | 3 | import com.ecommercebd.order.domain.Order; 4 | import com.ecommercebd.order.domain.OrderRepository; 5 | import org.springframework.data.jpa.repository.EntityGraph; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | 8 | import java.util.List; 9 | 10 | public interface OrderJpaRepository extends JpaRepository, OrderRepository { 11 | 12 | @EntityGraph(attributePaths = {"customer"}) 13 | List findAll(); 14 | 15 | 16 | } -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/product/domain/Product.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.product.domain; 2 | 3 | import lombok.Getter; 4 | import lombok.NoArgsConstructor; 5 | import lombok.Setter; 6 | 7 | import javax.persistence.Entity; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.GenerationType; 10 | import javax.persistence.Id; 11 | 12 | @Entity 13 | @Getter 14 | @Setter 15 | @NoArgsConstructor 16 | public class Product { 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | private Long id; 20 | private String name; 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## E-commerce-database 2 | 3 | 4 | 🏷️ Sobre o Projeto:
5 | E-commerce para realizar a venda de diversos banco de dados 6 | 7 | 🚀Ferramentas utilizadas: 8 | - Spring Data 9 | - Spring security 10 | - mysql 11 | - java 17 12 | 13 | ⚙️Principais funcionalidades implementadas no back-end: 14 |
... 15 | 16 | 📄 Documentação: 17 | - Diagrama de Classe: 18 | ![imagem com diagrama de classe do projeto](https://github.com/mariasantosdev/e-commerce-database/blob/master/docs/classDiagram.svg) 19 | 20 | - Diagrama de Caso de uso: 21 | ![imagem com diagrama de caso de uso](https://github.com/mariasantosdev/e-commerce-database/blob/master/docs/useCaseDiagram.svg) 22 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import javax.persistence.*; 9 | 10 | @Entity 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | @Getter 14 | @Setter 15 | @Table(name = "`user`") 16 | public class User { 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | private Long id; 20 | private String email; 21 | private String password; 22 | private String phone; 23 | private String cpf; 24 | @Enumerated(EnumType.ORDINAL) 25 | private Role role; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/application/OrderResponse.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.application; 2 | 3 | import com.ecommercebd.plan.domain.Plan; 4 | import com.ecommercebd.user.application.UserResponse; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | 10 | import java.math.BigDecimal; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | @Getter 15 | @Setter 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class OrderResponse { 19 | private Long id; 20 | private BigDecimal subtotal; 21 | private UserResponse customer; 22 | private List plans = new ArrayList<>(); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/application/NewPublicUserRequest.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.application; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | import org.hibernate.validator.constraints.br.CPF; 8 | 9 | import javax.validation.constraints.Email; 10 | import javax.validation.constraints.NotBlank; 11 | 12 | @Getter 13 | @Setter 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class NewPublicUserRequest { 17 | 18 | @NotBlank 19 | @Email 20 | private String email; 21 | @NotBlank 22 | private String password; 23 | private String phone; 24 | @NotBlank 25 | @CPF 26 | private String cpf; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/plan/application/PlanResponse.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.plan.application; 2 | 3 | import com.ecommercebd.product.application.ProductResponse; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.math.BigDecimal; 10 | 11 | @Getter 12 | @Setter 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | class PlanResponse { 16 | private Long id; 17 | private BigDecimal price; 18 | private String name; 19 | private String description; 20 | private String characteristic; 21 | private Long storage; 22 | private int limitOfConnections; 23 | private int limitOfUsers; 24 | private ProductResponse product; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/application/NewMyOrderRequest.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.application; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import javax.validation.Valid; 10 | import javax.validation.constraints.DecimalMin; 11 | import javax.validation.constraints.NotNull; 12 | import java.math.BigDecimal; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | @Getter 17 | @Setter 18 | @NoArgsConstructor 19 | @AllArgsConstructor 20 | public class NewMyOrderRequest { 21 | @DecimalMin(value = "0.1") 22 | @NotNull(message = "Subtotal inválido") 23 | @JsonProperty 24 | private BigDecimal subtotal; 25 | @NotNull @Valid 26 | private List plans = new ArrayList<>(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/application/NewUserRequest.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.application; 2 | 3 | import com.ecommercebd.user.domain.Role; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | import org.hibernate.validator.constraints.br.CPF; 9 | 10 | import javax.validation.constraints.Email; 11 | import javax.validation.constraints.NotBlank; 12 | import javax.validation.constraints.NotNull; 13 | 14 | 15 | @Getter 16 | @Setter 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class NewUserRequest { 20 | 21 | @NotBlank 22 | @Email 23 | private String email; 24 | @NotBlank 25 | private String password; 26 | private String phone; 27 | @NotBlank 28 | @CPF 29 | private String cpf; 30 | @NotNull 31 | private Role role = Role.CLIENT; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/config/ModelMapperConfig.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.config; 2 | 3 | import com.ecommercebd.mapper.Mapper; 4 | import org.modelmapper.ModelMapper; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class ModelMapperConfig { 10 | @Bean 11 | public Mapper mapper() { 12 | final ModelMapper modelMapper = new ModelMapper(); 13 | return new Mapper() { 14 | @Override 15 | public D map(Object source, Class destinationType) { 16 | return modelMapper.map(source, destinationType); 17 | } 18 | 19 | @Override 20 | public void map(Object source, Object destination) { 21 | modelMapper.map(source, destination); 22 | } 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/application/NewOrderRequest.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.application; 2 | 3 | import com.ecommercebd.order.domain.Order; 4 | import com.ecommercebd.plan.domain.Plan; 5 | import com.ecommercebd.user.application.UserId; 6 | import com.ecommercebd.user.domain.User; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | import lombok.AllArgsConstructor; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | import javax.validation.Valid; 14 | import javax.validation.constraints.DecimalMin; 15 | import javax.validation.constraints.NotBlank; 16 | import javax.validation.constraints.NotNull; 17 | import java.math.BigDecimal; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | @Getter 22 | @Setter 23 | @NoArgsConstructor 24 | @AllArgsConstructor 25 | class NewOrderRequest { 26 | 27 | @DecimalMin(value = "0.1") 28 | @NotNull(message = "Subtotal inválido") 29 | @JsonProperty 30 | private BigDecimal subtotal; 31 | @NotNull @Valid 32 | private UserId customer; 33 | @NotNull @Valid 34 | private List plans = new ArrayList<>(); 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/domain/Order.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.domain; 2 | 3 | import com.ecommercebd.plan.domain.Plan; 4 | import com.ecommercebd.user.domain.User; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | 10 | import javax.persistence.*; 11 | import javax.validation.constraints.NotNull; 12 | import java.math.BigDecimal; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | @Entity 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | @Getter 20 | @Setter 21 | @Table(name = "`order`") 22 | public class Order { 23 | @Id 24 | @GeneratedValue(strategy = GenerationType.IDENTITY) 25 | private Long id; 26 | private BigDecimal subtotal; 27 | @NotNull 28 | @ManyToOne(fetch = FetchType.LAZY) 29 | @JoinColumn(name = "customer_id", 30 | foreignKey = @ForeignKey(name = "fk_order_customer_id")) 31 | private User customer; 32 | @ManyToMany(fetch = FetchType.LAZY) 33 | @JoinTable(name = "order_plans", 34 | joinColumns = @JoinColumn(name = "order_id", 35 | foreignKey = @ForeignKey(name = "fk_order_plans_order_id")), 36 | inverseJoinColumns = @JoinColumn(name = "plan_id", 37 | foreignKey = @ForeignKey(name = "fk_order_plans_plan_id"))) 38 | private List plans = new ArrayList<>(); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/security/JPAUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.security; 2 | 3 | import com.ecommercebd.user.domain.Role; 4 | import com.ecommercebd.user.domain.UserRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 7 | import org.springframework.security.core.userdetails.User; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | import org.springframework.security.core.userdetails.UserDetailsService; 10 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.Arrays; 14 | 15 | @Service 16 | public class JPAUserDetailsService implements UserDetailsService { 17 | 18 | @Autowired 19 | private UserRepository userRepository; 20 | 21 | @Override 22 | public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { 23 | var user = userRepository.findByEmail(email) 24 | .orElseThrow(()-> new UsernameNotFoundException(email)); 25 | 26 | final Role role = user.getRole(); 27 | 28 | final SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROLE_"+role.name()); 29 | 30 | return new User( 31 | user.getEmail(), 32 | user.getPassword(), 33 | Arrays.asList(simpleGrantedAuthority) 34 | ); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/security/CustomWebSecurityConfigurerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.security; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 10 | import org.springframework.security.core.userdetails.UserDetailsService; 11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 12 | import org.springframework.security.crypto.password.PasswordEncoder; 13 | 14 | @Configuration 15 | @EnableWebSecurity 16 | @EnableGlobalMethodSecurity(prePostEnabled = true) 17 | public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { 18 | 19 | @Autowired 20 | private UserDetailsService userDetailsService; 21 | 22 | @Bean 23 | public PasswordEncoder passwordEncoder() { 24 | return new BCryptPasswordEncoder(); 25 | } 26 | 27 | @Override 28 | protected void configure(HttpSecurity http) throws Exception { 29 | http.userDetailsService(userDetailsService) 30 | .csrf().disable() 31 | .httpBasic(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/plan/domain/Plan.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.plan.domain; 2 | 3 | import com.ecommercebd.product.domain.Product; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import javax.persistence.*; 10 | import javax.validation.constraints.Positive; 11 | import javax.validation.constraints.Size; 12 | import java.math.BigDecimal; 13 | 14 | @Entity 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | @Getter 18 | @Setter 19 | public class Plan { 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private Long id; 23 | private BigDecimal price; 24 | @Column(unique=true) 25 | @Size(min =1, max=200) 26 | private String name; 27 | @Size(min = 1, max=500) 28 | private String description; 29 | @Size(min = 1, max=500) 30 | private String characteristic; 31 | private Long storage; 32 | @Positive 33 | private int limitOfConnections; 34 | @Positive 35 | private int limitOfUsers; 36 | @ManyToOne 37 | @JoinColumn(name = "product_id", 38 | foreignKey = @ForeignKey(name = "fk_plan_product_id")) 39 | private Product product; 40 | 41 | public Plan(BigDecimal price, String name, String description, String characteristic, Long storage, 42 | int limitOfConnections, int limitOfUsers) { 43 | this.price = price; 44 | this.name = name; 45 | this.description = description; 46 | this.characteristic = characteristic; 47 | this.storage = storage; 48 | this.limitOfConnections = limitOfConnections; 49 | this.limitOfUsers = limitOfUsers; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/plan/application/NewPlanRequest.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.plan.application; 2 | 3 | import com.ecommercebd.plan.domain.Plan; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | import javax.validation.Valid; 9 | import javax.validation.constraints.NotBlank; 10 | import javax.validation.constraints.NotNull; 11 | import javax.validation.constraints.Positive; 12 | 13 | import java.math.BigDecimal; 14 | 15 | @Getter 16 | @Setter 17 | class NewPlanRequest { 18 | @NotNull(message = "Por favor insira um preço") 19 | @JsonProperty 20 | private BigDecimal price; 21 | @NotBlank(message = "Por favor insira um nome") 22 | @JsonProperty 23 | private String name; 24 | @NotBlank(message = "Por favor insira uma descrição") 25 | @JsonProperty 26 | private String description; 27 | @NotBlank(message = "Por favor insira as caracteristicas do produto") 28 | @JsonProperty 29 | private String characteristic; 30 | @NotNull(message = "Por favor insira o tamanho do armazenamento desse banco de dados") 31 | @JsonProperty 32 | private Long storage; 33 | @NotNull(message = "Por favor insira a quantidade limite de conexões") 34 | @JsonProperty 35 | @Positive(message = "Por favor insira um número de conexões válido") 36 | private int limitOfConnections; 37 | @NotNull(message = "Por favor insira a quantidade limites de usuários") 38 | @JsonProperty 39 | @Positive(message = "Por favor insira um número de limite de usuários válido") 40 | private int limitOfUsers; 41 | @NotNull 42 | @Valid 43 | private ProductId product; 44 | 45 | Plan toEntity() { 46 | return new Plan(price, name, description, characteristic, storage, limitOfConnections, limitOfUsers); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /docs/Ecomerce de BD.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "b7017847-e8f0-4c7a-bfde-cc98a543f278", 4 | "name": "Ecomerce de BD", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 6 | }, 7 | "item": [ 8 | { 9 | "name": "Post Produto", 10 | "request": { 11 | "method": "POST", 12 | "header": [], 13 | "body": { 14 | "mode": "raw", 15 | "raw": "{\n \"price\": 10,\n \"name\": \"MySQL\",\n \"description\": \"MySQL\",\n \"characteristic\": \"Teste\",\n \"storage\": 100,\n \"limitOfConnections\": 10,\n \"limitOfUsers\": 2\n}", 16 | "options": { 17 | "raw": { 18 | "language": "json" 19 | } 20 | } 21 | }, 22 | "url": { 23 | "raw": "http://localhost:8080/products", 24 | "protocol": "http", 25 | "host": [ 26 | "localhost" 27 | ], 28 | "port": "8080", 29 | "path": [ 30 | "products" 31 | ] 32 | } 33 | }, 34 | "response": [] 35 | }, 36 | { 37 | "name": "Put Produto", 38 | "request": { 39 | "method": "PUT", 40 | "header": [], 41 | "body": { 42 | "mode": "raw", 43 | "raw": "{\n \"price\": 10,\n \"name\": \"MySQL 8\",\n \"description\": \"MySQL 8 DB\",\n \"characteristic\": \"Teste\",\n \"storage\": 100,\n \"limitOfConnections\": 10,\n \"limitOfUsers\": 2\n}", 44 | "options": { 45 | "raw": { 46 | "language": "json" 47 | } 48 | } 49 | }, 50 | "url": { 51 | "raw": "http://localhost:8080/products/1", 52 | "protocol": "http", 53 | "host": [ 54 | "localhost" 55 | ], 56 | "port": "8080", 57 | "path": [ 58 | "products", 59 | "1" 60 | ] 61 | } 62 | }, 63 | "response": [] 64 | }, 65 | { 66 | "name": "Get Produto", 67 | "request": { 68 | "method": "GET", 69 | "header": [], 70 | "url": { 71 | "raw": "http://localhost:8080/products", 72 | "protocol": "http", 73 | "host": [ 74 | "localhost" 75 | ], 76 | "port": "8080", 77 | "path": [ 78 | "products" 79 | ] 80 | } 81 | }, 82 | "response": [] 83 | } 84 | ] 85 | } -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/product/application/ProductController.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.product.application; 2 | 3 | import com.ecommercebd.exception.NotFoundException; 4 | import com.ecommercebd.mapper.Mapper; 5 | import com.ecommercebd.product.domain.Product; 6 | import com.ecommercebd.product.domain.ProductRepository; 7 | import com.ecommercebd.security.IsAdmin; 8 | import lombok.RequiredArgsConstructor; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import javax.validation.Valid; 13 | import java.util.List; 14 | 15 | @RestController 16 | @RequestMapping("/products") 17 | @RequiredArgsConstructor 18 | class ProductController { 19 | 20 | private final Mapper mapper; 21 | private final ProductRepository productRepository; 22 | 23 | @GetMapping 24 | List findAll() { 25 | return productRepository.findAll() 26 | .stream() 27 | .map(p -> mapper.map(p, ProductResponse.class)).toList(); 28 | } 29 | 30 | @GetMapping("{productId}") 31 | ProductResponse findById(@PathVariable Long productId) { 32 | return productRepository.findById(productId) 33 | .map(p -> mapper.map(p, ProductResponse.class)) 34 | .orElseThrow(() -> new NotFoundException("Produto não encontrado.")); 35 | } 36 | 37 | @PostMapping 38 | @ResponseStatus(HttpStatus.CREATED) 39 | @IsAdmin 40 | Product create(@RequestBody @Valid NewProductRequest newProductRequest) { 41 | return productRepository.save(mapper.map(newProductRequest, Product.class)); 42 | } 43 | 44 | @PutMapping("{productId}") 45 | @IsAdmin 46 | ProductResponse update(@PathVariable Long productId, 47 | @RequestBody @Valid NewProductRequest newProductRequest) { 48 | final Product product = productRepository.findById(productId) 49 | .orElseThrow(() -> new NotFoundException("Produto não encontrado.")); 50 | 51 | this.mapper.map(newProductRequest, product); 52 | this.productRepository.save(product); 53 | 54 | return this.mapper.map(product, ProductResponse.class); 55 | } 56 | 57 | @DeleteMapping("{productId}") 58 | @IsAdmin 59 | void delete(@PathVariable Long productId) { 60 | Product product = productRepository.findById(productId) 61 | .orElseThrow(() -> new NotFoundException("Produto não encontrado.")); 62 | 63 | productRepository.delete(product); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/application/MyUserController.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.application; 2 | 3 | import com.ecommercebd.exception.NotFoundException; 4 | import com.ecommercebd.mapper.Mapper; 5 | import com.ecommercebd.security.IsClientOrAdmin; 6 | import com.ecommercebd.user.domain.Role; 7 | import com.ecommercebd.user.domain.User; 8 | import com.ecommercebd.user.domain.UserRepository; 9 | import lombok.RequiredArgsConstructor; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 12 | import org.springframework.security.core.userdetails.UserDetails; 13 | import org.springframework.security.crypto.password.PasswordEncoder; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import javax.validation.Valid; 17 | 18 | @RestController 19 | @RequiredArgsConstructor 20 | public class MyUserController { 21 | 22 | private final Mapper mapper; 23 | private final UserRepository userRepository; 24 | private final PasswordEncoder passwordEncoder; 25 | 26 | @IsClientOrAdmin 27 | @GetMapping("user/me") 28 | UserResponse profile(@AuthenticationPrincipal UserDetails userDetails) { 29 | return userRepository.findByEmail(userDetails.getUsername()) 30 | .map(p -> mapper.map(p, UserResponse.class)) 31 | .orElseThrow(() -> new NotFoundException("Usuário não encontrado.")); 32 | } 33 | 34 | @IsClientOrAdmin 35 | @PutMapping("user/update-password") 36 | @ResponseStatus(HttpStatus.NO_CONTENT) 37 | void updatePassword(@AuthenticationPrincipal UserDetails userDetails, @RequestBody UpdateUserPasswordRequest request) { 38 | User user = userRepository.findByEmail(userDetails.getUsername()) 39 | .orElseThrow(() -> new NotFoundException("Usuário não encontrado.")); 40 | user.setPassword(passwordEncoder.encode(request.getPassword())); 41 | userRepository.save(user); 42 | } 43 | 44 | @PostMapping("user") 45 | @ResponseStatus(HttpStatus.CREATED) 46 | UserResponse create(@RequestBody @Valid NewPublicUserRequest request){ 47 | User user = mapper.map(request, User.class); 48 | user.setRole(Role.CLIENT); 49 | user.setPassword(passwordEncoder.encode(request.getPassword())); 50 | user = this.userRepository.save(user); 51 | 52 | return this.mapper.map(user, UserResponse.class); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.2 9 | 10 | 11 | com.ecommerce-bd 12 | demo 13 | 0.0.1-SNAPSHOT 14 | ecommerce-bd 15 | Project for sale of data bases 16 | 17 | 18 | 17 19 | 3.0.0 20 | 8.0.28 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-data-jpa 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-security 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-validation 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-devtools 43 | runtime 44 | true 45 | 46 | 47 | 48 | mysql 49 | mysql-connector-java 50 | ${mysqlconnector.version} 51 | 52 | 53 | org.modelmapper 54 | modelmapper 55 | ${modelmapper.version} 56 | 57 | 58 | org.projectlombok 59 | lombok 60 | true 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-test 67 | test 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.springframework.boot 76 | spring-boot-maven-plugin 77 | 78 | 79 | 80 | org.projectlombok 81 | lombok 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/application/MyOrderController.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.application; 2 | 3 | import com.ecommercebd.exception.NotFoundException; 4 | import com.ecommercebd.mapper.Mapper; 5 | import com.ecommercebd.order.domain.Order; 6 | import com.ecommercebd.order.domain.OrderRepository; 7 | import com.ecommercebd.plan.application.BusinessException; 8 | import com.ecommercebd.plan.domain.Plan; 9 | import com.ecommercebd.plan.domain.PlanRepository; 10 | import com.ecommercebd.security.IsClientOrAdmin; 11 | import com.ecommercebd.user.domain.User; 12 | import com.ecommercebd.user.domain.UserRepository; 13 | import lombok.RequiredArgsConstructor; 14 | import org.springframework.http.HttpStatus; 15 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 16 | import org.springframework.security.core.userdetails.UserDetails; 17 | import org.springframework.web.bind.annotation.*; 18 | 19 | import javax.validation.Valid; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | @RestController 24 | @RequiredArgsConstructor 25 | @IsClientOrAdmin 26 | public class MyOrderController { 27 | private final Mapper mapper; 28 | private final OrderRepository orderRepository; 29 | private final UserRepository userRepository; 30 | private final PlanRepository planRepository; 31 | 32 | @GetMapping("{orderId}") 33 | OrderResponse findById(@PathVariable Long orderId, @AuthenticationPrincipal UserDetails userDetails){ 34 | return orderRepository.findByIdAndCustomerEmail(orderId, userDetails.getUsername()) 35 | .map(p -> mapper.map(p, OrderResponse.class)) 36 | .orElseThrow(() -> new NotFoundException("Pedido não encontrado.")); 37 | } 38 | 39 | @GetMapping("/{orders}") 40 | List findAll(@AuthenticationPrincipal UserDetails userDetails){ 41 | return orderRepository.findAllByCustomerEmail(userDetails.getUsername()) 42 | .stream() 43 | .map(p -> mapper.map(p, OrderResponse.class)).toList(); 44 | } 45 | 46 | @PostMapping 47 | @ResponseStatus(HttpStatus.CREATED) 48 | OrderResponse create(@RequestBody @Valid NewMyOrderRequest request, @AuthenticationPrincipal UserDetails userDetails) { 49 | Order order = mapper.map(request, Order.class); 50 | 51 | User user = userRepository.findByEmail(userDetails.getUsername()) 52 | .orElseThrow(() -> new BusinessException(String.format("Usuário não encontrado"))); 53 | 54 | List plans = new ArrayList<>(); 55 | for (Plan plan : order.getPlans()) { 56 | Plan planFound = planRepository.findById(plan.getId()) 57 | .orElseThrow(() -> new BusinessException(String.format("Plano não encontrado", plan.getId()))); 58 | 59 | plans.add(planFound); 60 | } 61 | 62 | order.setCustomer(user); 63 | order.setPlans(plans); 64 | 65 | orderRepository.save(order); 66 | return this.mapper.map(order, OrderResponse.class); 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/user/application/UserController.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.user.application; 2 | 3 | 4 | import com.ecommercebd.exception.NotFoundException; 5 | import com.ecommercebd.mapper.Mapper; 6 | import com.ecommercebd.security.IsAdmin; 7 | import com.ecommercebd.user.domain.User; 8 | import com.ecommercebd.user.domain.UserRepository; 9 | import lombok.RequiredArgsConstructor; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.security.crypto.password.PasswordEncoder; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PathVariable; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.PutMapping; 17 | import org.springframework.web.bind.annotation.RequestBody; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.bind.annotation.ResponseStatus; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | import javax.validation.Valid; 23 | import java.util.List; 24 | 25 | @RestController 26 | @RequestMapping("/users") 27 | @RequiredArgsConstructor 28 | @IsAdmin 29 | class UserController { 30 | 31 | private final Mapper mapper; 32 | private final UserRepository userRepository; 33 | private final PasswordEncoder passwordEncoder; 34 | 35 | @GetMapping 36 | List findAll(){ 37 | return userRepository.findAll() 38 | .stream() 39 | .map(p -> mapper.map(p, UserResponse.class)).toList(); 40 | } 41 | 42 | @GetMapping("{userId}") 43 | UserResponse findById(@PathVariable Long userId){ 44 | return userRepository.findById(userId) 45 | .map(p -> mapper.map(p, UserResponse.class)) 46 | .orElseThrow(() -> new NotFoundException("Usuário não encontrado.")); 47 | } 48 | 49 | @PostMapping 50 | @ResponseStatus(HttpStatus.CREATED) 51 | UserResponse create(@RequestBody @Valid NewUserRequest newUserRequest){ 52 | User user = mapper.map(newUserRequest, User.class); 53 | user.setPassword(passwordEncoder.encode(newUserRequest.getPassword())); 54 | user = this.userRepository.save(user); 55 | 56 | return this.mapper.map(user, UserResponse.class); 57 | } 58 | 59 | @PutMapping("{userId}") 60 | UserResponse update(@PathVariable Long userId, 61 | @RequestBody @Valid NewUserRequest newUserRequest){ 62 | final User user = userRepository.findById(userId) 63 | .orElseThrow(() -> new NotFoundException("Usuário não encontrado")); 64 | 65 | this.mapper.map(newUserRequest, user); 66 | this.userRepository.save(user); 67 | 68 | return this.mapper.map(user, UserResponse.class); 69 | } 70 | 71 | @DeleteMapping("{userId}") 72 | void delete(@PathVariable Long userId){ 73 | User user = userRepository.findById(userId) 74 | .orElseThrow(() -> new NotFoundException("Usuário não encontrado")); 75 | userRepository.delete(user); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/order/application/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.order.application; 2 | 3 | import com.ecommercebd.exception.NotFoundException; 4 | import com.ecommercebd.mapper.Mapper; 5 | import com.ecommercebd.order.domain.Order; 6 | import com.ecommercebd.order.domain.OrderRepository; 7 | import com.ecommercebd.plan.application.BusinessException; 8 | import com.ecommercebd.plan.domain.Plan; 9 | import com.ecommercebd.plan.domain.PlanRepository; 10 | import com.ecommercebd.security.IsAdmin; 11 | import com.ecommercebd.user.domain.User; 12 | import com.ecommercebd.user.domain.UserRepository; 13 | import lombok.AllArgsConstructor; 14 | import org.springframework.http.HttpStatus; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import javax.validation.Valid; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | @RestController 22 | @AllArgsConstructor 23 | @RequestMapping("/orders") 24 | @IsAdmin 25 | class OrderController { 26 | 27 | private final Mapper mapper; 28 | private final OrderRepository orderRepository; 29 | private final UserRepository userRepository; 30 | private final PlanRepository planRepository; 31 | 32 | @GetMapping 33 | List findAll(){ 34 | return orderRepository.findAll() 35 | .stream() 36 | .map(p -> mapper.map(p, OrderResponse.class)).toList(); 37 | } 38 | 39 | @GetMapping("{orderId}") 40 | OrderResponse findById(@PathVariable Long orderId){ 41 | return orderRepository.findById(orderId) 42 | .map(p -> mapper.map(p, OrderResponse.class)) 43 | .orElseThrow(() -> new NotFoundException("Pedido não encontrado.")); 44 | } 45 | 46 | @PostMapping 47 | @ResponseStatus(HttpStatus.CREATED) 48 | OrderResponse create(@RequestBody @Valid NewOrderRequest newOrderRequest){ 49 | Order order = mapper.map(newOrderRequest, Order.class); 50 | 51 | User customer = order.getCustomer(); 52 | Long customerId = customer.getId(); 53 | 54 | customer = userRepository.findById(customerId) 55 | .orElseThrow(() -> new BusinessException(String.format("Usuário não encontrado", customerId))); 56 | 57 | 58 | List plans = new ArrayList<>(); 59 | for (Plan plan : order.getPlans()) { 60 | Plan planFound = planRepository.findById(plan.getId()) 61 | .orElseThrow(() -> new BusinessException(String.format("Plano não encontrado", plan.getId()))); 62 | 63 | plans.add(planFound); 64 | } 65 | 66 | 67 | order.setCustomer(customer); 68 | order.setPlans(plans); 69 | 70 | orderRepository.save(order); 71 | return this.mapper.map(order, OrderResponse.class); 72 | 73 | } 74 | 75 | @PutMapping("/{orderId}") 76 | OrderResponse update(@PathVariable Long orderId, 77 | @RequestBody @Valid NewOrderRequest newOrderRequest){ 78 | final Order order = orderRepository.findById(orderId) 79 | .orElseThrow(() -> new NotFoundException("Pedido não localizado.")); 80 | 81 | this.mapper.map(newOrderRequest, order); 82 | this.orderRepository.save(order); 83 | return this.mapper.map(order, OrderResponse.class); 84 | } 85 | 86 | 87 | @DeleteMapping("{orderId}") 88 | void delete(@PathVariable Long orderId){ 89 | Order order = orderRepository.findById(orderId) 90 | .orElseThrow(() -> new NotFoundException("Pedido não localizado")); 91 | orderRepository.delete(order); 92 | } 93 | 94 | } -------------------------------------------------------------------------------- /src/main/java/com/ecommercebd/plan/application/PlanController.java: -------------------------------------------------------------------------------- 1 | package com.ecommercebd.plan.application; 2 | 3 | import com.ecommercebd.exception.NotFoundException; 4 | import com.ecommercebd.mapper.Mapper; 5 | import com.ecommercebd.plan.domain.Plan; 6 | import com.ecommercebd.plan.domain.PlanRepository; 7 | import com.ecommercebd.product.domain.Product; 8 | import com.ecommercebd.product.domain.ProductRepository; 9 | import com.ecommercebd.security.IsAdmin; 10 | import lombok.AllArgsConstructor; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PathVariable; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.PutMapping; 17 | import org.springframework.web.bind.annotation.RequestBody; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.bind.annotation.ResponseStatus; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | import javax.validation.Valid; 23 | import java.util.List; 24 | 25 | 26 | @RestController 27 | @AllArgsConstructor 28 | @RequestMapping("/plans") 29 | class PlanController { 30 | 31 | private final PlanRepository planRepository; 32 | private final Mapper mapper; 33 | private final ProductRepository productRepository; 34 | 35 | @GetMapping 36 | List findAll() { 37 | return planRepository.findAll() 38 | .stream() 39 | .map(p -> mapper.map(p, PlanResponse.class)).toList(); 40 | } 41 | 42 | @GetMapping("{planId}") 43 | PlanResponse findById(@PathVariable Long planId) { 44 | return planRepository.findById(planId) 45 | .map(p -> mapper.map(p, PlanResponse.class)) 46 | .orElseThrow(() -> new NotFoundException("Plano não encontrado.")); 47 | } 48 | 49 | @PostMapping 50 | @ResponseStatus(HttpStatus.CREATED) 51 | //TODO alterar esse método create para retornar PlanResponse 52 | //TODO Ta dando 500 ao cadastrar duas vezes o mesmo registro - tratar 53 | @IsAdmin 54 | PlanResponse create(@RequestBody @Valid NewPlanRequest newPlanRequest) { 55 | Plan plan = mapper.map(newPlanRequest, Plan.class); 56 | 57 | Product product = plan.getProduct(); 58 | Long productId = product.getId(); 59 | 60 | product = productRepository.findById(productId) 61 | .orElseThrow(() -> new BusinessException(String.format("Produto do plano %s não encontrado", productId))); 62 | 63 | plan.setProduct(product); 64 | planRepository.save(plan); 65 | return this.mapper.map(plan, PlanResponse.class); 66 | } 67 | 68 | @PutMapping("{planId}") 69 | @IsAdmin 70 | PlanResponse update(@PathVariable Long planId, 71 | @RequestBody @Valid NewPlanRequest newPlanRequest) { 72 | final Plan plan = planRepository.findById(planId) 73 | .orElseThrow(() -> new NotFoundException("Plano não encontrado.")); 74 | 75 | this.mapper.map(newPlanRequest, plan); 76 | this.planRepository.save(plan); 77 | 78 | return this.mapper.map(plan, PlanResponse.class); 79 | } 80 | 81 | @DeleteMapping("{planId}") 82 | @IsAdmin 83 | void delete(@PathVariable Long planId) { 84 | Plan plan = planRepository.findById(planId) 85 | .orElseThrow(() -> new NotFoundException("Plano não encontrado.")); 86 | 87 | planRepository.delete(plan); 88 | } 89 | } -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /docs/openAPI.yml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | 3 | info: 4 | title: LoveLace 5 | version: '1.0' 6 | description: >- 7 | REST API da plataforma de ecommerce de banco de dados 8 | contact: 9 | email: contato@lovelace.com 10 | name: LoveLace 11 | url: 'https://lovelace.com' 12 | 13 | servers: 14 | - description: Ambiente local de desenvolvimento 15 | url: 'http://localhost:8080' 16 | - description: Ambiente de produção 17 | url: 'https://api.lovelace.com' 18 | 19 | components: 20 | schemas: 21 | Page: 22 | type: object 23 | required: 24 | - number 25 | - size 26 | - totalPages 27 | - totalElements 28 | - content 29 | properties: 30 | number: 31 | type: integer 32 | format: int32 33 | example: 2 34 | size: 35 | type: number 36 | format: int32 37 | example: 9 38 | totalPages: 39 | type: integer 40 | format: int32 41 | example: 15 42 | totalElements: 43 | type: number 44 | format: int32 45 | example: 442 46 | ProblemObject: 47 | type: object 48 | required: 49 | - type 50 | - userMessage 51 | properties: 52 | name: 53 | type: string 54 | example: amount 55 | userMessage: 56 | type: string 57 | example: O valor é obrigatório 58 | title: ProblemObject 59 | Problem: 60 | title: Problem 61 | type: object 62 | required: 63 | - status 64 | - timestamp 65 | - type 66 | - title 67 | - detail 68 | description: > 69 | Representa um problema na comunicação com a API. 70 | Este modelo de representação é baseado na RFC 7807 (Problem Details for HTTP APIs) 71 | properties: 72 | status: 73 | type: integer 74 | format: int32 75 | example: 400 76 | timestamp: 77 | type: string 78 | format: date-time 79 | example: '2020-12-01T18:09:02Z' 80 | type: 81 | type: string 82 | example: 'https://lovelace.com/dados-invalidos' 83 | title: 84 | type: string 85 | example: Dados inválidos 86 | detail: 87 | type: string 88 | example: Um ou mais campos estão inválidos. Faça o preenchimento correto e tente novamente. 89 | # userMessage: 90 | # type: string 91 | # example: Um ou mais campos estão inválidos. Faça o preenchimento correto e tente novamente. 92 | objects: 93 | type: array 94 | description: Lista de objetos ou campos que geraram o erro (opcional) 95 | items: 96 | $ref: '#/components/schemas/ProblemObject' 97 | ProductResponse: 98 | required: 99 | - id 100 | - name 101 | type: object 102 | properties: 103 | id: 104 | type: integer 105 | format: int64 106 | example: 1 107 | name: 108 | type: string 109 | example: 'Maria db' 110 | 111 | NewProductRequest: 112 | required: 113 | - name 114 | type: object 115 | properties: 116 | name: 117 | type: string 118 | example: 'Maria db' 119 | PlanId: 120 | required: 121 | - id 122 | type: object 123 | properties: 124 | id: 125 | type: integer 126 | format: int64 127 | example: 1 128 | 129 | UpdateProductRequest: 130 | required: 131 | - name 132 | type: object 133 | properties: 134 | name: 135 | type: string 136 | example: 'Maria db' 137 | 138 | UpdateOrderRequest: 139 | required: 140 | - subtotal 141 | - customer 142 | type: object 143 | properties: 144 | subtotal: 145 | type: number 146 | format: double 147 | example: 10.8 148 | customer: 149 | type: integer 150 | format: int64 151 | example: 1 152 | 153 | NewOrderRequest: 154 | required: 155 | - subtotal 156 | - customer 157 | - plans 158 | type: object 159 | properties: 160 | subtotal: 161 | type: number 162 | format: double 163 | example: 250.40 164 | customer: 165 | type: integer 166 | format: int64 167 | example: 1 168 | plans: 169 | type: array 170 | items: 171 | $ref: '#/components/schemas/PlanId' 172 | 173 | OrderResponse: 174 | required: 175 | - id 176 | - subtotal 177 | - customer 178 | - plans 179 | type: object 180 | properties: 181 | id: 182 | type: integer 183 | format: int64 184 | example: 1 185 | subtotal: 186 | type: number 187 | format: double 188 | example: 10.8 189 | customer: 190 | $ref: '#/components/schemas/CustomerId' 191 | plans: 192 | type: array 193 | items: 194 | $ref: '#/components/schemas/PlanId' 195 | 196 | CustomerId: 197 | required: 198 | - id 199 | type: object 200 | properties: 201 | id: 202 | type: integer 203 | format: int64 204 | example: 1 205 | 206 | UserResponse: 207 | required: 208 | - id 209 | - email 210 | - password 211 | - phone 212 | - cpf 213 | - role 214 | type: object 215 | properties: 216 | id: 217 | type: integer 218 | format: int64 219 | example: 1 220 | email: 221 | type: string 222 | example: 'Maria db' 223 | password: 224 | type: string 225 | example: 'Test#01*' 226 | phone: 227 | type: string 228 | example: '(61)3300-5564' 229 | cpf: 230 | type: string 231 | example: '000.001.005-81' 232 | role: 233 | type: string 234 | enum: [ADMIN, CLIENT] 235 | example: 'CLIENT' 236 | 237 | NewUserRequest: 238 | required: 239 | - id 240 | - email 241 | - password 242 | - phone 243 | - cpf 244 | - role 245 | type: object 246 | properties: 247 | id: 248 | type: integer 249 | format: int64 250 | example: 1 251 | email: 252 | type: string 253 | example: 'Maria db' 254 | password: 255 | type: string 256 | example: 'Test#01*' 257 | phone: 258 | type: string 259 | example: '(61)3300-5564' 260 | cpf: 261 | type: string 262 | example: '000.001.005-81' 263 | role: 264 | type: string 265 | enum: [ADMIN, CLIENT] 266 | example: 'CLIENT' 267 | 268 | UpdateUserRequest: 269 | required: 270 | - id 271 | - email 272 | - password 273 | - phone 274 | - cpf 275 | - role 276 | type: object 277 | properties: 278 | id: 279 | type: integer 280 | format: int64 281 | example: 1 282 | email: 283 | type: string 284 | example: 'Maria db' 285 | password: 286 | type: string 287 | example: 'Test#01*' 288 | phone: 289 | type: string 290 | example: '(61)3300-5564' 291 | cpf: 292 | type: string 293 | example: '000.001.005-81' 294 | role: 295 | type: string 296 | enum: [ADMIN, CLIENT] 297 | example: 'ADMIN' 298 | 299 | PlanResponse: 300 | required: 301 | - id 302 | - price 303 | - name 304 | - description 305 | - characteristic 306 | - storage 307 | - limitOfConnections 308 | - limitOfUsers 309 | - product 310 | type: object 311 | properties: 312 | id: 313 | type: integer 314 | format: int64 315 | example: 1 316 | price: 317 | type: number 318 | format: double 319 | example: 150.8 320 | name: 321 | type: string 322 | example: 'Basico' 323 | description: 324 | type: string 325 | example: 'Plano Básico - Sem servidor' 326 | characteristic: 327 | type: string 328 | example: 'Ideal para uso em aplicativos sem servidor e com tráfego baixo ou variável.' 329 | storage: 330 | type: integer 331 | format: int64 332 | example: 1 333 | limitOfConnections: 334 | type: integer 335 | format: int64 336 | example: 10 337 | limitOfUsers: 338 | type: integer 339 | format: int64 340 | example: 5 341 | product: 342 | type: integer 343 | format: int64 344 | example: 1 345 | 346 | NewPlanRequest: 347 | required: 348 | - id 349 | - price 350 | - name 351 | - description 352 | - characteristic 353 | - storage 354 | - limitOfConnections 355 | - limitOfUsers 356 | - product 357 | type: object 358 | properties: 359 | id: 360 | type: integer 361 | format: int64 362 | example: 1 363 | price: 364 | type: number 365 | format: double 366 | example: 150.8 367 | name: 368 | type: string 369 | example: 'Basico' 370 | description: 371 | type: string 372 | example: 'Plano Básico - Sem servidor' 373 | characteristic: 374 | type: string 375 | example: 'Ideal para uso em aplicativos sem servidor e com tráfego baixo ou variável.' 376 | storage: 377 | type: integer 378 | format: int64 379 | example: 1 380 | limitOfConnections: 381 | type: integer 382 | format: int64 383 | example: 10 384 | limitOfUsers: 385 | type: integer 386 | format: int64 387 | example: 5 388 | product: 389 | type: integer 390 | format: int64 391 | example: 1 392 | 393 | UpdatePlanRequest: 394 | required: 395 | - id 396 | - price 397 | - name 398 | - description 399 | - characteristic 400 | - storage 401 | - limitOfConnections 402 | - limitOfUsers 403 | - product 404 | type: object 405 | properties: 406 | id: 407 | type: integer 408 | format: int64 409 | example: 1 410 | price: 411 | type: number 412 | format: double 413 | example: 150.8 414 | name: 415 | type: string 416 | example: 'Basico' 417 | description: 418 | type: string 419 | example: 'Plano Básico - Sem servidor' 420 | characteristic: 421 | type: string 422 | example: 'Ideal para uso em aplicativos sem servidor e com tráfego baixo ou variável.' 423 | storage: 424 | type: integer 425 | format: int64 426 | example: 1 427 | limitOfConnections: 428 | type: integer 429 | format: int64 430 | example: 10 431 | limitOfUsers: 432 | type: integer 433 | format: int64 434 | example: 5 435 | product: 436 | type: integer 437 | format: int64 438 | example: 1 439 | 440 | 441 | 442 | responses: 443 | NotFound: 444 | description: Recurso não encontrado 445 | content: 446 | application/json: 447 | schema: 448 | $ref: '#/components/schemas/Problem' 449 | BadRequest: 450 | description: Requisição inválida 451 | content: 452 | application/json: 453 | schema: 454 | $ref: '#/components/schemas/Problem' 455 | 456 | paths: 457 | /products: 458 | get: 459 | operationId: getProducts 460 | summary: Listagem de Produtos 461 | tags: 462 | - Products 463 | responses: 464 | '200': 465 | description: OK 466 | content: 467 | application/json: 468 | schema: 469 | type: array 470 | items: 471 | $ref: '#/components/schemas/ProductResponse' 472 | post: 473 | operationId: postProducts 474 | summary: Cadastro de Produtos 475 | tags: 476 | - Products 477 | requestBody: 478 | content: 479 | application/json: 480 | schema: 481 | $ref: '#/components/schemas/NewProductRequest' 482 | responses: 483 | '201': 484 | description: Produto criado 485 | content: 486 | application/json: 487 | schema: 488 | $ref: '#/components/schemas/ProductResponse' 489 | '400': 490 | $ref: '#/components/responses/BadRequest' 491 | 492 | /products/{productId}: 493 | parameters: 494 | - schema: 495 | type: integer 496 | format: int64 497 | name: productId 498 | in: path 499 | required: true 500 | get: 501 | operationId: getProduct 502 | summary: Busca um Produto 503 | tags: 504 | - Products 505 | responses: 506 | '200': 507 | description: OK 508 | content: 509 | application/json: 510 | schema: 511 | $ref: '#/components/schemas/ProductResponse' 512 | '404': 513 | $ref: '#/components/responses/NotFound' 514 | put: 515 | operationId: putProducts 516 | summary: Atualização de Produtos 517 | tags: 518 | - Products 519 | requestBody: 520 | content: 521 | application/json: 522 | schema: 523 | $ref: '#/components/schemas/UpdateProductRequest' 524 | responses: 525 | '200': 526 | description: Produto atualizado 527 | content: 528 | application/json: 529 | schema: 530 | $ref: '#/components/schemas/ProductResponse' 531 | '400': 532 | $ref: '#/components/responses/BadRequest' 533 | delete: 534 | operationId: deleteProduct 535 | summary: Deleta um Produto 536 | tags: 537 | - Products 538 | responses: 539 | '204': 540 | description: Produto deletado 541 | '404': 542 | $ref: '#/components/responses/NotFound' 543 | 544 | /orders: 545 | get: 546 | operationId: getOrders 547 | summary: Listagem de Pedidos 548 | tags: 549 | - Orders 550 | responses: 551 | '200': 552 | description: OK 553 | content: 554 | application/json: 555 | schema: 556 | type: array 557 | items: 558 | $ref: '#/components/schemas/OrderResponse' 559 | 560 | post: 561 | operationId: postOrders 562 | summary: Cadastro de Pedidos 563 | tags: 564 | - Orders 565 | requestBody: 566 | content: 567 | application/json: 568 | schema: 569 | $ref: '#/components/schemas/NewOrderRequest' 570 | responses: 571 | '201': 572 | description: Pedido criado 573 | content: 574 | application/json: 575 | schema: 576 | $ref: '#/components/schemas/OrderResponse' 577 | '400': 578 | $ref: '#/components/responses/BadRequest' 579 | 580 | /orders/{orderId}: 581 | parameters: 582 | - schema: 583 | type: integer 584 | format: int64 585 | name: orderId 586 | in: path 587 | required: true 588 | get: 589 | operationId: getOrder 590 | summary: Busca um Pedido 591 | tags: 592 | - Orders 593 | responses: 594 | '200': 595 | description: OK 596 | content: 597 | application/json: 598 | schema: 599 | $ref: '#/components/schemas/OrderResponse' 600 | '404': 601 | $ref: '#/components/responses/NotFound' 602 | 603 | put: 604 | operationId: putOrders 605 | summary: Atualização de Pedido 606 | tags: 607 | - Orders 608 | requestBody: 609 | content: 610 | application/json: 611 | schema: 612 | $ref: '#/components/schemas/UpdateOrderRequest' 613 | responses: 614 | '200': 615 | description: Pedido atualizado 616 | content: 617 | application/json: 618 | schema: 619 | $ref: '#/components/schemas/OrderResponse' 620 | '400': 621 | $ref: '#/components/responses/BadRequest' 622 | 623 | delete: 624 | operationId: deleteOrder 625 | summary: Deleta um Pedido 626 | tags: 627 | - Orders 628 | responses: 629 | '204': 630 | description: Pedido deletado 631 | '404': 632 | $ref: '#/components/responses/NotFound' 633 | 634 | /user: 635 | get: 636 | operationId: getUsers 637 | summary: Listagem de Usuarios 638 | tags: 639 | - Users 640 | responses: 641 | '200': 642 | description: OK 643 | content: 644 | application/json: 645 | schema: 646 | type: array 647 | items: 648 | $ref: '#/components/schemas/UserResponse' 649 | post: 650 | operationId: postUsers 651 | summary: Cadastro de Usuarios 652 | tags: 653 | - Users 654 | requestBody: 655 | content: 656 | application/json: 657 | schema: 658 | $ref: '#/components/schemas/NewUserRequest' 659 | responses: 660 | '201': 661 | description: Usuario criado 662 | content: 663 | application/json: 664 | schema: 665 | $ref: '#/components/schemas/UserResponse' 666 | '400': 667 | $ref: '#/components/responses/BadRequest' 668 | 669 | /user/{userId}: 670 | parameters: 671 | - schema: 672 | type: integer 673 | format: int64 674 | name: userId 675 | in: path 676 | required: true 677 | get: 678 | operationId: getUser 679 | summary: Busca um Usuario 680 | tags: 681 | - Users 682 | responses: 683 | '200': 684 | description: OK 685 | content: 686 | application/json: 687 | schema: 688 | $ref: '#/components/schemas/UserResponse' 689 | '404': 690 | $ref: '#/components/responses/NotFound' 691 | 692 | put: 693 | operationId: putUsers 694 | summary: Atualização de Usuario 695 | tags: 696 | - Users 697 | requestBody: 698 | content: 699 | application/json: 700 | schema: 701 | $ref: '#/components/schemas/UpdateUserRequest' 702 | responses: 703 | '200': 704 | description: Usuario atualizado 705 | content: 706 | application/json: 707 | schema: 708 | $ref: '#/components/schemas/UserResponse' 709 | '400': 710 | $ref: '#/components/responses/BadRequest' 711 | 712 | delete: 713 | operationId: deleteUser 714 | summary: Deleta um usuario 715 | tags: 716 | - Users 717 | responses: 718 | '204': 719 | description: Usuario deletado 720 | '404': 721 | $ref: '#/components/responses/NotFound' 722 | 723 | /plan: 724 | get: 725 | operationId: getPlans 726 | summary: Listagem de Planos 727 | tags: 728 | - Plans 729 | responses: 730 | '200': 731 | description: OK 732 | content: 733 | application/json: 734 | schema: 735 | type: array 736 | items: 737 | $ref: '#/components/schemas/PlanResponse' 738 | post: 739 | operationId: postPlans 740 | summary: Cadastro de Planos 741 | tags: 742 | - Plans 743 | requestBody: 744 | content: 745 | application/json: 746 | schema: 747 | $ref: '#/components/schemas/NewPlanRequest' 748 | responses: 749 | '201': 750 | description: Plano criado 751 | content: 752 | application/json: 753 | schema: 754 | $ref: '#/components/schemas/PlanResponse' 755 | '400': 756 | $ref: '#/components/responses/BadRequest' 757 | 758 | /plan/{planId}: 759 | parameters: 760 | - schema: 761 | type: integer 762 | format: int64 763 | name: planId 764 | in: path 765 | required: true 766 | get: 767 | operationId: getPlan 768 | summary: Busca um Plano 769 | tags: 770 | - Plans 771 | responses: 772 | '200': 773 | description: OK 774 | content: 775 | application/json: 776 | schema: 777 | $ref: '#/components/schemas/PlanResponse' 778 | '404': 779 | $ref: '#/components/responses/NotFound' 780 | 781 | put: 782 | operationId: putPlans 783 | summary: Atualização de Plano 784 | tags: 785 | - Plans 786 | requestBody: 787 | content: 788 | application/json: 789 | schema: 790 | $ref: '#/components/schemas/UpdatePlanRequest' 791 | responses: 792 | '200': 793 | description: Plano atualizado 794 | content: 795 | application/json: 796 | schema: 797 | $ref: '#/components/schemas/PlanResponse' 798 | '400': 799 | $ref: '#/components/responses/BadRequest' 800 | 801 | delete: 802 | operationId: deletePlan 803 | summary: Deleta um Plano 804 | tags: 805 | - Plans 806 | responses: 807 | '204': 808 | description: Plano deletado 809 | '404': 810 | $ref: '#/components/responses/NotFound' 811 | 812 | 813 | tags: 814 | - name: Products 815 | description: Produtos 816 | - name: Orders 817 | description: Pedidos 818 | - name: Plans 819 | description: Planos 820 | - name: Users 821 | description: Usuarios -------------------------------------------------------------------------------- /docs/useCaseDiagram.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/classDiagram.svg: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------