diff --git a/src/main/java/com/marcomnrq/ecommerce/EcommerceApplication.java b/src/main/java/com/marcomnrq/ecommerce/EcommerceApplication.java index 8ee7800..a34295c 100644 --- a/src/main/java/com/marcomnrq/ecommerce/EcommerceApplication.java +++ b/src/main/java/com/marcomnrq/ecommerce/EcommerceApplication.java @@ -10,12 +10,12 @@ @SpringBootApplication public class EcommerceApplication { - public static void main(String[] args) { - SpringApplication.run(EcommerceApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(EcommerceApplication.class, args); + } - @Bean - public ModelMapper modelMapper() { - return new ModelMapper(); - } + @Bean + public ModelMapper modelMapper() { + return new ModelMapper(); + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/configuration/OpenApiConfiguration.java b/src/main/java/com/marcomnrq/ecommerce/configuration/OpenApiConfiguration.java index 69f5c7f..d0b0768 100644 --- a/src/main/java/com/marcomnrq/ecommerce/configuration/OpenApiConfiguration.java +++ b/src/main/java/com/marcomnrq/ecommerce/configuration/OpenApiConfiguration.java @@ -8,17 +8,19 @@ @Configuration public class OpenApiConfiguration { - @Bean(name = "eCommerceOpenApi") - public OpenAPI eCommerceOpenApi() { - return new OpenAPI() - .info( - new Info() - .title("MP eCommerce Application API") - .description("API implemented with Spring Boot RESTful service and documented using springdoc-openapi and OpenAPI 3.0") - .version("1.0") - .contact(new Contact() - .name("Marco Antonio Manrique Acha") - .email("manriqueacham@gmail.com") - .url("https://blucode.solutions"))); - } + @Bean(name = "eCommerceOpenApi") + public OpenAPI eCommerceOpenApi() { + return new OpenAPI() + .info( + new Info() + .title("MP eCommerce Application API") + .description( + "API implemented with Spring Boot RESTful service and documented using springdoc-openapi and OpenAPI 3.0") + .version("1.0") + .contact( + new Contact() + .name("Marco Antonio Manrique Acha") + .email("manriqueacham@gmail.com") + .url("https://blucode.solutions"))); + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/configuration/SecurityConfiguration.java b/src/main/java/com/marcomnrq/ecommerce/configuration/SecurityConfiguration.java index fff1a88..56083e9 100644 --- a/src/main/java/com/marcomnrq/ecommerce/configuration/SecurityConfiguration.java +++ b/src/main/java/com/marcomnrq/ecommerce/configuration/SecurityConfiguration.java @@ -21,39 +21,42 @@ @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfiguration extends WebSecurityConfigurerAdapter { - private final UserDetailsService userDetailsService; - - private final JwtAuthenticationFilter jwtAuthenticationFilter; - - @Override - @Bean(BeanIds.AUTHENTICATION_MANAGER) - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } - - @Override - public void configure(HttpSecurity httpSecurity) throws Exception { - httpSecurity - .cors().disable() - .csrf().disable() - .authorizeRequests() - - .antMatchers("/**") - .permitAll() - - .anyRequest() - .authenticated(); - httpSecurity - .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); - } - - @Autowired - public void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { - authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); - } - - @Bean - PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } + private final UserDetailsService userDetailsService; + + private final JwtAuthenticationFilter jwtAuthenticationFilter; + + @Override + @Bean(BeanIds.AUTHENTICATION_MANAGER) + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + @Override + public void configure(HttpSecurity httpSecurity) throws Exception { + httpSecurity + .cors() + .disable() + .csrf() + .disable() + .authorizeRequests() + .antMatchers("/**") + .permitAll() + .anyRequest() + .authenticated(); + httpSecurity.addFilterBefore( + jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) + throws Exception { + authenticationManagerBuilder + .userDetailsService(userDetailsService) + .passwordEncoder(passwordEncoder()); + } + + @Bean + PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/controller/AuthenticationController.java b/src/main/java/com/marcomnrq/ecommerce/controller/AuthenticationController.java index de2bd36..4617915 100644 --- a/src/main/java/com/marcomnrq/ecommerce/controller/AuthenticationController.java +++ b/src/main/java/com/marcomnrq/ecommerce/controller/AuthenticationController.java @@ -5,14 +5,12 @@ import com.marcomnrq.ecommerce.resource.authentication.RefreshTokenRequest; import com.marcomnrq.ecommerce.resource.authentication.RegistrationRequest; import com.marcomnrq.ecommerce.service.AuthenticationService; +import javax.validation.Valid; import lombok.AllArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; -import java.security.Principal; - @RestController @AllArgsConstructor @RequestMapping("/api/authentication") diff --git a/src/main/java/com/marcomnrq/ecommerce/controller/CartController.java b/src/main/java/com/marcomnrq/ecommerce/controller/CartController.java index faeb4b9..e4ea01d 100644 --- a/src/main/java/com/marcomnrq/ecommerce/controller/CartController.java +++ b/src/main/java/com/marcomnrq/ecommerce/controller/CartController.java @@ -7,6 +7,4 @@ @RestController @AllArgsConstructor @RequestMapping("/api") -public class CartController { - -} +public class CartController {} diff --git a/src/main/java/com/marcomnrq/ecommerce/controller/OrderController.java b/src/main/java/com/marcomnrq/ecommerce/controller/OrderController.java index 433747f..1b904df 100644 --- a/src/main/java/com/marcomnrq/ecommerce/controller/OrderController.java +++ b/src/main/java/com/marcomnrq/ecommerce/controller/OrderController.java @@ -1,7 +1,6 @@ package com.marcomnrq.ecommerce.controller; import com.marcomnrq.ecommerce.resource.IpnResource; -import com.marcomnrq.ecommerce.resource.MercadopagoResource; import com.marcomnrq.ecommerce.service.OrderService; import lombok.AllArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/com/marcomnrq/ecommerce/controller/PaymentController.java b/src/main/java/com/marcomnrq/ecommerce/controller/PaymentController.java index 44c4053..49dbac8 100644 --- a/src/main/java/com/marcomnrq/ecommerce/controller/PaymentController.java +++ b/src/main/java/com/marcomnrq/ecommerce/controller/PaymentController.java @@ -3,14 +3,13 @@ import com.marcomnrq.ecommerce.domain.model.Payment; import com.marcomnrq.ecommerce.resource.MercadopagoResource; import com.marcomnrq.ecommerce.service.PaymentService; +import java.util.Map; import lombok.AllArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @AllArgsConstructor @RequestMapping("api/payments") diff --git a/src/main/java/com/marcomnrq/ecommerce/controller/ProductController.java b/src/main/java/com/marcomnrq/ecommerce/controller/ProductController.java index 37f8f18..da8a7f7 100644 --- a/src/main/java/com/marcomnrq/ecommerce/controller/ProductController.java +++ b/src/main/java/com/marcomnrq/ecommerce/controller/ProductController.java @@ -3,6 +3,9 @@ import com.marcomnrq.ecommerce.domain.model.Product; import com.marcomnrq.ecommerce.resource.ProductResource; import com.marcomnrq.ecommerce.service.ProductService; +import java.util.List; +import java.util.stream.Collectors; +import javax.validation.Valid; import lombok.AllArgsConstructor; import org.modelmapper.ModelMapper; import org.springframework.data.domain.Page; @@ -11,10 +14,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; -import java.util.List; -import java.util.stream.Collectors; - @RestController @AllArgsConstructor @RequestMapping("/api") diff --git a/src/main/java/com/marcomnrq/ecommerce/controller/UserController.java b/src/main/java/com/marcomnrq/ecommerce/controller/UserController.java index 7eb8241..858ba7f 100644 --- a/src/main/java/com/marcomnrq/ecommerce/controller/UserController.java +++ b/src/main/java/com/marcomnrq/ecommerce/controller/UserController.java @@ -3,36 +3,36 @@ import com.marcomnrq.ecommerce.domain.model.User; import com.marcomnrq.ecommerce.resource.UserResource; import com.marcomnrq.ecommerce.service.UserService; +import java.security.Principal; +import javax.validation.Valid; import lombok.AllArgsConstructor; import org.modelmapper.ModelMapper; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; -import java.security.Principal; - @RestController @AllArgsConstructor @RequestMapping("api/users") public class UserController { - private final ModelMapper modelMapper; + private final ModelMapper modelMapper; - private final UserService userService; + private final UserService userService; - @GetMapping - public UserResource getUserByEmail(Principal principal) { - String email = principal.getName(); - return convertToResource(userService.getUserByEmail(email)); - } + @GetMapping + public UserResource getUserByEmail(Principal principal) { + String email = principal.getName(); + return convertToResource(userService.getUserByEmail(email)); + } - @PutMapping - public UserResource updateUser(@Valid @RequestBody UserResource userResource, Principal principal) { - String email = principal.getName(); - return convertToResource(userService.updateUser(email, userResource)); - } + @PutMapping + public UserResource updateUser( + @Valid @RequestBody UserResource userResource, Principal principal) { + String email = principal.getName(); + return convertToResource(userService.updateUser(email, userResource)); + } - // Model Mapper - private UserResource convertToResource(User entity) { - return modelMapper.map(entity, UserResource.class); - } + // Model Mapper + private UserResource convertToResource(User entity) { + return modelMapper.map(entity, UserResource.class); + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/controller/WebController.java b/src/main/java/com/marcomnrq/ecommerce/controller/WebController.java index 5d62bb2..2fbe9a7 100644 --- a/src/main/java/com/marcomnrq/ecommerce/controller/WebController.java +++ b/src/main/java/com/marcomnrq/ecommerce/controller/WebController.java @@ -6,12 +6,8 @@ @Controller public class WebController { - @GetMapping( { "/" - , "/carrito" - , "/ordenes" - , "/payment" - }) - public String index() { - return "index"; - } + @GetMapping({"/", "/carrito", "/ordenes", "/payment"}) + public String index() { + return "index"; + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/AuditModel.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/AuditModel.java index ce9623f..e7ed430 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/AuditModel.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/AuditModel.java @@ -1,15 +1,14 @@ package com.marcomnrq.ecommerce.domain.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.io.Serializable; +import java.util.Date; +import javax.persistence.*; import lombok.Data; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; - @Data @MappedSuperclass @EntityListeners(AuditingEntityListener.class) diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/Cart.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/Cart.java index 73fb81d..3ef0d9f 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/Cart.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/Cart.java @@ -1,12 +1,11 @@ package com.marcomnrq.ecommerce.domain.model; +import java.util.List; +import javax.persistence.*; import lombok.Data; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; -import javax.persistence.*; -import java.util.List; - @Data @Entity @Table(name = "carts") diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/CartItem.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/CartItem.java index 456ad9c..4f1ff9c 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/CartItem.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/CartItem.java @@ -1,8 +1,7 @@ package com.marcomnrq.ecommerce.domain.model; -import lombok.Data; - import javax.persistence.*; +import lombok.Data; @Data @Entity diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/Category.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/Category.java index 38e930e..65ad291 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/Category.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/Category.java @@ -1,12 +1,11 @@ package com.marcomnrq.ecommerce.domain.model; +import java.util.List; +import javax.persistence.*; import lombok.Data; import net.minidev.json.annotate.JsonIgnore; import org.hibernate.annotations.NaturalId; -import javax.persistence.*; -import java.util.List; - @Data @Entity @Table(name = "categories") diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/Order.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/Order.java index 505ae6d..ef0c541 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/Order.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/Order.java @@ -1,9 +1,8 @@ package com.marcomnrq.ecommerce.domain.model; -import lombok.Data; - -import javax.persistence.*; import java.util.List; +import javax.persistence.*; +import lombok.Data; @Data @Entity diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/OrderItem.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/OrderItem.java index ccf761b..798f049 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/OrderItem.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/OrderItem.java @@ -1,8 +1,7 @@ package com.marcomnrq.ecommerce.domain.model; -import lombok.Data; - import javax.persistence.*; +import lombok.Data; @Data @Entity diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/Payment.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/Payment.java index de429df..216ea5a 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/Payment.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/Payment.java @@ -1,10 +1,8 @@ package com.marcomnrq.ecommerce.domain.model; -import lombok.Data; - import javax.persistence.*; - +import lombok.Data; @Data @Entity diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/Product.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/Product.java index a449ffc..3cf6e92 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/Product.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/Product.java @@ -10,25 +10,21 @@ @Entity @Table(name = "products") public class Product extends AuditModel { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - private String name; - - private Integer stock; - - private Float price; - - private String description; - - @ManyToMany(fetch = FetchType.LAZY, - cascade = {CascadeType.PERSIST, CascadeType.MERGE}) - @JoinTable(name = "products_categories", - joinColumns = {@JoinColumn(name = "product_id")}, - inverseJoinColumns = {@JoinColumn(name = "category_id")}) - @JsonIgnore - List categories; - - private Boolean enabled; + @ManyToMany( + fetch = FetchType.LAZY, + cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinTable( + name = "products_categories", + joinColumns = {@JoinColumn(name = "product_id")}, + inverseJoinColumns = {@JoinColumn(name = "category_id")}) + @JsonIgnore + List categories; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + private String name; + private Integer stock; + private Float price; + private String description; + private Boolean enabled; } diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/RefreshToken.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/RefreshToken.java index 03a1567..c7b71be 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/RefreshToken.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/RefreshToken.java @@ -8,12 +8,12 @@ @Entity @Table(name = "refresh_tokens") public class RefreshToken extends AuditModel { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - @OneToOne(fetch = FetchType.LAZY) - private User user; + @OneToOne(fetch = FetchType.LAZY) + private User user; - private String token; -} \ No newline at end of file + private String token; +} diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/Role.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/Role.java index 8cda86a..c085abe 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/Role.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/Role.java @@ -1,13 +1,12 @@ package com.marcomnrq.ecommerce.domain.model; +import java.util.List; +import javax.persistence.*; +import javax.validation.constraints.NotBlank; import lombok.Data; import net.minidev.json.annotate.JsonIgnore; import org.hibernate.annotations.NaturalId; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.util.List; - @Data @Entity @Table(name = "roles") diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/model/User.java b/src/main/java/com/marcomnrq/ecommerce/domain/model/User.java index 2a588d3..2a81727 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/model/User.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/model/User.java @@ -1,36 +1,29 @@ package com.marcomnrq.ecommerce.domain.model; +import java.util.List; +import javax.persistence.*; import lombok.Data; import net.minidev.json.annotate.JsonIgnore; import org.hibernate.annotations.NaturalId; -import javax.persistence.*; -import java.util.List; - @Data @Entity @Table(name ="users") public class User extends AuditModel { + @ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinTable( + name = "users_roles", + joinColumns = {@JoinColumn(name = "user_id")}, + inverseJoinColumns = {@JoinColumn(name = "role_id")}) + @JsonIgnore + List roles; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @NaturalId private String email; - private String password; - private String firstName; - private String lastName; - - @ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) - @JoinTable( - name = "users_roles", - joinColumns = {@JoinColumn(name = "user_id")}, - inverseJoinColumns = {@JoinColumn(name = "role_id")}) - @JsonIgnore - List roles; - private Boolean enabled; } diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/repository/CartRepository.java b/src/main/java/com/marcomnrq/ecommerce/domain/repository/CartRepository.java index ea4d7c7..14fec1c 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/repository/CartRepository.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/repository/CartRepository.java @@ -7,5 +7,5 @@ import java.util.Optional; public interface CartRepository extends JpaRepository { - Optional findByUser(User user); + Optional findByUser(User user); } diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/repository/CategoryRepository.java b/src/main/java/com/marcomnrq/ecommerce/domain/repository/CategoryRepository.java index f7066bf..c2edb54 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/repository/CategoryRepository.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/repository/CategoryRepository.java @@ -1,9 +1,8 @@ package com.marcomnrq.ecommerce.domain.repository; import com.marcomnrq.ecommerce.domain.model.Category; -import org.springframework.data.jpa.repository.JpaRepository; - import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; public interface CategoryRepository extends JpaRepository { Optional findByName(String name); diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/repository/PaymentRepository.java b/src/main/java/com/marcomnrq/ecommerce/domain/repository/PaymentRepository.java index 16984a2..74f3ccd 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/repository/PaymentRepository.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/repository/PaymentRepository.java @@ -3,6 +3,4 @@ import com.marcomnrq.ecommerce.domain.model.Payment; import org.springframework.data.jpa.repository.JpaRepository; -public interface PaymentRepository extends JpaRepository { - -} +public interface PaymentRepository extends JpaRepository {} diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/repository/ProductRepository.java b/src/main/java/com/marcomnrq/ecommerce/domain/repository/ProductRepository.java index ef8c9c1..2829ff1 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/repository/ProductRepository.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/repository/ProductRepository.java @@ -3,6 +3,4 @@ import com.marcomnrq.ecommerce.domain.model.Product; import org.springframework.data.jpa.repository.JpaRepository; -public interface ProductRepository extends JpaRepository { - -} +public interface ProductRepository extends JpaRepository {} diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/repository/RefreshTokenRepository.java b/src/main/java/com/marcomnrq/ecommerce/domain/repository/RefreshTokenRepository.java index a15cbb3..43e04ed 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/repository/RefreshTokenRepository.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/repository/RefreshTokenRepository.java @@ -1,9 +1,8 @@ package com.marcomnrq.ecommerce.domain.repository; import com.marcomnrq.ecommerce.domain.model.RefreshToken; -import org.springframework.data.jpa.repository.JpaRepository; - import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; public interface RefreshTokenRepository extends JpaRepository { Optional findByToken(String token); diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/repository/RoleRepository.java b/src/main/java/com/marcomnrq/ecommerce/domain/repository/RoleRepository.java index ebcbb1f..0d3a96a 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/repository/RoleRepository.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/repository/RoleRepository.java @@ -4,5 +4,5 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface RoleRepository extends JpaRepository { - Role findByName(String name); + Role findByName(String name); } diff --git a/src/main/java/com/marcomnrq/ecommerce/domain/repository/UserRepository.java b/src/main/java/com/marcomnrq/ecommerce/domain/repository/UserRepository.java index 42ca9b1..1ae9eec 100644 --- a/src/main/java/com/marcomnrq/ecommerce/domain/repository/UserRepository.java +++ b/src/main/java/com/marcomnrq/ecommerce/domain/repository/UserRepository.java @@ -1,9 +1,8 @@ package com.marcomnrq.ecommerce.domain.repository; import com.marcomnrq.ecommerce.domain.model.User; -import org.springframework.data.jpa.repository.JpaRepository; - import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; public interface UserRepository extends JpaRepository { Optional findByEmail(String email); diff --git a/src/main/java/com/marcomnrq/ecommerce/exception/CustomException.java b/src/main/java/com/marcomnrq/ecommerce/exception/CustomException.java index 1174ebb..568368c 100644 --- a/src/main/java/com/marcomnrq/ecommerce/exception/CustomException.java +++ b/src/main/java/com/marcomnrq/ecommerce/exception/CustomException.java @@ -1,11 +1,11 @@ package com.marcomnrq.ecommerce.exception; -public class CustomException extends RuntimeException{ - public CustomException(String exceptionMessage, Exception exception) { - super(exceptionMessage, exception); - } +public class CustomException extends RuntimeException { + public CustomException(String exceptionMessage, Exception exception) { + super(exceptionMessage, exception); + } - public CustomException(String exceptionMessage) { - super(exceptionMessage); - } + public CustomException(String exceptionMessage) { + super(exceptionMessage); + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/resource/IpnResource.java b/src/main/java/com/marcomnrq/ecommerce/resource/IpnResource.java index c29b277..0ac1a2d 100644 --- a/src/main/java/com/marcomnrq/ecommerce/resource/IpnResource.java +++ b/src/main/java/com/marcomnrq/ecommerce/resource/IpnResource.java @@ -1,18 +1,17 @@ package com.marcomnrq.ecommerce.resource; -import lombok.Data; - import java.util.Date; +import lombok.Data; @Data public class IpnResource { - private Integer id; - private Boolean live_mode; - private String type; - private Date date_created; - private Long application_id; - private Integer user_id; - private Integer version; - private String api_version; - private String action; + private Integer id; + private Boolean live_mode; + private String type; + private Date date_created; + private Long application_id; + private Integer user_id; + private Integer version; + private String api_version; + private String action; } diff --git a/src/main/java/com/marcomnrq/ecommerce/resource/MercadopagoResource.java b/src/main/java/com/marcomnrq/ecommerce/resource/MercadopagoResource.java index eec3c8b..83fc241 100644 --- a/src/main/java/com/marcomnrq/ecommerce/resource/MercadopagoResource.java +++ b/src/main/java/com/marcomnrq/ecommerce/resource/MercadopagoResource.java @@ -1,15 +1,14 @@ package com.marcomnrq.ecommerce.resource; import com.mercadopago.resources.datastructures.preference.Item; -import lombok.Data; - import java.util.List; +import lombok.Data; @Data public class MercadopagoResource { - private String id; - private String initPoint; - private String sandboxInitPoint; - private String externalReference; - private List items; + private String id; + private String initPoint; + private String sandboxInitPoint; + private String externalReference; + private List items; } diff --git a/src/main/java/com/marcomnrq/ecommerce/resource/ProductResource.java b/src/main/java/com/marcomnrq/ecommerce/resource/ProductResource.java index d70f399..cb047f0 100644 --- a/src/main/java/com/marcomnrq/ecommerce/resource/ProductResource.java +++ b/src/main/java/com/marcomnrq/ecommerce/resource/ProductResource.java @@ -4,8 +4,8 @@ @Data public class ProductResource { - private String name; - private Integer stock; - private Float price; - private Boolean enabled; + private String name; + private Integer stock; + private Float price; + private Boolean enabled; } diff --git a/src/main/java/com/marcomnrq/ecommerce/resource/UserResource.java b/src/main/java/com/marcomnrq/ecommerce/resource/UserResource.java index 62e14ae..d5a92e7 100644 --- a/src/main/java/com/marcomnrq/ecommerce/resource/UserResource.java +++ b/src/main/java/com/marcomnrq/ecommerce/resource/UserResource.java @@ -4,7 +4,7 @@ @Data public class UserResource { - private String email; - private String firstName; - private String lastName; + private String email; + private String firstName; + private String lastName; } diff --git a/src/main/java/com/marcomnrq/ecommerce/security/JwtAuthenticationFilter.java b/src/main/java/com/marcomnrq/ecommerce/security/JwtAuthenticationFilter.java index b80ad9f..3db6448 100644 --- a/src/main/java/com/marcomnrq/ecommerce/security/JwtAuthenticationFilter.java +++ b/src/main/java/com/marcomnrq/ecommerce/security/JwtAuthenticationFilter.java @@ -1,22 +1,20 @@ package com.marcomnrq.ecommerce.security; import com.marcomnrq.ecommerce.service.UserDetailsService; +import java.io.IOException; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import lombok.AllArgsConstructor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; - import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import org.springframework.web.filter.OncePerRequestFilter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - @Component @AllArgsConstructor public class JwtAuthenticationFilter extends OncePerRequestFilter { diff --git a/src/main/java/com/marcomnrq/ecommerce/security/JwtProvider.java b/src/main/java/com/marcomnrq/ecommerce/security/JwtProvider.java index 0c39da1..fef5a79 100644 --- a/src/main/java/com/marcomnrq/ecommerce/security/JwtProvider.java +++ b/src/main/java/com/marcomnrq/ecommerce/security/JwtProvider.java @@ -3,18 +3,17 @@ import com.marcomnrq.ecommerce.exception.CustomException; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.userdetails.User; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; import java.io.IOException; import java.io.InputStream; import java.security.*; import java.security.cert.CertificateException; import java.time.Instant; import java.util.Date; +import javax.annotation.PostConstruct; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.userdetails.User; +import org.springframework.stereotype.Service; @Service public class JwtProvider { diff --git a/src/main/java/com/marcomnrq/ecommerce/service/AuthenticationService.java b/src/main/java/com/marcomnrq/ecommerce/service/AuthenticationService.java index a67df6b..08cd63d 100644 --- a/src/main/java/com/marcomnrq/ecommerce/service/AuthenticationService.java +++ b/src/main/java/com/marcomnrq/ecommerce/service/AuthenticationService.java @@ -1,6 +1,5 @@ package com.marcomnrq.ecommerce.service; -import com.marcomnrq.ecommerce.domain.model.Role; import com.marcomnrq.ecommerce.domain.model.User; import com.marcomnrq.ecommerce.domain.repository.RoleRepository; import com.marcomnrq.ecommerce.domain.repository.UserRepository; @@ -9,6 +8,10 @@ import com.marcomnrq.ecommerce.resource.authentication.RefreshTokenRequest; import com.marcomnrq.ecommerce.resource.authentication.RegistrationRequest; import com.marcomnrq.ecommerce.security.JwtProvider; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collections; + import lombok.AllArgsConstructor; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -18,9 +21,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.Instant; -import java.util.Arrays; - @Service @AllArgsConstructor public class AuthenticationService { @@ -46,7 +46,7 @@ public void signUp(RegistrationRequest registrationRequest) { user.setFirstName(registrationRequest.getFirstName()); user.setLastName(registrationRequest.getLastName()); user.setPassword(passwordEncoder.encode(registrationRequest.getPassword())); - user.setRoles(Arrays.asList(roleRepository.findByName("ROLE_USER"))); + user.setRoles(Collections.singletonList(roleRepository.findByName("ROLE_USER"))); user.setEnabled(true); diff --git a/src/main/java/com/marcomnrq/ecommerce/service/CartService.java b/src/main/java/com/marcomnrq/ecommerce/service/CartService.java index 738c8b7..e6f298c 100644 --- a/src/main/java/com/marcomnrq/ecommerce/service/CartService.java +++ b/src/main/java/com/marcomnrq/ecommerce/service/CartService.java @@ -11,12 +11,10 @@ import com.mercadopago.exceptions.MPException; import com.mercadopago.resources.Preference; import com.mercadopago.resources.datastructures.preference.*; +import java.util.List; import lombok.AllArgsConstructor; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import java.util.List; - @Service @AllArgsConstructor public class CartService { @@ -41,7 +39,7 @@ public Cart emptyCart(Long userId){ public Cart addItem(Long userId, CartItem cartItem){ User user = userRepository.findById(userId).orElseThrow(() -> new CustomException("user not found")); Cart cart = cartRepository.findByUser(user).orElseThrow(() -> new CustomException("user not found")); - if(cart.getItems().contains(cartItem) == true){ + if(cart.getItems().contains(cartItem)){ // Item is already on cart int index = cart.getItems().indexOf(cartItem); int quantity = cart.getItems().get(index).getQuantity(); diff --git a/src/main/java/com/marcomnrq/ecommerce/service/OrderService.java b/src/main/java/com/marcomnrq/ecommerce/service/OrderService.java index af8bdd1..0cc8f97 100644 --- a/src/main/java/com/marcomnrq/ecommerce/service/OrderService.java +++ b/src/main/java/com/marcomnrq/ecommerce/service/OrderService.java @@ -1,12 +1,6 @@ package com.marcomnrq.ecommerce.service; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.marcomnrq.ecommerce.exception.CustomException; -import com.marcomnrq.ecommerce.resource.MercadopagoResource; -import com.mercadopago.MercadoPago; -import com.mercadopago.exceptions.MPException; -import com.mercadopago.resources.Preference; import com.mercadopago.resources.datastructures.preference.*; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/marcomnrq/ecommerce/service/PaymentService.java b/src/main/java/com/marcomnrq/ecommerce/service/PaymentService.java index ff0178f..24921ec 100644 --- a/src/main/java/com/marcomnrq/ecommerce/service/PaymentService.java +++ b/src/main/java/com/marcomnrq/ecommerce/service/PaymentService.java @@ -19,84 +19,84 @@ @AllArgsConstructor public class PaymentService { - private final PaymentRepository paymentRepository; + private final PaymentRepository paymentRepository; - private final Gson gson; + private final Gson gson; - public MercadopagoResource generatePreference(){ - try{ - MercadoPago.SDK.setAccessToken("APP_USR-8208253118659647-112521-dd670f3fd6aa9147df51117701a2082e-677408439"); - MercadoPago.SDK.setIntegratorId("dev_2e4ad5dd362f11eb809d0242ac130004"); - Preference preference = new Preference(); - // Appending the items - Item item = new Item(); - item.setId("1234"); - item.setTitle("Apple iPhone 5S"); - item.setPictureUrl("https://i.blogs.es/3ade97/iphone-5-4/1366_2000.jpg"); - item.setQuantity(1); - item.setDescription("Dispositivo móvil de Tienda e-commerce"); - item.setCurrencyId("PEN"); - item.setUnitPrice((float) 149.99); - preference.appendItem(item); - // Payer information - Payer payer = new Payer(); - payer.setName("Lalo Landa") - .setEmail("test_user_46542185@testuser.com") - .setIdentification(new Identification() - .setType("DNI") - .setNumber("223344445")) - .setPhone(new Phone() - .setAreaCode("52") - .setNumber("5549737300")) - .setAddress(new Address() - .setZipCode("03940") - .setStreetNumber(1602) - .setStreetName("Insurgentes Sur")); - preference.setPayer(payer); - // Back urls and notification url - preference.setBackUrls( - new BackUrls() - .setFailure("https://mp-marco.herokuapp.com/payment") - .setPending("https://mp-marco.herokuapp.com/payment") - .setSuccess("https://mp-marco.herokuapp.com/payment") - ); - preference.setNotificationUrl("https://mp-marco.herokuapp.com/api/payments/notifications"); - preference.setExternalReference("manriqueacham@gmail.com"); - // Payment Methods - PaymentMethods paymentMethods = new PaymentMethods(); - paymentMethods.setExcludedPaymentMethods("diners"); - paymentMethods.setExcludedPaymentTypes("atm"); - paymentMethods.setInstallments(6); - preference.setPaymentMethods(paymentMethods); - preference.setAutoReturn(Preference.AutoReturn.approved); - // Saving and returning - preference = preference.save(); + public MercadopagoResource generatePreference() { + try { + MercadoPago.SDK.setAccessToken( + "APP_USR-8208253118659647-112521-dd670f3fd6aa9147df51117701a2082e-677408439"); + MercadoPago.SDK.setIntegratorId("dev_2e4ad5dd362f11eb809d0242ac130004"); + Preference preference = new Preference(); + // Appending the items + Item item = new Item(); + item.setId("1234"); + item.setTitle("Apple iPhone 5S"); + item.setPictureUrl("https://i.blogs.es/3ade97/iphone-5-4/1366_2000.jpg"); + item.setQuantity(1); + item.setDescription("Dispositivo móvil de Tienda e-commerce"); + item.setCurrencyId("PEN"); + item.setUnitPrice((float) 149.99); + preference.appendItem(item); + // Payer information + Payer payer = new Payer(); + payer + .setName("Lalo Landa") + .setEmail("test_user_46542185@testuser.com") + .setIdentification(new Identification().setType("DNI").setNumber("223344445")) + .setPhone(new Phone().setAreaCode("52").setNumber("5549737300")) + .setAddress( + new Address() + .setZipCode("03940") + .setStreetNumber(1602) + .setStreetName("Insurgentes Sur")); + preference.setPayer(payer); + // Back urls and notification url + preference.setBackUrls( + new BackUrls() + .setFailure("https://mp-marco.herokuapp.com/payment") + .setPending("https://mp-marco.herokuapp.com/payment") + .setSuccess("https://mp-marco.herokuapp.com/payment")); + preference.setNotificationUrl("https://mp-marco.herokuapp.com/api/payments/notifications"); + preference.setExternalReference("manriqueacham@gmail.com"); + // Payment Methods + PaymentMethods paymentMethods = new PaymentMethods(); + paymentMethods.setExcludedPaymentMethods("diners"); + paymentMethods.setExcludedPaymentTypes("atm"); + paymentMethods.setInstallments(6); + preference.setPaymentMethods(paymentMethods); + preference.setAutoReturn(Preference.AutoReturn.approved); + // Saving and returning + preference = preference.save(); - // Resource (DTO) - MercadopagoResource resource = new MercadopagoResource(); - resource.setId(preference.getId()); - resource.setInitPoint(preference.getInitPoint()); - resource.setSandboxInitPoint(preference.getSandboxInitPoint()); - resource.setItems(preference.getItems()); - resource.setExternalReference(preference.getExternalReference()); - return resource; + // Resource (DTO) + MercadopagoResource resource = new MercadopagoResource(); + resource.setId(preference.getId()); + resource.setInitPoint(preference.getInitPoint()); + resource.setSandboxInitPoint(preference.getSandboxInitPoint()); + resource.setItems(preference.getItems()); + resource.setExternalReference(preference.getExternalReference()); + return resource; - } catch (MPException exception){ - throw new CustomException("Something went wrong", exception); - } - } - public void paymentNotification(String parameters, String body){ - Payment payment = new Payment(); - payment.setParameters(parameters); - payment.setBody(body); - paymentRepository.save(payment); - } - public Page getAllPayments(Pageable pageable){ - return paymentRepository.findAll(pageable); + } catch (MPException exception) { + throw new CustomException("Something went wrong", exception); } + } - public ResponseEntity deleteAllPayments(){ - paymentRepository.deleteAll(); - return ResponseEntity.ok().build(); - } + public void paymentNotification(String parameters, String body) { + Payment payment = new Payment(); + payment.setParameters(parameters); + payment.setBody(body); + paymentRepository.save(payment); + } + + public Page getAllPayments(Pageable pageable) { + return paymentRepository.findAll(pageable); + } + + public ResponseEntity deleteAllPayments() { + paymentRepository.deleteAll(); + return ResponseEntity.ok().build(); + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/service/ProductService.java b/src/main/java/com/marcomnrq/ecommerce/service/ProductService.java index 36295ce..8d76c48 100644 --- a/src/main/java/com/marcomnrq/ecommerce/service/ProductService.java +++ b/src/main/java/com/marcomnrq/ecommerce/service/ProductService.java @@ -16,55 +16,71 @@ @AllArgsConstructor public class ProductService { - private final ProductRepository productRepository; + private final ProductRepository productRepository; - private final CategoryRepository categoryRepository; + private final CategoryRepository categoryRepository; - public Product createProduct(Product product){ - return productRepository.save(product); - } + public Product createProduct(Product product) { + return productRepository.save(product); + } - public Product getProductById(Integer id){ - return productRepository.findById(id).orElseThrow(() -> new CustomException("Product not found")); - } + public Product getProductById(Integer id) { + return productRepository + .findById(id) + .orElseThrow(() -> new CustomException("Product not found")); + } - public Page getAllProducts(Pageable pageable){ - return productRepository.findAll(pageable); - } + public Page getAllProducts(Pageable pageable) { + return productRepository.findAll(pageable); + } - public Product updateProduct(Integer id, ProductResource productResource){ - Product product = productRepository.findById(id).orElseThrow(() -> new CustomException("Product not found")); - product.setName(productResource.getName()); - product.setStock(productResource.getStock()); - product.setPrice(productResource.getPrice()); - product.setEnabled(productResource.getEnabled()); - return productRepository.save(product); - } + public Product updateProduct(Integer id, ProductResource productResource) { + Product product = + productRepository.findById(id).orElseThrow(() -> new CustomException("Product not found")); + product.setName(productResource.getName()); + product.setStock(productResource.getStock()); + product.setPrice(productResource.getPrice()); + product.setEnabled(productResource.getEnabled()); + return productRepository.save(product); + } - public ResponseEntity deleteProduct(Integer id){ - Product product = productRepository.findById(id).orElseThrow(() -> new CustomException("Product not found")); - productRepository.delete(product); - return ResponseEntity.ok().build(); - } + public ResponseEntity deleteProduct(Integer id) { + Product product = + productRepository.findById(id).orElseThrow(() -> new CustomException("Product not found")); + productRepository.delete(product); + return ResponseEntity.ok().build(); + } - public Product assignCategory(Integer productId, Integer categoryId){ - Category category = categoryRepository.findById(categoryId) - .orElseThrow(() -> new CustomException("Category not found")); - return productRepository.findById(productId).map(product -> { - if(!product.getCategories().contains(category)) { + public Product assignCategory(Integer productId, Integer categoryId) { + Category category = + categoryRepository + .findById(categoryId) + .orElseThrow(() -> new CustomException("Category not found")); + return productRepository + .findById(productId) + .map( + product -> { + if (!product.getCategories().contains(category)) { product.getCategories().add(category); return productRepository.save(product); - } - return product; - }).orElseThrow(() -> new CustomException("Product not found")); - } + } + return product; + }) + .orElseThrow(() -> new CustomException("Product not found")); + } - public Product unAssignCategory(Integer productId, Integer categoryId){ - Category category = categoryRepository.findById(categoryId) - .orElseThrow(() -> new CustomException("Category not found")); - return productRepository.findById(productId).map(product -> { - product.getCategories().remove(category); - return productRepository.save(product); - }).orElseThrow(() -> new CustomException("Product not found")); - } + public Product unAssignCategory(Integer productId, Integer categoryId) { + Category category = + categoryRepository + .findById(categoryId) + .orElseThrow(() -> new CustomException("Category not found")); + return productRepository + .findById(productId) + .map( + product -> { + product.getCategories().remove(category); + return productRepository.save(product); + }) + .orElseThrow(() -> new CustomException("Product not found")); + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/service/RefreshTokenService.java b/src/main/java/com/marcomnrq/ecommerce/service/RefreshTokenService.java index cbad484..d006c0d 100644 --- a/src/main/java/com/marcomnrq/ecommerce/service/RefreshTokenService.java +++ b/src/main/java/com/marcomnrq/ecommerce/service/RefreshTokenService.java @@ -6,45 +6,47 @@ import com.marcomnrq.ecommerce.domain.repository.UserRepository; import com.marcomnrq.ecommerce.exception.CustomException; import com.marcomnrq.ecommerce.resource.authentication.RefreshTokenRequest; +import java.util.Optional; +import java.util.UUID; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; -import java.util.UUID; - @Service @Transactional @AllArgsConstructor public class RefreshTokenService { - private final RefreshTokenRepository refreshTokenRepository; + private final RefreshTokenRepository refreshTokenRepository; - private final UserRepository userRepository; + private final UserRepository userRepository; - public RefreshToken generateRefreshToken(String email) { - // Accessing the user - Optional userOptional = userRepository.findByEmail(email); - User user = userOptional.orElseThrow(() -> new CustomException("User not found with email: " + email)); + public RefreshToken generateRefreshToken(String email) { + // Accessing the user + Optional userOptional = userRepository.findByEmail(email); + User user = + userOptional.orElseThrow(() -> new CustomException("User not found with email: " + email)); - // Generating a new refresh token - RefreshToken refreshToken = new RefreshToken(); - refreshToken.setToken(UUID.randomUUID().toString()); - refreshToken.setUser(user); + // Generating a new refresh token + RefreshToken refreshToken = new RefreshToken(); + refreshToken.setToken(UUID.randomUUID().toString()); + refreshToken.setUser(user); - // Storing it in the database - return refreshTokenRepository.save(refreshToken); - } + // Storing it in the database + return refreshTokenRepository.save(refreshToken); + } - public void validateRefreshToken(RefreshTokenRequest refreshTokenRequest) { - RefreshToken token = refreshTokenRepository.findByToken(refreshTokenRequest.getRefreshToken()) - .orElseThrow(() -> new CustomException("Invalid refresh token")); - if(token.getUser().getEmail() != refreshTokenRequest.getEmail()){ - throw new CustomException("Invalid refresh token (email)"); - } + public void validateRefreshToken(RefreshTokenRequest refreshTokenRequest) { + RefreshToken token = + refreshTokenRepository + .findByToken(refreshTokenRequest.getRefreshToken()) + .orElseThrow(() -> new CustomException("Invalid refresh token")); + if (token.getUser().getEmail() != refreshTokenRequest.getEmail()) { + throw new CustomException("Invalid refresh token (email)"); } + } - public void deleteRefreshToken(String token) { - refreshTokenRepository.deleteByToken(token); - } + public void deleteRefreshToken(String token) { + refreshTokenRepository.deleteByToken(token); + } } diff --git a/src/main/java/com/marcomnrq/ecommerce/service/UserDetailsService.java b/src/main/java/com/marcomnrq/ecommerce/service/UserDetailsService.java index 22edc1c..a113ffb 100644 --- a/src/main/java/com/marcomnrq/ecommerce/service/UserDetailsService.java +++ b/src/main/java/com/marcomnrq/ecommerce/service/UserDetailsService.java @@ -4,6 +4,10 @@ import com.marcomnrq.ecommerce.domain.model.User; import com.marcomnrq.ecommerce.domain.repository.UserRepository; import com.marcomnrq.ecommerce.exception.CustomException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; import lombok.AllArgsConstructor; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -11,11 +15,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; - @Service @AllArgsConstructor public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService { diff --git a/src/main/java/com/marcomnrq/ecommerce/service/UserService.java b/src/main/java/com/marcomnrq/ecommerce/service/UserService.java index ed67b9e..65d6adb 100644 --- a/src/main/java/com/marcomnrq/ecommerce/service/UserService.java +++ b/src/main/java/com/marcomnrq/ecommerce/service/UserService.java @@ -4,11 +4,10 @@ import com.marcomnrq.ecommerce.domain.repository.UserRepository; import com.marcomnrq.ecommerce.exception.CustomException; import com.marcomnrq.ecommerce.resource.UserResource; +import java.util.Optional; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; -import java.util.Optional; - @Service @AllArgsConstructor public class UserService {