allowedOrigins;
-//
-// @Bean
-// CorsFilter corsFilter() {
-// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
-// CorsConfiguration config = new CorsConfiguration();
-// config.setAllowCredentials(true);
-// config.setAllowedOrigins(allowedOrigins);
-// config.setAllowedMethods(Collections.singletonList("*"));
-// config.setAllowedHeaders(Collections.singletonList("*"));
-// source.registerCorsConfiguration("/**", config);
-// return new CorsFilter(source);
-// }
-}
\ No newline at end of file
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/CredentialsUtils.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/CredentialsUtils.java
deleted file mode 100644
index 2cff08f..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/CredentialsUtils.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-import org.keycloak.representations.idm.CredentialRepresentation;
-
-public class CredentialsUtils {
-
- private CredentialsUtils(){}
-
- public static CredentialRepresentation createPasswordCredentials(String password) {
- CredentialRepresentation passwordCredentials = new CredentialRepresentation();
- passwordCredentials.setTemporary(false);
- passwordCredentials.setType(CredentialRepresentation.PASSWORD);
- passwordCredentials.setValue(password);
- return passwordCredentials;
- }
-}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/CustomFilter.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/CustomFilter.java
deleted file mode 100644
index 6f13c84..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/CustomFilter.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.filter.GenericFilterBean;
-
-import javax.servlet.*;
-import java.io.IOException;
-
-
-@Slf4j
-public class CustomFilter extends GenericFilterBean {
-
- @Override
- public void doFilter(
- ServletRequest request,
- ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
- log.error("XXX");
- chain.doFilter(request, response);
- }
-}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/KeycloakConfigProperties.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/KeycloakConfigProperties.java
deleted file mode 100644
index bd1e808..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/KeycloakConfigProperties.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-
-import lombok.Getter;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
-import org.jboss.resteasy.client.jaxrs.ResteasyClient;
-import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
-import org.keycloak.OAuth2Constants;
-import org.keycloak.admin.client.KeycloakBuilder;
-import org.keycloak.admin.client.resource.UsersResource;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@Slf4j
-@Getter
-@Setter
-@ConfigurationProperties(prefix = "tribune.keycloak.client.user-management")
-public class KeycloakConfigProperties {
-
- @Value("${keycloak.auth-server-url}")
- private String authServerUrl;
- @Value("${keycloak.realm}")
- private String realm;
- private String resource;
- private String clientSecret;
- private String username;
- private String password;
-
- public UsersResource getInstance(){
- ResteasyClient resteasyClient=new ResteasyClientBuilder()
- .connectionPoolSize(10)
- .build();
- return KeycloakBuilder.builder()
- .serverUrl(authServerUrl)
- .realm(realm)
- .grantType(OAuth2Constants.PASSWORD)
- .username(username)
- .password(password)
- .clientId(resource)
- .clientSecret(clientSecret)
- .resteasyClient(resteasyClient)
- .build().realm(realm).users();
- }
-}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/SecurityConfig.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/SecurityConfig.java
deleted file mode 100644
index dbd34f5..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/SecurityConfig.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-import lombok.extern.slf4j.Slf4j;
-import org.keycloak.adapters.springsecurity.KeycloakConfiguration;
-import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider;
-import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
-import org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticationProcessingFilter;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.core.Ordered;
-import org.springframework.core.annotation.Order;
-import org.springframework.http.HttpMethod;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.http.SessionCreationPolicy;
-import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper;
-import org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy;
-import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
-
-/**
- * The {@link EnableGlobalMethodSecurity} enables direct config of role-based access
- * to our controllers. See the following example:
- * {@code
- * @PreAuthorize("hasRole('USER')")
- * @GetMapping("/title)
- * public ResponseEntitygetTitle(){
- * //
- * return title;
- * }
- * }
- */
-@Slf4j
-@Order(Ordered.HIGHEST_PRECEDENCE)
-@KeycloakConfiguration
-//@EnableGlobalMethodSecurity(prePostEnabled = true)
-public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
-
- @Autowired
- public void configureGlobal(AuthenticationManagerBuilder auth) {
- KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
- keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
- auth.authenticationProvider(keycloakAuthenticationProvider);
- }
-
- /**
- * The other way around
- * return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
- * */
- @Bean
- @Override
- protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
- return new NullAuthenticatedSessionStrategy();
- }
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
-
- super.configure(http);
- // Enable CORS and disable CSRF
- http
- .cors()
- .and()
- .csrf().disable()
- // Set session management to stateless
- .sessionManagement()
- .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
- .and()
- .authorizeRequests()
- .antMatchers(HttpMethod.GET, "/v1/transaction/status/**").hasRole(MERCHANT)
- .antMatchers(HttpMethod.POST, "/v1/transaction/**").hasRole(MERCHANT)
- .antMatchers(HttpMethod.POST, "/v1/users/**").anonymous()
- .antMatchers(HttpMethod.GET, "/api/user-data/me", "/actuator/**").permitAll()
- .antMatchers(HttpMethod.GET, "/v1/dummy/**").permitAll()
- .antMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs", "/v3/api-docs/**").permitAll()
- .anyRequest().fullyAuthenticated();
- }
-
- /**
- * provided by keycloak to handle authentication failures.
- * */
- @Bean
- @Override
- protected KeycloakAuthenticationProcessingFilter keycloakAuthenticationProcessingFilter() throws Exception {
- KeycloakAuthenticationProcessingFilter filter = new KeycloakAuthenticationProcessingFilter(this.authenticationManagerBean());
- filter.setSessionAuthenticationStrategy(this.sessionAuthenticationStrategy());
- filter.setAuthenticationFailureHandler(new TribuneKeycloakAuthenticationFailureHandler());
- return filter;
- }
-
- public static final String MERCHANT = "merchant";
- public static final String USER = "user";
- public static final String MANAGE_USERS = "manage-users";
-}
\ No newline at end of file
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/TribuneKeycloakAuthenticationFailureHandler.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/TribuneKeycloakAuthenticationFailureHandler.java
deleted file mode 100644
index 9028164..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/TribuneKeycloakAuthenticationFailureHandler.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-import com.tribune.backend.domain.dto.GenericResponse;
-import lombok.AllArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.web.authentication.AuthenticationFailureHandler;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-import static org.keycloak.util.JsonSerialization.mapper;
-
-@Slf4j
-@AllArgsConstructor
-public class TribuneKeycloakAuthenticationFailureHandler implements AuthenticationFailureHandler {
-
- @Override
- public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException ex) throws IOException {
- ex.printStackTrace();
- log.error("Authentication Error: {}", ex.getMessage());
- response.setContentType(MediaType.APPLICATION_JSON_VALUE);
- response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
-
- //todo:check removal of WWW_AUTHENTICATE header from response
- GenericResponse genericResponse = GenericResponse.builder()
- .message(ex.getMessage())
- .reason(response.getHeader(HttpHeaders.WWW_AUTHENTICATE))
- .code(response.getStatus())
- .build();
- response.getWriter().write(mapper.writeValueAsString(genericResponse));
- }
-}
\ No newline at end of file
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserDTO.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserDTO.java
deleted file mode 100644
index f660e74..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserDTO.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-import lombok.*;
-
-import javax.validation.constraints.NotBlank;
-
-@Getter
-@Setter
-@AllArgsConstructor
-@NoArgsConstructor
-@Builder
-public class UserDTO {
-
- @NotBlank
- private String username;
- @NotBlank
- private String email;
- @NotBlank
- private String password;
- @NotBlank
- private String firstName;
- @NotBlank
- private String lastName;
-}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserLoginRequest.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserLoginRequest.java
deleted file mode 100644
index c5c5732..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserLoginRequest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Getter;
-import lombok.Setter;
-
-import javax.validation.constraints.NotBlank;
-
-@Getter
-@Setter
-@AllArgsConstructor
-@Builder
-public class UserLoginRequest {
-
- @NotBlank
- private String username;
- @NotBlank
- private String password;
-}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserManagementService.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserManagementService.java
deleted file mode 100644
index fa5de92..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserManagementService.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.tribune.backend.domain.dto.GenericResponse;
-import org.keycloak.representations.idm.UserRepresentation;
-
-import javax.ws.rs.core.Response;
-import java.util.List;
-
-
-public interface UserManagementService {
-
- Response addUser(UserDTO userDTO);
-
- List getUser(String userName);
-
- void updateUser(String userId, UserDTO userDTO);
- void deleteUser(String userId);
-
- void sendVerificationLink(String userId);
-
- void sendResetPassword(String userId);
-
- GenericResponse authenticate(UserLoginRequest userDTO);
-}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserManagementServiceImpl.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserManagementServiceImpl.java
deleted file mode 100644
index f86e4cb..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/config/security/UserManagementServiceImpl.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package com.tribune.backend.infrastructure.config.security;
-
-import com.tribune.backend.domain.dto.GenericResponse;
-import com.tribune.backend.infrastructure.error.BackendException;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import lombok.extern.slf4j.Slf4j;
-import org.keycloak.representations.idm.CredentialRepresentation;
-import org.keycloak.representations.idm.UserRepresentation;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.MediaType;
-import org.springframework.http.client.reactive.ReactorClientHttpConnector;
-import org.springframework.stereotype.Service;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.reactive.function.BodyInserters;
-import org.springframework.web.reactive.function.client.WebClient;
-import org.springframework.web.util.UriComponentsBuilder;
-import reactor.netty.http.client.HttpClient;
-
-import javax.ws.rs.core.Response;
-import java.net.URI;
-import java.time.Duration;
-import java.util.Collections;
-import java.util.List;
-
-
-@Slf4j
-@Service
-public class UserManagementServiceImpl implements UserManagementService {
- @Value("${keycloak.resource}")
- private String tribuneSpringbootClient;
-
- private final KeycloakConfigProperties properties;
-
- @Autowired
- public UserManagementServiceImpl(KeycloakConfigProperties properties) {
- this.properties = properties;
- }
-
- @Override
- public Response addUser(UserDTO userDTO) {
- CredentialRepresentation credential = CredentialsUtils
- .createPasswordCredentials(userDTO.getPassword());
-
- UserRepresentation user = new UserRepresentation();
-
- user.setUsername(userDTO.getUsername());
- user.setFirstName(userDTO.getFirstName());
- user.setLastName(userDTO.getLastName());
- user.setEmail(userDTO.getEmail());
- user.setCredentials(Collections.singletonList(credential));
- user.setEnabled(true);
-
- return properties.getInstance().create(user);
- }
-
- @Override
- public List getUser(String userName) {
- return properties.getInstance().search(userName, true);
- }
-
- @Override
- public void updateUser(String userId, UserDTO userDTO) {
- CredentialRepresentation credential = CredentialsUtils
- .createPasswordCredentials(userDTO.getPassword());
- UserRepresentation user = new UserRepresentation();
- user.setUsername(userDTO.getUsername());
- user.setFirstName(userDTO.getFirstName());
- user.setLastName(userDTO.getLastName());
- user.setEmail(userDTO.getEmail());
- user.setCredentials(Collections.singletonList(credential));
- //todo:needs confirmation
- properties.getInstance().get(userId).update(user);
- }
-
- @Override
- public void deleteUser(String userId) {
- //todo:needs confirmation
- properties.getInstance().get(userId)
- .remove();
- }
-
- @Override
- public void sendVerificationLink(String userId) {
- //todo:needs confirmation
- properties.getInstance().get(userId)
- .sendVerifyEmail();
- }
-
- @Override
- public void sendResetPassword(String userId) {
- //todo:needs confirmation
- properties.getInstance().get(userId)
- .executeActionsEmail(List.of("UPDATE_PASSWORD"));
- }
-
- @Override
- public GenericResponse authenticate(UserLoginRequest userDTO) {
- URI uri=UriComponentsBuilder.fromUriString(
- String.format("%s/realms/%s/protocol/openid-connect/token",
- properties.getAuthServerUrl(), properties.getRealm())
- ).build().toUri();
-
- HttpClient httpClient = HttpClient.create()
- .responseTimeout(Duration.ofSeconds(2));
-
- MultiValueMap formData = new LinkedMultiValueMap<>();
- formData.add("username", userDTO.getUsername());
- formData.add("password", userDTO.getPassword());
- formData.add("client_id", tribuneSpringbootClient);
- formData.add("grant_type", CredentialRepresentation.PASSWORD);
-
- ObjectNode node= WebClient.builder()
- .clientConnector(new ReactorClientHttpConnector(httpClient))
- .build()
- .post()
- .uri(uri)
- .body(BodyInserters.fromFormData(formData))
- .accept(MediaType.APPLICATION_JSON)
- .exchangeToMono(clientResponse -> {
- if (clientResponse.statusCode().is4xxClientError()) {
- log.error("error");
- return clientResponse.bodyToMono(ObjectNode.class).map(val -> {
-
- throw new BackendException(val, clientResponse.statusCode());
- });
- } else
- return clientResponse.bodyToMono(ObjectNode.class);
- })
- .block();
-
- return GenericResponse.builder()
- .code(200)
- .message("Success!")
- .data(node)
- .build();
- }
-}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/controller/OrdersController.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/controller/OrdersController.java
index 4a885d0..9e3ffde 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/controller/OrdersController.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/controller/OrdersController.java
@@ -1,8 +1,9 @@
package com.tribune.backend.infrastructure.controller;
-import com.tribune.backend.domain.dto.PlaceOrderRequest;
+import com.tribune.backend.domain.dto.SubmitOrderRequest;
import com.tribune.backend.domain.dto.GenericResponse;
import com.tribune.backend.domain.dto.SingleOrderResponse;
+import com.tribune.backend.infrastructure.error.NotFoundException;
import com.tribune.backend.infrastructure.services.OrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -18,13 +19,17 @@ public class OrdersController {
private final OrderService orderService;
- @PostMapping("/order")
- public GenericResponse createBlog(@Valid @RequestBody PlaceOrderRequest createOrderRequest) {
+ @PostMapping("/submitOrder")
+ public GenericResponse placeOrder(@Valid @RequestBody SubmitOrderRequest createOrderRequest) throws NotFoundException {
+
+ SingleOrderResponse orderResponse=orderService.processOrder(createOrderRequest);
+
return GenericResponse.builder()
.code(201)
- .data(orderService.placeOrder(createOrderRequest))
+ .data(orderResponse)
.message("Created!")
.build();
}
+
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/controller/UserController.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/controller/UserController.java
deleted file mode 100644
index 4649b68..0000000
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/controller/UserController.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.tribune.backend.infrastructure.controller;
-
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.tribune.backend.domain.dto.GenericResponse;
-import com.tribune.backend.infrastructure.config.security.UserDTO;
-import com.tribune.backend.infrastructure.config.security.UserLoginRequest;
-import com.tribune.backend.infrastructure.config.security.UserManagementService;
-import lombok.AllArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.keycloak.representations.idm.UserRepresentation;
-import org.springframework.web.bind.annotation.*;
-
-import javax.validation.Valid;
-import javax.ws.rs.core.Response;
-import java.util.List;
-
-@Slf4j
-@AllArgsConstructor
-@RestController
-@RequestMapping(path = "/v1/users")
-public class UserController {
- private final UserManagementService service;
-
-
- @PostMapping("/user/auth")
- public GenericResponse authenticate(@Valid @RequestBody UserLoginRequest userDTO){
- return service.authenticate(userDTO);
- }
-
- @PostMapping("/user")
- public Response addUser(@Valid @RequestBody UserDTO userDTO){
- return service.addUser(userDTO);
- }
-
- @GetMapping(path = "/user/{userName}")
- public List getUser(@PathVariable("userName") String userName){
- return service.getUser(userName);
- }
-
- @PutMapping(path = "/user/{userId}")
- public String updateUser(@PathVariable("userId") String userId, @RequestBody UserDTO userDTO){
- service.updateUser(userId, userDTO);
- return "User Details Updated Successfully.";
- }
-
- @DeleteMapping(path = "/user/{userId}")
- public String deleteUser(@PathVariable("userId") String userId){
- service.deleteUser(userId);
- return "User Deleted Successfully.";
- }
-
- @GetMapping(path = "/user/verify/{userId}")
- public String sendVerificationLink(@PathVariable("userId") String userId){
- service.sendVerificationLink(userId);
- return "Verification Link Send to Registered E-mail Id.";
- }
-
- @GetMapping(path = "/user/reset-password/{userId}")
- public String sendResetPasswordLink(@PathVariable("userId") String userId){
- service.sendResetPassword(userId);
- return "Reset Password Link Send Successfully to Registered E-mail Id.";
- }
-}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/DevBootstrap.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/DevBootstrap.java
new file mode 100644
index 0000000..b734059
--- /dev/null
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/DevBootstrap.java
@@ -0,0 +1,87 @@
+package com.tribune.backend.infrastructure.db;
+
+
+import com.tribune.backend.domain.element.customer.CustomerState;
+import com.tribune.backend.domain.element.customer.CustomerType;
+import com.tribune.backend.infrastructure.db.entities.CustomerEntity;
+import com.tribune.backend.infrastructure.db.entities.ProductEntity;
+import com.tribune.backend.infrastructure.db.repository.CustomerRepository;
+import com.tribune.backend.infrastructure.db.repository.ProductRepository;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+
+@Slf4j
+@Transactional
+@AllArgsConstructor
+@Component
+public class DevBootstrap implements CommandLineRunner {
+
+ private CustomerRepository customerRepository;
+ private ProductRepository productRepository;
+
+
+ @Override
+ public void run(String... args) {
+
+ initCustomers();
+ initProducts();
+ }
+
+ public void initCustomers() {
+ customerRepository.deleteAll();
+ CustomerEntity customer0 = CustomerEntity.builder()
+ .firstName("John")
+ .lastName("Doe")
+ .type(CustomerType.TRADITIONAL)
+ .displayName("Failure")
+ .state(CustomerState.ACTIVE)
+ .build();
+ CustomerEntity customer1 = CustomerEntity.builder()
+ .firstName("Bill")
+ .lastName("Gates")
+ .type(CustomerType.TRADITIONAL)
+ .displayName("Billy the beast")
+ .state(CustomerState.DISABLED)
+ .build();
+
+ customerRepository.saveAll(List.of(customer0, customer1));
+ }
+
+ public void initProducts() {
+ productRepository.deleteAll();
+ ProductEntity product0 = ProductEntity.builder()
+ .name("Samsung Galaxy S23")
+ .company("Samsung")
+ .price(BigDecimal.valueOf(3112.50))
+ .quantity(15)
+ .build();
+ ProductEntity product1 = ProductEntity.builder()
+ .name("Iphone 14 pro max")
+ .company("Apple")
+ .price(BigDecimal.valueOf(2000))
+ .quantity(5)
+ .build();
+ ProductEntity product2 = ProductEntity.builder()
+ .name("Xiaomi Note 11")
+ .company("Xiaomi")
+ .price(BigDecimal.valueOf(800))
+ .quantity(22)
+ .build();
+ ProductEntity product3 = ProductEntity.builder()
+ .name("Nokia whatever")
+ .company("Nokia")
+ .price(BigDecimal.valueOf(1500))
+ .quantity(82)
+ .build();
+
+ productRepository.saveAll(List.of(product0, product1, product2, product3));
+
+ }
+}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/AddressEntity.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/AddressEntity.java
index 44db402..9f1bddd 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/AddressEntity.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/AddressEntity.java
@@ -2,11 +2,11 @@ package com.tribune.backend.infrastructure.db.entities;
import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
+import org.hibernate.annotations.UpdateTimestamp;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
+import javax.persistence.*;
+import java.time.LocalDateTime;
import java.util.UUID;
@@ -16,13 +16,21 @@ import java.util.UUID;
@AllArgsConstructor
@Builder
@Entity
+@Table(name ="ADDRESS")
public class AddressEntity {
@Id
- private UUID id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ @Column(name = "CUSTOMER")
+ private UUID customer;
- @ManyToOne
- @JoinColumn(name = "customer",referencedColumnName = "id")
- private CustomerEntity customerEntity;
+ @CreationTimestamp
+ @Column(name = "CREATION_TIMESTAMP",nullable = false,updatable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime creationTimestamp;
+
+ @UpdateTimestamp
+ @Column(name = "UPDATE_TIMESTAMP",nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime updateTimestamp;
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/CustomerEntity.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/CustomerEntity.java
index 74848cd..4fb4c9d 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/CustomerEntity.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/CustomerEntity.java
@@ -1,13 +1,15 @@
package com.tribune.backend.infrastructure.db.entities;
-import com.tribune.backend.domain.dto.customer.CustomerState;
-import com.tribune.backend.domain.dto.customer.CustomerType;
+import com.tribune.backend.domain.element.customer.CustomerState;
+import com.tribune.backend.domain.element.customer.CustomerType;
import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
+import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.*;
+import java.time.LocalDateTime;
import java.util.List;
-import java.util.UUID;
@Setter
@Getter
@@ -15,10 +17,12 @@ import java.util.UUID;
@AllArgsConstructor
@Builder
@Entity
+@Table(name ="CUSTOMER")
public class CustomerEntity {
@Id
- private UUID id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
private String displayName;
@@ -32,9 +36,20 @@ public class CustomerEntity {
@Enumerated(value = EnumType.STRING)
private CustomerType type;
- @OneToMany(mappedBy = "customerEntity", fetch = FetchType.LAZY)
+ @OneToMany(mappedBy = "customer", fetch = FetchType.LAZY)
private List paymentEntityList;
- @OneToMany(mappedBy = "customerEntity", fetch = FetchType.LAZY)
+ @OneToMany(mappedBy = "customer", fetch = FetchType.LAZY)
private List addressEntityList;
+
+ @OneToMany(mappedBy = "customer", fetch = FetchType.LAZY)
+ private List invoiceEntityList;
+
+ @CreationTimestamp
+ @Column(name = "CREATION_TIMESTAMP",nullable = false,updatable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime creationTimestamp;
+
+ @UpdateTimestamp
+ @Column(name = "UPDATE_TIMESTAMP",nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime updateTimestamp;
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/InvoiceEntity.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/InvoiceEntity.java
index f3544b5..f5d494f 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/InvoiceEntity.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/InvoiceEntity.java
@@ -2,10 +2,11 @@ package com.tribune.backend.infrastructure.db.entities;
import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
+import org.hibernate.annotations.UpdateTimestamp;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
+import javax.persistence.*;
+import java.time.LocalDateTime;
import java.util.UUID;
@Setter
@@ -14,13 +15,23 @@ import java.util.UUID;
@AllArgsConstructor
@Builder
@Entity
+@Table(name = "INVOICE")
public class InvoiceEntity {
@Id
- private UUID id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
- @ManyToOne
- private CustomerEntity customerEntity;
+ @Column(name = "CUSTOMER")
+ private UUID customer;
+
+ @CreationTimestamp
+ @Column(name = "CREATION_TIMESTAMP", nullable = false, updatable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime creationTimestamp;
+
+ @UpdateTimestamp
+ @Column(name = "UPDATE_TIMESTAMP", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime updateTimestamp;
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/LineItemEntity.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/LineItemEntity.java
index e3b686f..8bd830b 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/LineItemEntity.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/LineItemEntity.java
@@ -12,14 +12,21 @@ import java.util.UUID;
@AllArgsConstructor
@Builder
@Entity
+@Table(name ="LINE_ITEM")
public class LineItemEntity {
@Id
- private UUID id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @Column(name = "customer_order")
+ private Long customerOrder;
+
+
+ @JoinColumn(name = "product",referencedColumnName = "id")
@ManyToOne
- private OrderEntity orderEntity;
+ private ProductEntity product;
- @OneToOne
- private ProductEntity productEntity;
+ private Integer quantity;
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/OrderEntity.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/OrderEntity.java
index 0197d65..34b3d77 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/OrderEntity.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/OrderEntity.java
@@ -3,26 +3,44 @@ package com.tribune.backend.infrastructure.db.entities;
import com.tribune.backend.domain.enums.OrderStatus;
import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
+import org.hibernate.annotations.DynamicUpdate;
+import org.hibernate.annotations.UpdateTimestamp;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.OneToMany;
+import javax.persistence.*;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
import java.util.List;
-import java.util.UUID;
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
+@DynamicUpdate
@Entity
+@Table(name = "CUSTOMER_ORDER")
public class OrderEntity {
@Id
- private UUID id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @Enumerated(value = EnumType.STRING)
private OrderStatus status;
- @OneToMany
- private List lineItemEntities;
+ @OneToMany(mappedBy = "id")
+ private List lineItems;
+
+
+ private BigDecimal payment;
+
+ @CreationTimestamp
+ @Column(name = "CREATION_TIMESTAMP",nullable = false,updatable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime creationTimestamp;
+
+ @UpdateTimestamp
+ @Column(name = "UPDATE_TIMESTAMP",nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime updateTimestamp;
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/PaymentEntity.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/PaymentEntity.java
index 8fdf54d..83cc129 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/PaymentEntity.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/PaymentEntity.java
@@ -2,11 +2,11 @@ package com.tribune.backend.infrastructure.db.entities;
import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
+import org.hibernate.annotations.UpdateTimestamp;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
+import javax.persistence.*;
+import java.time.LocalDateTime;
import java.util.UUID;
@Setter
@@ -15,13 +15,20 @@ import java.util.UUID;
@AllArgsConstructor
@Builder
@Entity
+@Table(name ="PAYMENT")
public class PaymentEntity {
@Id
- private UUID id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ @Column(name = "CUSTOMER")
+ private UUID customer;
+ @CreationTimestamp
+ @Column(name = "CREATION_TIMESTAMP",nullable = false,updatable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime creationTimestamp;
- @ManyToOne
- @JoinColumn(name = "customer",referencedColumnName = "id")
- private CustomerEntity customerEntity;
+ @UpdateTimestamp
+ @Column(name = "UPDATE_TIMESTAMP",nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime updateTimestamp;
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/ProductEntity.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/ProductEntity.java
index e0b6b18..3090a1d 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/ProductEntity.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/entities/ProductEntity.java
@@ -2,19 +2,42 @@ package com.tribune.backend.infrastructure.db.entities;
import lombok.*;
+import org.hibernate.annotations.CreationTimestamp;
+import org.hibernate.annotations.DynamicUpdate;
+import org.hibernate.annotations.UpdateTimestamp;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import java.util.UUID;
+import javax.persistence.*;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
@Setter
@Getter
+@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
+@DynamicUpdate
@Entity
+@Table(name ="PRODUCT")
public class ProductEntity {
@Id
- private UUID id;
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+
+ private String company;
+
+ private Integer quantity;
+
+ private BigDecimal price;
+
+ @CreationTimestamp
+ @Column(name = "CREATION_TIMESTAMP",nullable = false,updatable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime creationTimestamp;
+
+ @UpdateTimestamp
+ @Column(name = "UPDATE_TIMESTAMP",nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
+ private LocalDateTime updateTimestamp;
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/repository/CustomerRepository.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/repository/CustomerRepository.java
index 05c93c5..aa8be38 100644
--- a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/repository/CustomerRepository.java
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/repository/CustomerRepository.java
@@ -5,10 +5,8 @@ import com.tribune.backend.infrastructure.db.entities.CustomerEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
-import java.util.UUID;
-
@Repository
-public interface CustomerRepository extends JpaRepository {
+public interface CustomerRepository extends JpaRepository {
}
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/repository/ProductRepository.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/repository/ProductRepository.java
new file mode 100644
index 0000000..d5f33f2
--- /dev/null
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/db/repository/ProductRepository.java
@@ -0,0 +1,15 @@
+package com.tribune.backend.infrastructure.db.repository;
+
+
+import com.tribune.backend.infrastructure.db.entities.ProductEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ProductRepository extends JpaRepository {
+
+ List findByIdIn(List ids);
+}
+
diff --git a/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/error/ControllerAdvisor.java b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/error/ControllerAdvisor.java
new file mode 100644
index 0000000..20d0b27
--- /dev/null
+++ b/backend-infrastructure/src/main/java/com/tribune/backend/infrastructure/error/ControllerAdvisor.java
@@ -0,0 +1,71 @@
+package com.tribune.backend.infrastructure.error;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.tribune.backend.domain.dto.GenericResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.validation.FieldError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+import org.springframework.web.context.request.WebRequest;
+import org.springframework.web.server.ResponseStatusException;
+import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
+
+@Slf4j
+@RestControllerAdvice
+public class ControllerAdvisor extends ResponseEntityExceptionHandler {
+
+
+ @ExceptionHandler(BackendException.class)
+ public ResponseEntity> handleException(BackendException e) {
+ log.error("status:{} --- error: {}", e.getStatus(), e.getError());
+ GenericResponse response = GenericResponse.builder()
+ .message(e.getMessage())
+ .code(e.getStatus().value())
+ .data(e.getError())
+ .build();
+ return ResponseEntity.status(e.getStatus()).body(response);
+ }
+
+ @ExceptionHandler(ResponseStatusException.class)
+ public ResponseEntity> handleException(ResponseStatusException e) {
+ log.error("status:{} --- error: {}", e.getStatus(), e.getMessage());
+ GenericResponse response = GenericResponse.builder()
+ .message(e.getReason())
+ .code(e.getStatus().value())
+ .build();
+ return ResponseEntity.status(e.getStatus()).body(response);
+ }
+
+ @Override
+ protected ResponseEntity