diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8011f1b..4ae9aed 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -42,6 +42,13 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Set up JDK 21 (only for Java) + if: matrix.language == 'java' + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '21' + # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v3 @@ -57,6 +64,9 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). # If this step fails, then you should remove it and run the build manually (see below) + - name: Build with Maven (only for Java) + if: matrix.language =='java' + - name: Autobuild for JavaScript if: matrix.language == 'javascript' uses: github/codeql-action/autobuild@v3 diff --git a/.github/workflows/pull_request_template.yml b/.github/workflows/pull_request_template.yml index 1cf146f..a0eb298 100644 --- a/.github/workflows/pull_request_template.yml +++ b/.github/workflows/pull_request_template.yml @@ -4,6 +4,10 @@ on: pull_request: types: [opened, edited] +permissions: + contents: write + pull-requests: write + jobs: autofill_pr: runs-on: ubuntu-latest diff --git a/cart-service/pom.xml b/cart-service/pom.xml index a79f731..e239533 100644 --- a/cart-service/pom.xml +++ b/cart-service/pom.xml @@ -48,14 +48,8 @@ com.blubin - user-service - ${revision} - compile - - - com.blubin - product-service - ${revision} + common-service + 1.0-SNAPSHOT compile @@ -65,10 +59,14 @@ org.springframework.boot spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-compiler-plugin + 3.3.5 + + + + repackage + + + diff --git a/cart-service/src/main/java/com/blubin/cartservice/CartServiceApplication.java b/cart-service/src/main/java/com/blubin/cartservice/CartServiceApplication.java index af388fc..f1b1f5f 100644 --- a/cart-service/src/main/java/com/blubin/cartservice/CartServiceApplication.java +++ b/cart-service/src/main/java/com/blubin/cartservice/CartServiceApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"com.blubin.commonservice", + "com.blubin.cartservice"}) public class CartServiceApplication { public static void main(String[] args) { diff --git a/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCart.java b/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCart.java index e6cba1e..8621b2e 100644 --- a/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCart.java +++ b/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCart.java @@ -1,22 +1,24 @@ package com.blubin.cartservice.model; -import com.blubin.userservice.model.SiteUser; import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "shopping_cart") public class ShoppingCart { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "cart_id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "cart_id",updatable = false, nullable = false) + private UUID id; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private SiteUser user; + @NotNull + @Column(name = "user_id") + private UUID user; } \ No newline at end of file diff --git a/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCartItem.java b/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCartItem.java index e266ed0..50c6dd4 100644 --- a/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCartItem.java +++ b/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCartItem.java @@ -1,9 +1,12 @@ package com.blubin.cartservice.model; -import com.blubin.productservice.model.ProductItem; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import java.util.UUID; @Getter @Setter @@ -15,14 +18,10 @@ public class ShoppingCartItem { @MapsId("cartId") @ManyToOne(fetch = FetchType.LAZY, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) @JoinColumn(name = "cart_id", nullable = false) private ShoppingCart cart; - @MapsId("productItemId") - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "product_item_id", nullable = false) - private ProductItem productItem; - @Column(name = "quantity") private Integer quantity; diff --git a/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCartItemId.java b/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCartItemId.java index e896430..d75e702 100644 --- a/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCartItemId.java +++ b/cart-service/src/main/java/com/blubin/cartservice/model/ShoppingCartItemId.java @@ -8,6 +8,7 @@ import org.hibernate.Hibernate; import java.util.Objects; +import java.util.UUID; @Getter @Setter @@ -16,11 +17,11 @@ public class ShoppingCartItemId implements java.io.Serializable { private static final long serialVersionUID = -1478894238683425865L; @NotNull @Column(name = "cart_id", nullable = false) - private Integer cartId; + private UUID cartId; @NotNull @Column(name = "product_item_id", nullable = false) - private Integer productItemId; + private UUID productItemId; @Override public boolean equals(Object o) { diff --git a/cart-service/src/main/resources/application.properties b/cart-service/src/main/resources/application.properties deleted file mode 100644 index ec71451..0000000 --- a/cart-service/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=cart-service diff --git a/cart-service/src/main/resources/application.yml b/cart-service/src/main/resources/application.yml index ff64b34..00c10c1 100644 --- a/cart-service/src/main/resources/application.yml +++ b/cart-service/src/main/resources/application.yml @@ -1,6 +1,9 @@ +server: + port: 8085 + spring: application: - name: user_service + name: cart_service datasource: url: jdbc:postgresql://localhost:5432/ecommerce username: postgres diff --git a/common-service/pom.xml b/common-service/pom.xml index b94f6f5..85eb0a1 100644 --- a/common-service/pom.xml +++ b/common-service/pom.xml @@ -8,12 +8,12 @@ ${revision} ../pom.xml + common-service common-service common-service 21 - 1.0-SNAPSHOT @@ -41,13 +41,14 @@ - - org.springframework.boot - spring-boot-maven-plugin - org.apache.maven.plugins maven-compiler-plugin + 3.13.0 + + 21 + 21 + diff --git a/common-service/src/main/java/com/blubin/commonservice/CommonServiceApplication.java b/common-service/src/main/java/com/blubin/commonservice/CommonServiceApplication.java index 6cc6fcc..b87ff89 100644 --- a/common-service/src/main/java/com/blubin/commonservice/CommonServiceApplication.java +++ b/common-service/src/main/java/com/blubin/commonservice/CommonServiceApplication.java @@ -1,13 +1,13 @@ -package com.blubin.commonservice; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class CommonServiceApplication { - - public static void main(String[] args) { - SpringApplication.run(CommonServiceApplication.class, args); - } - -} +//package com.blubin.commonservice; +// +//import org.springframework.boot.SpringApplication; +//import org.springframework.boot.autoconfigure.SpringBootApplication; +// +//@SpringBootApplication +//public class CommonServiceApplication { +// +// public static void main(String[] args) { +// SpringApplication.run(CommonServiceApplication.class, args); +// } +// +//} diff --git a/common-service/src/test/java/com/blubin/commonservice/CommonServiceApplicationTests.java b/common-service/src/test/java/com/blubin/commonservice/CommonServiceApplicationTests.java deleted file mode 100644 index 2f6e914..0000000 --- a/common-service/src/test/java/com/blubin/commonservice/CommonServiceApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.blubin.commonservice; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class CommonServiceApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/docker-compose.yml b/docker-compose.yml index 55fb8be..15b6afa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,34 +1,65 @@ version: "3.8" services: + postgres: + image: postgres:15 + container_name: postgres + hostname: ${POSTGRES_HOST} + restart: always + environment: + - POSTGRES_USER + - POSTGRES_PASSWORD + - POSTGRES_DB + ports: + - "${POSTGRES_PORT}:${POSTGRES_PORT}" + networks: + - spring-cloud-network + + pyadmin: + image: dpage/pgadmin4:2024-10-19-2 + container_name: pyadmin + hostname: pyadmin + restart: always + environment: + - PGADMIN_DEFAULT_EMAIL + - PGADMIN_DEFAULT_PASSWORD + volumes: + - pgadmin:/var/lib/pgadmin + networks: + - spring-cloud-network + identity-service: - build: - context: . - dockerfile: ./identity-service/Dockerfile + build: ./identity-service container_name: identity-service image: identity-service:latest ports: - - "8081:8080" + - "8080:8080" restart: always environment: - - SPRING_PROFILES_ACTIVE=prod + - SPRING_DATASOURCE_URL + depends_on: + - postgres networks: - spring-cloud-network common-service: - build: - context: . - dockerfile: ./common-service/Dockerfile + build: ./common-service container_name: common-service image: common-service:latest ports: - - "8082:8080" + - "8081:8081" restart: always environment: - - SPRING_PROFILES_ACTIVE=prod + - SPRING_DATASOURCE_URL + depends_on: + - postgres networks: - spring-cloud-network networks: spring-cloud-network: - driver: bridge \ No newline at end of file + driver: bridge + +volumes: + postgres: + pgadmin: diff --git a/identity-service/pom.xml b/identity-service/pom.xml index 87ed682..6f82c95 100644 --- a/identity-service/pom.xml +++ b/identity-service/pom.xml @@ -68,55 +68,45 @@ org.springframework.boot spring-boot-starter-oauth2-client - - com.blubin - common-service - ${revision} - compile - - - com.blubin - user-service - ${revision} - compile - + io.github.cdimascio dotenv-java 3.0.0 + + + jakarta.platform + jakarta.jakartaee-api + 10.0.0 + provided + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.blubin + common-service + 1.0-SNAPSHOT + compile + - - - - - - - - - - - - - - - - - - - - - org.springframework.boot spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-compiler-plugin + 3.3.5 + + + + repackage + + + diff --git a/identity-service/src/main/java/com/blubin/identityservice/IdentityServiceApplication.java b/identity-service/src/main/java/com/blubin/identityservice/IdentityServiceApplication.java index d4ed5d9..ecd7b02 100644 --- a/identity-service/src/main/java/com/blubin/identityservice/IdentityServiceApplication.java +++ b/identity-service/src/main/java/com/blubin/identityservice/IdentityServiceApplication.java @@ -6,8 +6,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; @SpringBootApplication(scanBasePackages = {"com.blubin.identityservice", - "com.blubin.commonservice", - "com.blubin.userservice"}) + "com.blubin.commonservice"}) @EnableConfigurationProperties(CorsConfig.class) public class IdentityServiceApplication { diff --git a/identity-service/src/main/java/com/blubin/identityservice/config/CustomUserDetailsService.java b/identity-service/src/main/java/com/blubin/identityservice/config/CustomUserDetailsService.java index 4b3e9f1..71fb267 100644 --- a/identity-service/src/main/java/com/blubin/identityservice/config/CustomUserDetailsService.java +++ b/identity-service/src/main/java/com/blubin/identityservice/config/CustomUserDetailsService.java @@ -1,7 +1,7 @@ package com.blubin.identityservice.config; -import com.blubin.userservice.model.SiteUser; -import com.blubin.userservice.repository.SiteUserRepository; +import com.blubin.identityservice.model.SiteUser; +import com.blubin.identityservice.repository.SiteUserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; diff --git a/identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java b/identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java index 4ceec6d..6ef02d3 100644 --- a/identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java +++ b/identity-service/src/main/java/com/blubin/identityservice/config/OAuth2LoginSuccessHandler.java @@ -1,7 +1,7 @@ package com.blubin.identityservice.config; +import com.blubin.identityservice.model.SiteUser; import com.blubin.identityservice.utils.JwtUtils; -import com.blubin.userservice.model.SiteUser; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; diff --git a/user-service/src/main/java/com/blubin/userservice/controller/UserController.java b/identity-service/src/main/java/com/blubin/identityservice/controller/UserController.java similarity index 76% rename from user-service/src/main/java/com/blubin/userservice/controller/UserController.java rename to identity-service/src/main/java/com/blubin/identityservice/controller/UserController.java index fb237cc..f5b6df8 100644 --- a/user-service/src/main/java/com/blubin/userservice/controller/UserController.java +++ b/identity-service/src/main/java/com/blubin/identityservice/controller/UserController.java @@ -1,8 +1,8 @@ -package com.blubin.userservice.controller; +package com.blubin.identityservice.controller; -import com.blubin.userservice.model.SiteUser; -import com.blubin.userservice.service.SiteUserService; -import com.blubin.userservice.viewmodel.user.SiteUserRequestVM; +import com.blubin.identityservice.model.SiteUser; +import com.blubin.identityservice.service.SiteUserService; +import com.blubin.identityservice.viewmodel.SiteUserRequestVM; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; diff --git a/identity-service/src/main/java/com/blubin/identityservice/model/CustomOidcUserService.java b/identity-service/src/main/java/com/blubin/identityservice/model/CustomOidcUserService.java index e16659b..36c0b2c 100644 --- a/identity-service/src/main/java/com/blubin/identityservice/model/CustomOidcUserService.java +++ b/identity-service/src/main/java/com/blubin/identityservice/model/CustomOidcUserService.java @@ -1,9 +1,7 @@ package com.blubin.identityservice.model; +import com.blubin.identityservice.repository.SiteUserRepository; import com.blubin.identityservice.utils.JwtUtils; -import com.blubin.userservice.model.SiteUser; -import com.blubin.userservice.model.UserRole; -import com.blubin.userservice.repository.SiteUserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.InternalAuthenticationServiceException; import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest; @@ -18,7 +16,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; -import java.util.UUID; @Service public class CustomOidcUserService extends OidcUserService { @@ -28,6 +25,9 @@ public class CustomOidcUserService extends OidcUserService { @Autowired private JwtUtils jwtUtils; + private final String USER_SERVICE_URL = "http://localhost:8082/api/users"; + + public CustomOidcUserService(JwtUtils jwtUtils) { this.jwtUtils = jwtUtils; } @@ -62,6 +62,7 @@ private OidcUser processOidcUser(OidcUserRequest userRequest, OidcUser oidcUser) String email = oidcUser.getAttribute("email"); String name = oidcUser.getAttribute("name"); + Optional userOptional = siteUserRepository.findByEmailAddress(email); SiteUser siteUser; @@ -82,40 +83,4 @@ private OidcUser processOidcUser(OidcUserRequest userRequest, OidcUser oidcUser) claims.put("token", jwt); return new DefaultOidcUser(oidcUser.getAuthorities(), oidcUserAuthority.getIdToken(), new OidcUserInfo(claims)); } - -// private OidcUser processOidcUser(OidcUserRequest userRequest, OidcUser oidcUser) { -// OidcUserAuthority oidcUserAuthority = (OidcUserAuthority) oidcUser.getAuthorities() -// .stream() -// .filter(OidcUserAuthority.class::isInstance) -// .findFirst() -// .orElse(null); -// -// String avatarUrl = null; -// if (oidcUserAuthority != null) { -// OidcUserInfo userInfo = oidcUserAuthority.getUserInfo(); -// if (userInfo != null && userInfo.getClaims() != null) { -// avatarUrl = (String) userInfo.getClaims().get("picture"); -// } else { -// avatarUrl = (String) oidcUserAuthority.getIdToken().getClaims().get("picture"); -// } -// } -// -// GoogleUserInfo googleUserInfo = new GoogleUserInfo(oidcUser.getAttributes()); -// -// String email = oidcUser.getEmail(); -// -// System.out.println(avatarUrl); -// -// Optional userOptional = siteUserRepository.findByEmailAddress(googleUserInfo.getEmail()); -// if (!userOptional.isPresent()) { -// SiteUser user = new SiteUser(); -// user.setEmailAddress(googleUserInfo.getEmail()); -// user.setUserName(googleUserInfo.getName()); -// user.setRole(UserRole.USER); -// user.setPassword(""); -// siteUserRepository.save(user); -// } -// -// return oidcUser; -// } } diff --git a/identity-service/src/main/java/com/blubin/identityservice/model/SiteUser.java b/identity-service/src/main/java/com/blubin/identityservice/model/SiteUser.java new file mode 100644 index 0000000..961a9d1 --- /dev/null +++ b/identity-service/src/main/java/com/blubin/identityservice/model/SiteUser.java @@ -0,0 +1,85 @@ +package com.blubin.identityservice.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.time.Instant; +import java.util.Collection; +import java.util.List; +import java.util.UUID; + +@Getter +@Setter +@Entity +@Table(name = "site_user") +public class SiteUser implements UserDetails { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", updatable = false, nullable = false) + private UUID id; + + @Size(max = 255) + @NotNull + @Column(name = "user_name", nullable = false) + private String userName; + + @Size(max = 255) + @NotNull + @Column(name = "email_address", nullable = false) + private String emailAddress; + + @Size(max = 20) + @Column(name = "phone_number", length = 20) + private String phoneNumber; + + @Size(max = 255) + @NotNull + @Column(name = "password", nullable = false) + private String password; + + @NotNull + @Enumerated(EnumType.STRING) + @Column(name = "role",nullable = false) + private UserRole role = UserRole.USER; + + @ColumnDefault("CURRENT_TIMESTAMP") + @Column(name = "created_at") + private Instant createdAt; + + @Override + public Collection getAuthorities() { + return List.of(new SimpleGrantedAuthority(role.name())); + } + + @Override + public String getUsername() { + return ""; + } + + @Override + public boolean isAccountNonExpired() { + return UserDetails.super.isAccountNonExpired(); + } + + @Override + public boolean isAccountNonLocked() { + return UserDetails.super.isAccountNonLocked(); + } + + @Override + public boolean isCredentialsNonExpired() { + return UserDetails.super.isCredentialsNonExpired(); + } + + @Override + public boolean isEnabled() { + return UserDetails.super.isEnabled(); + } +} \ No newline at end of file diff --git a/user-service/src/main/java/com/blubin/userservice/model/UserRole.java b/identity-service/src/main/java/com/blubin/identityservice/model/UserRole.java similarity index 52% rename from user-service/src/main/java/com/blubin/userservice/model/UserRole.java rename to identity-service/src/main/java/com/blubin/identityservice/model/UserRole.java index 2459071..b915b56 100644 --- a/user-service/src/main/java/com/blubin/userservice/model/UserRole.java +++ b/identity-service/src/main/java/com/blubin/identityservice/model/UserRole.java @@ -1,4 +1,4 @@ -package com.blubin.userservice.model; +package com.blubin.identityservice.model; public enum UserRole { ADMIN, diff --git a/user-service/src/main/java/com/blubin/userservice/repository/SiteUserRepository.java b/identity-service/src/main/java/com/blubin/identityservice/repository/SiteUserRepository.java similarity index 71% rename from user-service/src/main/java/com/blubin/userservice/repository/SiteUserRepository.java rename to identity-service/src/main/java/com/blubin/identityservice/repository/SiteUserRepository.java index a6a771e..9b2aba1 100644 --- a/user-service/src/main/java/com/blubin/userservice/repository/SiteUserRepository.java +++ b/identity-service/src/main/java/com/blubin/identityservice/repository/SiteUserRepository.java @@ -1,13 +1,14 @@ -package com.blubin.userservice.repository; +package com.blubin.identityservice.repository; -import com.blubin.userservice.model.SiteUser; +import com.blubin.identityservice.model.SiteUser; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.Optional; +import java.util.UUID; @Repository -public interface SiteUserRepository extends JpaRepository { +public interface SiteUserRepository extends JpaRepository { boolean existsByEmailAddress(String emailAddress); Optional findByEmailAddress(String emailAddress); } \ No newline at end of file diff --git a/user-service/src/main/java/com/blubin/userservice/service/SiteUserService.java b/identity-service/src/main/java/com/blubin/identityservice/service/SiteUserService.java similarity index 77% rename from user-service/src/main/java/com/blubin/userservice/service/SiteUserService.java rename to identity-service/src/main/java/com/blubin/identityservice/service/SiteUserService.java index c719b46..f4b3d97 100644 --- a/user-service/src/main/java/com/blubin/userservice/service/SiteUserService.java +++ b/identity-service/src/main/java/com/blubin/identityservice/service/SiteUserService.java @@ -1,8 +1,8 @@ -package com.blubin.userservice.service; +package com.blubin.identityservice.service; -import com.blubin.userservice.model.SiteUser; -import com.blubin.userservice.repository.SiteUserRepository; -import com.blubin.userservice.viewmodel.user.SiteUserRequestVM; +import com.blubin.identityservice.model.SiteUser; +import com.blubin.identityservice.repository.SiteUserRepository; +import com.blubin.identityservice.viewmodel.SiteUserRequestVM; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.security.crypto.password.PasswordEncoder; diff --git a/identity-service/src/main/java/com/blubin/identityservice/utils/JwtUtils.java b/identity-service/src/main/java/com/blubin/identityservice/utils/JwtUtils.java index 5a48b74..97af607 100644 --- a/identity-service/src/main/java/com/blubin/identityservice/utils/JwtUtils.java +++ b/identity-service/src/main/java/com/blubin/identityservice/utils/JwtUtils.java @@ -1,6 +1,6 @@ package com.blubin.identityservice.utils; -import com.blubin.userservice.model.SiteUser; +import com.blubin.identityservice.model.SiteUser; import io.jsonwebtoken.security.Keys; import io.jsonwebtoken.*; import jakarta.annotation.PostConstruct; diff --git a/identity-service/src/main/java/com/blubin/identityservice/viewmodel/SiteUserRequestVM.java b/identity-service/src/main/java/com/blubin/identityservice/viewmodel/SiteUserRequestVM.java new file mode 100644 index 0000000..f6300aa --- /dev/null +++ b/identity-service/src/main/java/com/blubin/identityservice/viewmodel/SiteUserRequestVM.java @@ -0,0 +1,21 @@ +package com.blubin.identityservice.viewmodel; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +@JsonSerialize +public record SiteUserRequestVM( + @NotBlank(message = "Email address must not be blank") + @Size(max = 255, message = "Email address must not exceed 255 characters") + String emailAddress, + + @Size(max = 20, message = "Phone number must not exceed 20 characters") + String phoneNumber, + + @NotBlank(message = "Password must not be blank") + @Size(max = 255, message = "Password must not exceed 255 characters") + String password +) {} \ No newline at end of file diff --git a/media-service/pom.xml b/media-service/pom.xml index 9016e29..a0fae6e 100644 --- a/media-service/pom.xml +++ b/media-service/pom.xml @@ -49,29 +49,17 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - - - - org.springframework.boot spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - + 3.3.5 + + + + repackage + + + diff --git a/media-service/src/main/resources/application.properties b/media-service/src/main/resources/application.properties deleted file mode 100644 index c6e959a..0000000 --- a/media-service/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=media-service diff --git a/media-service/src/main/resources/application.yml b/media-service/src/main/resources/application.yml index ff64b34..d0660d1 100644 --- a/media-service/src/main/resources/application.yml +++ b/media-service/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: application: - name: user_service + name: media_service datasource: url: jdbc:postgresql://localhost:5432/ecommerce username: postgres diff --git a/payment-service/pom.xml b/payment-service/pom.xml index 7d7e10c..7647441 100644 --- a/payment-service/pom.xml +++ b/payment-service/pom.xml @@ -48,45 +48,27 @@ com.blubin - user-service - ${revision} - compile - - - com.blubin - product-service + common-service ${revision} compile - - - - - - - - - - - - - - - - - - - - - - - - - - + + + org.springframework.boot + spring-boot-maven-plugin + 3.3.5 + + + + repackage + + + + + diff --git a/payment-service/src/main/java/com/blubin/paymentservice/PaymentServiceApplication.java b/payment-service/src/main/java/com/blubin/paymentservice/PaymentServiceApplication.java index d49e3b1..3face98 100644 --- a/payment-service/src/main/java/com/blubin/paymentservice/PaymentServiceApplication.java +++ b/payment-service/src/main/java/com/blubin/paymentservice/PaymentServiceApplication.java @@ -3,7 +3,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"com.blubin.paymentservice", + "com.blubin.commonservice"}) public class PaymentServiceApplication { public static void main(String[] args) { diff --git a/payment-service/src/main/java/com/blubin/paymentservice/model/OrderLine.java b/payment-service/src/main/java/com/blubin/paymentservice/model/OrderLine.java index 82d4f62..2867faf 100644 --- a/payment-service/src/main/java/com/blubin/paymentservice/model/OrderLine.java +++ b/payment-service/src/main/java/com/blubin/paymentservice/model/OrderLine.java @@ -1,11 +1,11 @@ package com.blubin.paymentservice.model; -import com.blubin.productservice.model.ProductItem; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; import java.math.BigDecimal; +import java.util.UUID; @Getter @Setter @@ -13,17 +13,16 @@ @Table(name = "order_line") public class OrderLine { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "order_line_id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id" ,updatable = false , nullable = false) + private UUID id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "order_id") private ShopOrder order; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "product_item_id") - private ProductItem productItem; + @Column(name = "product_item_id", nullable = false) + private UUID productItemId; @Column(name = "quantity") private Integer quantity; diff --git a/payment-service/src/main/java/com/blubin/paymentservice/model/OrderStatus.java b/payment-service/src/main/java/com/blubin/paymentservice/model/OrderStatus.java index 247fe0a..994a9ff 100644 --- a/payment-service/src/main/java/com/blubin/paymentservice/model/OrderStatus.java +++ b/payment-service/src/main/java/com/blubin/paymentservice/model/OrderStatus.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "order_status") public class OrderStatus { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id",updatable = false, nullable = false) + private UUID id; @Size(max = 100) @NotNull diff --git a/payment-service/src/main/java/com/blubin/paymentservice/model/PaymentType.java b/payment-service/src/main/java/com/blubin/paymentservice/model/PaymentType.java index f409eb3..652a955 100644 --- a/payment-service/src/main/java/com/blubin/paymentservice/model/PaymentType.java +++ b/payment-service/src/main/java/com/blubin/paymentservice/model/PaymentType.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "payment_type") public class PaymentType { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id",updatable = false, nullable = false) + private UUID id; @Size(max = 100) @NotNull diff --git a/payment-service/src/main/java/com/blubin/paymentservice/model/ShippingMethod.java b/payment-service/src/main/java/com/blubin/paymentservice/model/ShippingMethod.java index 2b39bf8..67b6717 100644 --- a/payment-service/src/main/java/com/blubin/paymentservice/model/ShippingMethod.java +++ b/payment-service/src/main/java/com/blubin/paymentservice/model/ShippingMethod.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "shipping_method") public class ShippingMethod { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id",updatable = false, nullable = false) + private UUID id; @Size(max = 100) @NotNull diff --git a/payment-service/src/main/java/com/blubin/paymentservice/model/ShopOrder.java b/payment-service/src/main/java/com/blubin/paymentservice/model/ShopOrder.java index 317ee8c..db92ae6 100644 --- a/payment-service/src/main/java/com/blubin/paymentservice/model/ShopOrder.java +++ b/payment-service/src/main/java/com/blubin/paymentservice/model/ShopOrder.java @@ -1,6 +1,5 @@ package com.blubin.paymentservice.model; -import com.blubin.userservice.model.SiteUser; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.Getter; @@ -8,6 +7,7 @@ import java.math.BigDecimal; import java.time.Instant; +import java.util.UUID; @Getter @Setter @@ -15,13 +15,12 @@ @Table(name = "shop_order") public class ShopOrder { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "order_id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "order_id",updatable = false, nullable = false) + private UUID id; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private SiteUser user; + @Column(name = "user_id") + private UUID user; @NotNull @Column(name = "order_date", nullable = false) diff --git a/payment-service/src/main/java/com/blubin/paymentservice/model/UserPaymentMethod.java b/payment-service/src/main/java/com/blubin/paymentservice/model/UserPaymentMethod.java index 2cef81e..d3e4197 100644 --- a/payment-service/src/main/java/com/blubin/paymentservice/model/UserPaymentMethod.java +++ b/payment-service/src/main/java/com/blubin/paymentservice/model/UserPaymentMethod.java @@ -1,13 +1,14 @@ package com.blubin.paymentservice.model; -import com.blubin.userservice.model.SiteUser; import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Getter; import lombok.Setter; import org.hibernate.annotations.ColumnDefault; import java.time.LocalDate; +import java.util.UUID; @Getter @Setter @@ -15,13 +16,13 @@ @Table(name = "user_payment_method") public class UserPaymentMethod { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id",updatable = false, nullable = false) + private UUID id; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private SiteUser user; + @NotNull + @Column(name = "user_id") + private UUID user; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "payment_type_id") diff --git a/payment-service/src/main/resources/application.properties b/payment-service/src/main/resources/application.properties deleted file mode 100644 index 85f2700..0000000 --- a/payment-service/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=payment-service diff --git a/payment-service/src/main/resources/application.yml b/payment-service/src/main/resources/application.yml index ff64b34..e649df0 100644 --- a/payment-service/src/main/resources/application.yml +++ b/payment-service/src/main/resources/application.yml @@ -1,6 +1,9 @@ +server: + port: 8086 + spring: application: - name: user_service + name: payment_service datasource: url: jdbc:postgresql://localhost:5432/ecommerce username: postgres diff --git a/pom.xml b/pom.xml index 3967211..abb71c0 100644 --- a/pom.xml +++ b/pom.xml @@ -2,12 +2,6 @@ 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.3.5 - - com.blubin shopping-overflow @@ -16,12 +10,11 @@ shopping-overflow - common-service identity-service user-service product-service - + cart-service media-service payment-service promotion-service @@ -33,7 +26,6 @@ 21 21 21 - 1.0-SNAPSHOT 2.0.2 @@ -60,6 +52,21 @@ + + org.springframework.boot + spring-boot-dependencies + 3.3.5 + pom + import + + + + org.springframework.boot + spring-boot-starter-parent + 3.3.5 + pom + import + net.logstash.logback logstash-logback-encoder @@ -140,18 +147,6 @@ ${testcontainers-keycloak.version} test - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - io.jsonwebtoken jjwt-impl @@ -246,10 +241,6 @@ org.springframework.boot spring-boot-starter-oauth2-client - - - - org.springframework.boot spring-boot-starter-oauth2-authorization-server @@ -289,7 +280,7 @@ org.projectlombok lombok - ${lombok.version} + ${org.lombok.version} org.projectlombok @@ -372,57 +363,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + org.springframework.boot + spring-boot-maven-plugin + + \ No newline at end of file diff --git a/product-service/Dockerfile b/product-service/Dockerfile index 26ce422..5d96b32 100644 --- a/product-service/Dockerfile +++ b/product-service/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:17-jdk-alpine +FROM eclipse-temurin:21-jre-alpine LABEL authors="blubin" COPY target/product-service*.jar app.jar ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file diff --git a/product-service/pom.xml b/product-service/pom.xml index 0477b0a..08c1d3b 100644 --- a/product-service/pom.xml +++ b/product-service/pom.xml @@ -58,10 +58,14 @@ org.springframework.boot spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-compiler-plugin + 3.3.5 + + + + repackage + + + diff --git a/product-service/src/main/java/com/blubin/productservice/ProductServiceApplication.java b/product-service/src/main/java/com/blubin/productservice/ProductServiceApplication.java index fd208cc..f53dbc3 100644 --- a/product-service/src/main/java/com/blubin/productservice/ProductServiceApplication.java +++ b/product-service/src/main/java/com/blubin/productservice/ProductServiceApplication.java @@ -3,7 +3,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"com.blubin.productservice", + "com.blubin.commonservice"}) public class ProductServiceApplication { public static void main(String[] args) { diff --git a/product-service/src/main/java/com/blubin/productservice/controller/BrandController.java b/product-service/src/main/java/com/blubin/productservice/controller/BrandController.java index 5f88f2d..b603831 100644 --- a/product-service/src/main/java/com/blubin/productservice/controller/BrandController.java +++ b/product-service/src/main/java/com/blubin/productservice/controller/BrandController.java @@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.util.UriComponentsBuilder; +import java.util.UUID; + @RestController public class BrandController { private static final Logger log = LoggerFactory.getLogger(BrandController.class); @@ -66,7 +68,7 @@ public ResponseEntity getPagingBrands( content = @Content(schema = @Schema(implementation = ErrorVm.class))), @ApiResponse(responseCode = "400", description = "Bad request", content = @Content(schema = @Schema(implementation = ErrorVm.class)))}) - public ResponseEntity updateBrand(@PathVariable Long id, @Valid @RequestBody final BrandPostVm brandPostVm) { + public ResponseEntity updateBrand(@PathVariable UUID id, @Valid @RequestBody final BrandPostVm brandPostVm) { brandService.update(brandPostVm, id); return ResponseEntity.noContent().build(); } @@ -78,7 +80,7 @@ public ResponseEntity updateBrand(@PathVariable Long id, @Valid @RequestBo content = @Content(schema = @Schema(implementation = ErrorVm.class))), @ApiResponse(responseCode = "400", description = "Bad request", content = @Content(schema = @Schema(implementation = ErrorVm.class)))}) - public ResponseEntity deleteBrand(@PathVariable Long id) { + public ResponseEntity deleteBrand(@PathVariable UUID id) { brandService.delete(id); return ResponseEntity.noContent().build(); } diff --git a/product-service/src/main/java/com/blubin/productservice/controller/ColourController.java b/product-service/src/main/java/com/blubin/productservice/controller/ColourController.java index 31f03b4..265b64c 100644 --- a/product-service/src/main/java/com/blubin/productservice/controller/ColourController.java +++ b/product-service/src/main/java/com/blubin/productservice/controller/ColourController.java @@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.util.UriComponentsBuilder; +import java.util.UUID; + @RestController public class ColourController { private static final Logger log = LoggerFactory.getLogger(ColourController.class); @@ -63,7 +65,7 @@ public ResponseEntity getPagingColour( content = @Content(schema = @Schema(implementation = ErrorVm.class))), @ApiResponse(responseCode = "400", description = "Bad request", content = @Content(schema = @Schema(implementation = ErrorVm.class)))}) - public ResponseEntity updateColour(@PathVariable Long id, @Valid @RequestBody final ColourPostVm colourPostVm) { + public ResponseEntity updateColour(@PathVariable UUID id, @Valid @RequestBody final ColourPostVm colourPostVm) { colourService.update(colourPostVm, id); return ResponseEntity.noContent().build(); } diff --git a/product-service/src/main/java/com/blubin/productservice/model/AttributeOption.java b/product-service/src/main/java/com/blubin/productservice/model/AttributeOption.java index 68c155b..39c3776 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/AttributeOption.java +++ b/product-service/src/main/java/com/blubin/productservice/model/AttributeOption.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "attribute_option") public class AttributeOption { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "attribute_option_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "attribute_option_id",updatable = false, nullable = false) + private UUID id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "attribute_type_id") diff --git a/product-service/src/main/java/com/blubin/productservice/model/AttributeType.java b/product-service/src/main/java/com/blubin/productservice/model/AttributeType.java index 5aaf7c4..0d1d629 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/AttributeType.java +++ b/product-service/src/main/java/com/blubin/productservice/model/AttributeType.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "attribute_type") public class AttributeType { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "attribute_type_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "attribute_type_id",updatable = false, nullable = false) + private UUID id; @Size(max = 100) @NotNull diff --git a/product-service/src/main/java/com/blubin/productservice/model/Brand.java b/product-service/src/main/java/com/blubin/productservice/model/Brand.java index 87bd44c..06e43a9 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/Brand.java +++ b/product-service/src/main/java/com/blubin/productservice/model/Brand.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "brand") public class Brand { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "brand_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "brand_id",updatable = false, nullable = false) + private UUID id; @Size(max = 200) @NotNull diff --git a/product-service/src/main/java/com/blubin/productservice/model/Colour.java b/product-service/src/main/java/com/blubin/productservice/model/Colour.java index 08c2747..886afd8 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/Colour.java +++ b/product-service/src/main/java/com/blubin/productservice/model/Colour.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "colour") public class Colour { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "colour_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "colour_id",updatable = false, nullable = false) + private UUID id; @Size(max = 100) @NotNull diff --git a/product-service/src/main/java/com/blubin/productservice/model/Product.java b/product-service/src/main/java/com/blubin/productservice/model/Product.java index 0c2a899..9707b17 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/Product.java +++ b/product-service/src/main/java/com/blubin/productservice/model/Product.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "product") public class Product { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "product_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "product_id",updatable = false, nullable = false) + private UUID id; @Size(max = 500) @NotNull diff --git a/product-service/src/main/java/com/blubin/productservice/model/ProductAttributeId.java b/product-service/src/main/java/com/blubin/productservice/model/ProductAttributeId.java index 901b121..8075b9c 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/ProductAttributeId.java +++ b/product-service/src/main/java/com/blubin/productservice/model/ProductAttributeId.java @@ -8,6 +8,7 @@ import org.hibernate.Hibernate; import java.util.Objects; +import java.util.UUID; @Getter @Setter @@ -16,11 +17,11 @@ public class ProductAttributeId implements java.io.Serializable { private static final long serialVersionUID = -5905382189716996702L; @NotNull @Column(name = "product_id", nullable = false) - private Long productId; + private UUID productId; @NotNull - @Column(name = "attribute_option_id", nullable = false) - private Long attributeOptionId; + @Column(name = "attribute_option_id",updatable = false, nullable = false) + private UUID attributeOptionId; @Override public boolean equals(Object o) { diff --git a/product-service/src/main/java/com/blubin/productservice/model/ProductCategory.java b/product-service/src/main/java/com/blubin/productservice/model/ProductCategory.java index 0f3168b..c694c3a 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/ProductCategory.java +++ b/product-service/src/main/java/com/blubin/productservice/model/ProductCategory.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "product_category") public class ProductCategory { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "product_category_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "product_category_id",updatable = false, nullable = false) + private UUID id; @Size(max = 100) @NotNull @@ -29,7 +31,7 @@ public class ProductCategory { private String categoryDescription; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "parent_product_category_id") + @JoinColumn(name = "parent_product_category_id", referencedColumnName = "product_category_id") private ProductCategory parentProductCategory; } \ No newline at end of file diff --git a/product-service/src/main/java/com/blubin/productservice/model/ProductImage.java b/product-service/src/main/java/com/blubin/productservice/model/ProductImage.java index a9329bd..ef6287b 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/ProductImage.java +++ b/product-service/src/main/java/com/blubin/productservice/model/ProductImage.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "product_image") public class ProductImage { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "image_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "image_id",updatable = false, nullable = false) + private UUID id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "product_id") diff --git a/product-service/src/main/java/com/blubin/productservice/model/ProductItem.java b/product-service/src/main/java/com/blubin/productservice/model/ProductItem.java index f6250ef..f3a8a3f 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/ProductItem.java +++ b/product-service/src/main/java/com/blubin/productservice/model/ProductItem.java @@ -7,6 +7,7 @@ import lombok.Setter; import java.math.BigDecimal; +import java.util.UUID; @Getter @Setter @@ -14,9 +15,9 @@ @Table(name = "product_item") public class ProductItem { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "product_item_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "product_item_id",updatable = false, nullable = false) + private UUID id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "product_id") diff --git a/product-service/src/main/java/com/blubin/productservice/model/ProductVariation.java b/product-service/src/main/java/com/blubin/productservice/model/ProductVariation.java index f634117..3b17e2d 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/ProductVariation.java +++ b/product-service/src/main/java/com/blubin/productservice/model/ProductVariation.java @@ -4,15 +4,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "product_variation") public class ProductVariation { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "variation_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "variation_id",updatable = false, nullable = false) + private UUID id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "product_item_id") diff --git a/product-service/src/main/java/com/blubin/productservice/model/SizeCategory.java b/product-service/src/main/java/com/blubin/productservice/model/SizeCategory.java index 9b44ce6..73f3cce 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/SizeCategory.java +++ b/product-service/src/main/java/com/blubin/productservice/model/SizeCategory.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "size_category") public class SizeCategory { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "category_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "category_id",updatable = false, nullable = false) + private UUID id; @Size(max = 100) @NotNull diff --git a/product-service/src/main/java/com/blubin/productservice/model/SizeOption.java b/product-service/src/main/java/com/blubin/productservice/model/SizeOption.java index 0d9a77e..375a341 100644 --- a/product-service/src/main/java/com/blubin/productservice/model/SizeOption.java +++ b/product-service/src/main/java/com/blubin/productservice/model/SizeOption.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "size_option") public class SizeOption { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "size_id", nullable = false) - private Long id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "size_id",updatable = false, nullable = false) + private UUID id; @Size(max = 100) @NotNull diff --git a/product-service/src/main/java/com/blubin/productservice/repository/AttributeTypeRepository.java b/product-service/src/main/java/com/blubin/productservice/repository/AttributeTypeRepository.java index 3a3ba50..88b572d 100644 --- a/product-service/src/main/java/com/blubin/productservice/repository/AttributeTypeRepository.java +++ b/product-service/src/main/java/com/blubin/productservice/repository/AttributeTypeRepository.java @@ -4,6 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.UUID; + @Repository -public interface AttributeTypeRepository extends JpaRepository { +public interface AttributeTypeRepository extends JpaRepository { } diff --git a/product-service/src/main/java/com/blubin/productservice/repository/BrandRepository.java b/product-service/src/main/java/com/blubin/productservice/repository/BrandRepository.java index 7947fa1..791c8b8 100644 --- a/product-service/src/main/java/com/blubin/productservice/repository/BrandRepository.java +++ b/product-service/src/main/java/com/blubin/productservice/repository/BrandRepository.java @@ -5,9 +5,11 @@ import org.springframework.stereotype.Repository; import org.springframework.data.jpa.repository.Query; +import java.util.UUID; + @Repository -public interface BrandRepository extends JpaRepository { +public interface BrandRepository extends JpaRepository { @Query("select e from Brand e where e.brandName = ?1 and (?2 is null or e.id != ?2)") - Brand findExistedName(String brandName, Long id); + Brand findExistedName(String brandName, UUID id); } diff --git a/product-service/src/main/java/com/blubin/productservice/repository/ColourRepository.java b/product-service/src/main/java/com/blubin/productservice/repository/ColourRepository.java index 439c8ec..dbe2743 100644 --- a/product-service/src/main/java/com/blubin/productservice/repository/ColourRepository.java +++ b/product-service/src/main/java/com/blubin/productservice/repository/ColourRepository.java @@ -5,9 +5,11 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.UUID; + @Repository -public interface ColourRepository extends JpaRepository { +public interface ColourRepository extends JpaRepository { @Query("select e from Colour e where e.hexCode = ?1 and (?2 is null or e.id != ?2)") - Colour findExistedHexCode(String hexCode, Long id); + Colour findExistedHexCode(String hexCode, UUID id); } diff --git a/product-service/src/main/java/com/blubin/productservice/repository/ProductCategoryRepository.java b/product-service/src/main/java/com/blubin/productservice/repository/ProductCategoryRepository.java index 88d5533..a16462f 100644 --- a/product-service/src/main/java/com/blubin/productservice/repository/ProductCategoryRepository.java +++ b/product-service/src/main/java/com/blubin/productservice/repository/ProductCategoryRepository.java @@ -5,9 +5,11 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.UUID; + @Repository -public interface ProductCategoryRepository extends JpaRepository { +public interface ProductCategoryRepository extends JpaRepository { @Query("select e from ProductCategory e where e.categoryName = ?1 and (?2 is null or e.id != ?2)") - ProductCategory findExistedName(String categoryName, Long id); + ProductCategory findExistedName(String categoryName, UUID id); } diff --git a/product-service/src/main/java/com/blubin/productservice/repository/ProductImageRepository.java b/product-service/src/main/java/com/blubin/productservice/repository/ProductImageRepository.java index 66b7dd2..5b74464 100644 --- a/product-service/src/main/java/com/blubin/productservice/repository/ProductImageRepository.java +++ b/product-service/src/main/java/com/blubin/productservice/repository/ProductImageRepository.java @@ -4,6 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.UUID; + @Repository -public interface ProductImageRepository extends JpaRepository { +public interface ProductImageRepository extends JpaRepository { } diff --git a/product-service/src/main/java/com/blubin/productservice/repository/ProductItemRepository.java b/product-service/src/main/java/com/blubin/productservice/repository/ProductItemRepository.java index 6b9c916..64ccfc1 100644 --- a/product-service/src/main/java/com/blubin/productservice/repository/ProductItemRepository.java +++ b/product-service/src/main/java/com/blubin/productservice/repository/ProductItemRepository.java @@ -4,6 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.UUID; + @Repository -public interface ProductItemRepository extends JpaRepository { +public interface ProductItemRepository extends JpaRepository { } diff --git a/product-service/src/main/java/com/blubin/productservice/repository/ProductRepository.java b/product-service/src/main/java/com/blubin/productservice/repository/ProductRepository.java index 0f82b35..45fd9e4 100644 --- a/product-service/src/main/java/com/blubin/productservice/repository/ProductRepository.java +++ b/product-service/src/main/java/com/blubin/productservice/repository/ProductRepository.java @@ -4,7 +4,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.UUID; + @Repository -public interface ProductRepository extends JpaRepository { +public interface ProductRepository extends JpaRepository { } diff --git a/product-service/src/main/java/com/blubin/productservice/service/BrandService.java b/product-service/src/main/java/com/blubin/productservice/service/BrandService.java index 27c567d..f98adb7 100644 --- a/product-service/src/main/java/com/blubin/productservice/service/BrandService.java +++ b/product-service/src/main/java/com/blubin/productservice/service/BrandService.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; @Service @Transactional @@ -26,11 +27,11 @@ public BrandService(BrandRepository brandRepository) { this.brandRepository = brandRepository; } - private boolean checkExistedName(String brandName, Long id) { + private boolean checkExistedName(String brandName, UUID id) { return brandRepository.findExistedName(brandName, id) != null; } - private void validExistedName(String brandName, Long brandId) { + private void validExistedName(String brandName, UUID brandId) { if(checkExistedName(brandName, brandId)) { throw new DuplicatedException(Constants.ErrorCodes.NAME_ALREADY_EXITED,brandName); } @@ -62,7 +63,7 @@ public BrandListGetVm getBrandList(int pageNo, int pageSize) { ); } - public Brand update(BrandPostVm brandPostVm, Long id) { + public Brand update(BrandPostVm brandPostVm, UUID id) { validExistedName(brandPostVm.name(), id); Brand brand = brandRepository @@ -74,7 +75,7 @@ public Brand update(BrandPostVm brandPostVm, Long id) { return brandRepository.save(brand); } - public void delete(Long id) { + public void delete(UUID id) { Brand brand = brandRepository.findById(id).orElseThrow( () -> new NotFoundException(Constants.ErrorCodes.BRAND_NOT_FOUND, id)); // if (!brand.getProducts().isEmpty()) { diff --git a/product-service/src/main/java/com/blubin/productservice/service/ColourService.java b/product-service/src/main/java/com/blubin/productservice/service/ColourService.java index 8e07603..f20fd28 100644 --- a/product-service/src/main/java/com/blubin/productservice/service/ColourService.java +++ b/product-service/src/main/java/com/blubin/productservice/service/ColourService.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; @Service public class ColourService { @@ -26,11 +27,11 @@ public ColourService(ColourRepository colourRepository) { } - private boolean checkExistedHexCode(String hexCode, Long id) { + private boolean checkExistedHexCode(String hexCode, UUID id) { return colourRepository.findExistedHexCode(hexCode, id) != null; } - private void validExistedName(String hexCode, Long ColourId) { + private void validExistedName(String hexCode, UUID ColourId) { if(checkExistedHexCode(hexCode, ColourId)) { throw new DuplicatedException(Constants.ErrorCodes.HEX_CODE_ALREADY_EXITED,hexCode); } @@ -63,7 +64,7 @@ public ColourListGetVm getColourList(int pageNo, int pageSize) { } - public Colour update(ColourPostVm ColourPostVm, Long id) { + public Colour update(ColourPostVm ColourPostVm, UUID id) { validExistedName(ColourPostVm.hexCode(), id); Colour Colour = colourRepository diff --git a/product-service/src/main/java/com/blubin/productservice/service/ProductCategoryService.java b/product-service/src/main/java/com/blubin/productservice/service/ProductCategoryService.java index 9d2f957..445d6b0 100644 --- a/product-service/src/main/java/com/blubin/productservice/service/ProductCategoryService.java +++ b/product-service/src/main/java/com/blubin/productservice/service/ProductCategoryService.java @@ -7,6 +7,8 @@ import com.blubin.productservice.viewmodel.productcategory.ProductCategoryPostVm; import org.springframework.stereotype.Service; +import java.util.UUID; + @Service public class ProductCategoryService { private final ProductCategoryRepository productCategoryRepository; @@ -15,11 +17,11 @@ public ProductCategoryService(ProductCategoryRepository productCategoryRepositor this.productCategoryRepository = productCategoryRepository; } - private boolean checkExistedName(String categoryName, Long id) { + private boolean checkExistedName(String categoryName, UUID id) { return productCategoryRepository.findExistedName(categoryName, id) != null; } - private void validExistedName(String categoryName, Long categoryId) { + private void validExistedName(String categoryName, UUID categoryId) { if(checkExistedName(categoryName, categoryId)) { throw new DuplicatedException(Constants.ErrorCodes.CATEGORY_NAME_ALREADY_EXITED,categoryName); } diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributeoption/AttributeOptionGetVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributeoption/AttributeOptionGetVm.java index e5fcbf1..76de434 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributeoption/AttributeOptionGetVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributeoption/AttributeOptionGetVm.java @@ -3,9 +3,11 @@ import com.blubin.productservice.model.AttributeOption; import com.blubin.productservice.viewmodel.attribute.attributetype.AttributeTypeGetVm; -public record AttributeOptionGetVm(Long id, +import java.util.UUID; + +public record AttributeOptionGetVm(UUID id, AttributeTypeGetVm attributeTypeGetVm, - String attributeOptionName) { + String attributeOptionName) { public static AttributeOptionGetVm fromModel(AttributeOption attributeOption) { return new AttributeOptionGetVm( attributeOption.getId(), diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributeoption/AttributeOptionPostVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributeoption/AttributeOptionPostVm.java index 150c21e..b368b6a 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributeoption/AttributeOptionPostVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributeoption/AttributeOptionPostVm.java @@ -3,8 +3,10 @@ import com.blubin.productservice.model.AttributeOption; import com.blubin.productservice.model.AttributeType; -public record AttributeOptionPostVm(Long id, - Long attributeTypeId, +import java.util.UUID; + +public record AttributeOptionPostVm(UUID id, + UUID attributeTypeId, String attributeOptionName) { public AttributeOption toModel(AttributeType attributeType) { AttributeOption attributeOption = new AttributeOption(); diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributetype/AttributeTypeGetVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributetype/AttributeTypeGetVm.java index 22162dc..e387b07 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributetype/AttributeTypeGetVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributetype/AttributeTypeGetVm.java @@ -3,7 +3,9 @@ import com.blubin.productservice.model.AttributeType; import net.logstash.logback.encoder.com.lmax.disruptor.dsl.ProducerType; -public record AttributeTypeGetVm(Long id, String attributeName) { +import java.util.UUID; + +public record AttributeTypeGetVm(UUID id, String attributeName) { public static AttributeTypeGetVm fromModel(AttributeType attributeType) { return new AttributeTypeGetVm(attributeType.getId(),attributeType.getAttributeName()); } diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributetype/AttributeTypePostVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributetype/AttributeTypePostVm.java index 6e619cf..80e2f51 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributetype/AttributeTypePostVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/attribute/attributetype/AttributeTypePostVm.java @@ -2,7 +2,9 @@ import com.blubin.productservice.model.AttributeType; -public record AttributeTypePostVm(Long id, String attributeName) { +import java.util.UUID; + +public record AttributeTypePostVm(UUID id, String attributeName) { public AttributeType toModel(){ AttributeType attributeType = new AttributeType(); attributeType.setId(this.id); diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/brand/BrandGetVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/brand/BrandGetVm.java index 2436960..712fd00 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/brand/BrandGetVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/brand/BrandGetVm.java @@ -2,7 +2,9 @@ import com.blubin.productservice.model.Brand; -public record BrandGetVm(Long id, String name, String description) { +import java.util.UUID; + +public record BrandGetVm(UUID id, String name, String description) { public static BrandGetVm fromModel(Brand brand) { return new BrandGetVm(brand.getId(), brand.getBrandName(), brand.getBrandDescription()); } diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/brand/BrandPostVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/brand/BrandPostVm.java index e75d289..7ca294e 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/brand/BrandPostVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/brand/BrandPostVm.java @@ -2,7 +2,9 @@ import com.blubin.productservice.model.Brand; -public record BrandPostVm(Long id, String name, String description) { +import java.util.UUID; + +public record BrandPostVm(UUID id, String name, String description) { public Brand toModel(){ Brand brand = new Brand(); brand.setId(id); diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/colour/ColourGetVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/colour/ColourGetVm.java index de5b438..6c6174a 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/colour/ColourGetVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/colour/ColourGetVm.java @@ -2,7 +2,9 @@ import com.blubin.productservice.model.Colour; -public record ColourGetVm(Long id, String colourName, String hexCode) { +import java.util.UUID; + +public record ColourGetVm(UUID id, String colourName, String hexCode) { public static ColourGetVm fromModel(Colour colour) { return new ColourGetVm(colour.getId(), colour.getColourName(), colour.getHexCode()); } diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/colour/ColourPostVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/colour/ColourPostVm.java index 94eaa87..9f2dde5 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/colour/ColourPostVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/colour/ColourPostVm.java @@ -2,7 +2,9 @@ import com.blubin.productservice.model.Colour; -public record ColourPostVm(Long id, String colourName, String hexCode) { +import java.util.UUID; + +public record ColourPostVm(UUID id, String colourName, String hexCode) { public Colour toModel() { Colour colour = new Colour(); colour.setId(id); diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/product/ProductGetVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/product/ProductGetVm.java index 9404600..ab39ac9 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/product/ProductGetVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/product/ProductGetVm.java @@ -4,8 +4,10 @@ import com.blubin.productservice.viewmodel.brand.BrandGetVm; import com.blubin.productservice.viewmodel.productcategory.ProductCategoryGetVm; +import java.util.UUID; + public record ProductGetVm( - Long id, + UUID id, String productName, ProductCategoryGetVm productCategory, String productDescription, diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/product/ProductPostVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/product/ProductPostVm.java index ecefd11..a609f5c 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/product/ProductPostVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/product/ProductPostVm.java @@ -4,6 +4,8 @@ import com.blubin.productservice.model.Product; import com.blubin.productservice.model.ProductCategory; +import java.util.UUID; + public record ProductPostVm( String productName, String productDescription, @@ -11,8 +13,8 @@ public record ProductPostVm( String modelWearing, String careInstructions, String about, - Long productCategoryId, - Long brandId + UUID productCategoryId, + UUID brandId ) { public Product toModel(ProductCategory productCategory, Brand brand) { Product product = new Product(); diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/productcategory/ProductCategoryGetVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/productcategory/ProductCategoryGetVm.java index 6a78f67..d3beb8e 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/productcategory/ProductCategoryGetVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/productcategory/ProductCategoryGetVm.java @@ -2,7 +2,9 @@ import com.blubin.productservice.model.ProductCategory; -public record ProductCategoryGetVm (Long id, String categoryName, String categoryImage, String categoryDescription) { +import java.util.UUID; + +public record ProductCategoryGetVm (UUID id, String categoryName, String categoryImage, String categoryDescription) { public static ProductCategoryGetVm fromModel(ProductCategory productCategory) { return new ProductCategoryGetVm(productCategory.getId(),productCategory.getCategoryName(), productCategory.getCategoryImage(),productCategory.getCategoryDescription()); diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/productcategory/ProductCategoryPostVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/productcategory/ProductCategoryPostVm.java index 4a0a243..8a2d408 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/productcategory/ProductCategoryPostVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/productcategory/ProductCategoryPostVm.java @@ -2,7 +2,9 @@ import com.blubin.productservice.model.ProductCategory; -public record ProductCategoryPostVm(Long id, String categoryName, String categoryImage, String categoryDescription) { +import java.util.UUID; + +public record ProductCategoryPostVm(UUID id, String categoryName, String categoryImage, String categoryDescription) { public ProductCategory toModel(){ ProductCategory productCategory = new ProductCategory(); productCategory.setId(id); diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/productimage/ProductImageGetVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/productimage/ProductImageGetVm.java index b6714c0..92fdfd9 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/productimage/ProductImageGetVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/productimage/ProductImageGetVm.java @@ -4,8 +4,10 @@ import com.blubin.productservice.viewmodel.product.ProductGetVm; import com.blubin.productservice.viewmodel.productitem.ProductItemGetVm; +import java.util.UUID; + public record ProductImageGetVm( - Long productImageId, + UUID productImageId, ProductGetVm product, String imageFilename, ProductItemGetVm productItem) { diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/productimage/ProductImagePostVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/productimage/ProductImagePostVm.java index edddd7a..c3cffc9 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/productimage/ProductImagePostVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/productimage/ProductImagePostVm.java @@ -4,10 +4,12 @@ import com.blubin.productservice.model.ProductImage; import com.blubin.productservice.model.ProductItem; -public record ProductImagePostVm(Long productImageId, - Long productId, +import java.util.UUID; + +public record ProductImagePostVm(UUID productImageId, + UUID productId, String imageFilename, - Long productItemId) { + UUID productItemId) { public ProductImage toModel(Product product, ProductItem productItem) { ProductImage productImage = new ProductImage(); productImage.setId(productImageId); diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/productitem/ProductItemGetVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/productitem/ProductItemGetVm.java index d7fe6f8..d405134 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/productitem/ProductItemGetVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/productitem/ProductItemGetVm.java @@ -5,8 +5,9 @@ import com.blubin.productservice.viewmodel.product.ProductGetVm; import java.math.BigDecimal; +import java.util.UUID; -public record ProductItemGetVm(Long productId, +public record ProductItemGetVm(UUID productId, ProductGetVm productGetVm, ColourGetVm colourGetVm, BigDecimal originalPrice, diff --git a/product-service/src/main/java/com/blubin/productservice/viewmodel/productitem/ProductItemPostVm.java b/product-service/src/main/java/com/blubin/productservice/viewmodel/productitem/ProductItemPostVm.java index f46a1c7..2bd2bab 100644 --- a/product-service/src/main/java/com/blubin/productservice/viewmodel/productitem/ProductItemPostVm.java +++ b/product-service/src/main/java/com/blubin/productservice/viewmodel/productitem/ProductItemPostVm.java @@ -5,10 +5,11 @@ import com.blubin.productservice.model.ProductItem; import java.math.BigDecimal; +import java.util.UUID; -public record ProductItemPostVm(Long id, - Long productId, - Long colourId, +public record ProductItemPostVm(UUID id, + UUID productId, + UUID colourId, BigDecimal originalPrice, BigDecimal salePrice, String productCode) { diff --git a/product-service/src/main/resources/application.properties b/product-service/src/main/resources/application.properties deleted file mode 100644 index 4be1a9b..0000000 --- a/product-service/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=product-service diff --git a/product-service/src/main/resources/application.yml b/product-service/src/main/resources/application.yml index 5b14898..023fbad 100644 --- a/product-service/src/main/resources/application.yml +++ b/product-service/src/main/resources/application.yml @@ -3,7 +3,7 @@ server: spring: application: - name: user_service + name: product_service datasource: url: jdbc:postgresql://localhost:5432/ecommerce username: postgres diff --git a/product-service/src/main/resources/test/main.py b/product-service/src/main/resources/test/main.py deleted file mode 100644 index f345cf7..0000000 --- a/product-service/src/main/resources/test/main.py +++ /dev/null @@ -1,95 +0,0 @@ -Middle ware - -import logging - -logger = logging.getLogger(__name__) - -@app.exception_handler(AppException) -async def app_exception_handler(request: Request, exc: AppException): - logger.error(f"Error {exc.status_code}: {exc.detail} | Trace ID: {exc.trace_id}") - return JSONResponse( - status_code=exc.status_code, - content={ - "status_code": exc.status_code, - "title": exc.title, - "detail": exc.detail, - "field_errors": exc.field_errors, - "trace_id": exc.trace_id, - } - ) - -Base Excep - -class AppException(Exception): - def __init__(self, status_code: int, title: str, detail: str, field_errors: Optional[List[str]] = None): - self.error_response = ErrorResponse( - status_code=status_code, - title=title, - detail=detail, - field_errors=field_errors or [] - ) - - -Error Res - -from typing import List, Optional -from pydantic import BaseModel -import uuid - -class ErrorResponse(BaseModel): - status_code: int - title: str - detail: str - field_errors: Optional[List[str]] = [] - trace_id: str - - def __init__(self, **data): - super().__init__(trace_id=str(uuid.uuid4()), **data) - - -router - - -@router.get("/chat-sessions", response_model=APIResponse, status_code=status.HTTP_200_OK) -def get_chat_sessions( - db_session: Session = Depends(get_db_session), user: User = Depends(get_current_user_from_token) -) -> BackendAPIResponse: - """ - Get all chat sessions of the user. - - Args: - db_session (Session): Database session. Defaults to relational database session. - user (User): User object - - Returns: - BackendAPIResponse: API response. - """ - if not user: - status_code, detail = ErrorCodesMappingNumber.UNAUTHORIZED_REQUEST.value - raise AppException( - status_code=status_code, - title="Unauthorized Request", - detail=detail, - trace_id="trace-12345" - ) - - # Get chat sessions of user - chat_sessions, err = ChatService(db_session=db_session).get_chat_sessions(user_id=user.id) - if err: - status_code, detail = err.kind - raise AppException( - status_code=status_code, - title="Database Error", - detail=detail, - trace_id="trace-67890" - ) - - # Parse chat sessions - data = [ChatSessionResponse.model_validate(chat_session) for chat_session in chat_sessions] if chat_sessions else [] - - return ( - BackendAPIResponse() - .set_message(message=Constants.API_SUCCESS) - .set_data(data=data) - .respond() - ) \ No newline at end of file diff --git a/product-service/src/main/resources/test/test.py b/product-service/src/main/resources/test/test.py deleted file mode 100644 index 7e93e1c..0000000 --- a/product-service/src/main/resources/test/test.py +++ /dev/null @@ -1,89 +0,0 @@ -class Constants: - # Error Handler - API_SUCCESS = "Success" - INVALID_REQUEST_MESSAGE = "Invalid request" - UNAUTHORIZED_REQUEST_MESSAGE = "Unauthorized request" - FORBIDDEN_REQUEST_MESSAGE = "Forbidden request" - NOT_FOUND_MESSAGE = "Not found" - USER_NOT_FOUND_MESSAGE = "User not found" - INTERNAL_SERVER_ERROR_MESSAGE = "Internal server error" - EMPTY_CHAT_MESSAGE_MESSAGE = "Empty chat message" - -class ErrorCodesMappingNumber(Enum): - INVALID_REQUEST = (400, Constants.INVALID_REQUEST_MESSAGE) - UNAUTHORIZED_REQUEST = (401, Constants.UNAUTHORIZED_REQUEST_MESSAGE) - FORBIDDEN_REQUEST = (403, Constants.FORBIDDEN_REQUEST_MESSAGE) - NOT_FOUND = (404, Constants.NOT_FOUND_MESSAGE) - INTERNAL_SERVER_ERROR = (500, Constants.INTERNAL_SERVER_ERROR_MESSAGE) - - # TODO: Think about adding more error codes here - AGENT_NOT_FOUND = (404, "Agent not specified or found for chat session") - STARTER_MESSAGE_NOT_FOUND = (404, "Starter message not found") - FOLDER_NOT_FOUND = (404, "Folder not found") - CONNECTOR_NOT_FOUND = (404, "Connector not found") - CHAT_SESSION_NOT_FOUND = (404, "Chat session not found") - CHAT_MESSAGE_NOT_FOUND = (404, "Chat message not found") - UNABLE_TO_UPLOAD_FILE_TO_MINIO = (404, "Unable to upload file to Minio") - UNABLE_TO_DELETE_FILE_FROM_MINIO = (404, "Unable to delete file from Minio") - LLM_PROVIDER_NOT_FOUND = (404, "LLM provider not found") - USER_SETTING_NOT_FOUND = (404, "User setting not found") - EMBEDDING_PROVIDER_NOT_FOUND = (404, "Embedding provider not found") - PROVIDER_TYPE_CHANGE_NOT_ALLOWED = (422, "Provider type change not allowed") - - NO_CONTENT = (204, "No content found") - - USER_WRONG_LOGIN_METHOD = (405, "User already exists with wrong login method") - - -class BaseException(Exception): - """ - Custom exception class for handling errors - """ - - def __init__(self, message: str, detail: str = None): - super().__init__(message) - self._message = message - self._detail = detail - - def __str__(self): - if self._detail: - return f"{self._message}: {self._detail}" - return self._message - -@router.get("/chat-sessions", response_model=APIResponse, status_code=status.HTTP_200_OK) -def get_chat_sessions( - db_session: Session = Depends(get_db_session), user: User = Depends(get_current_user_from_token) -) -> BackendAPIResponse: - """ - Get all chat sessions of the user. - - Args: - db_session (Session): Database session. Defaults to relational database session. - user (User): User object - - Returns: - BackendAPIResponse: API response. - """ - if not user: - status_code, detail = ErrorCodesMappingNumber.UNAUTHORIZED_REQUEST.value - raise HTTPException(status_code=status_code, detail=detail) - - # Get chat sessions of user - chat_sessions, err = ChatService(db_session=db_session).get_chat_sessions(user_id=user.id) - if err: - status_code, detail = err.kind - raise HTTPException(status_code=status_code, detail=detail) - - # Parse chat sessions - if chat_sessions: - data = [ChatSessionResponse.model_validate(chat_session) for chat_session in chat_sessions] - else: - data = [] - - return ( - BackendAPIResponse() - .set_message(message=Constants.API_SUCCESS) - .set_data(data=data) - .respond() - ) - diff --git a/promotion-service/pom.xml b/promotion-service/pom.xml index c0a3fb0..2cea881 100644 --- a/promotion-service/pom.xml +++ b/promotion-service/pom.xml @@ -48,39 +48,27 @@ com.blubin - product-service - ${revision} + common-service + 1.0-SNAPSHOT compile - - - - - - - - - - - - - - - - - - - - - - - - - - + + + org.springframework.boot + spring-boot-maven-plugin + 3.3.5 + + + + repackage + + + + + diff --git a/promotion-service/src/main/java/com/blubin/promotionservice/PromotionServiceApplication.java b/promotion-service/src/main/java/com/blubin/promotionservice/PromotionServiceApplication.java index b9eaac7..7d85af8 100644 --- a/promotion-service/src/main/java/com/blubin/promotionservice/PromotionServiceApplication.java +++ b/promotion-service/src/main/java/com/blubin/promotionservice/PromotionServiceApplication.java @@ -3,7 +3,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"com.blubin.promotionservice", + "com.blubin.commonservice"}) public class PromotionServiceApplication { public static void main(String[] args) { diff --git a/promotion-service/src/main/java/com/blubin/promotionservice/model/Promotion.java b/promotion-service/src/main/java/com/blubin/promotionservice/model/Promotion.java index f4cbd40..dde65af 100644 --- a/promotion-service/src/main/java/com/blubin/promotionservice/model/Promotion.java +++ b/promotion-service/src/main/java/com/blubin/promotionservice/model/Promotion.java @@ -8,6 +8,7 @@ import java.math.BigDecimal; import java.time.Instant; +import java.util.UUID; @Getter @Setter @@ -15,9 +16,9 @@ @Table(name = "promotion") public class Promotion { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "promotion_id",updatable = false, nullable = false) + private UUID id; @Size(max = 200) @NotNull diff --git a/promotion-service/src/main/java/com/blubin/promotionservice/model/PromotionCategory.java b/promotion-service/src/main/java/com/blubin/promotionservice/model/PromotionCategory.java index 3b492ae..de72e2f 100644 --- a/promotion-service/src/main/java/com/blubin/promotionservice/model/PromotionCategory.java +++ b/promotion-service/src/main/java/com/blubin/promotionservice/model/PromotionCategory.java @@ -1,9 +1,12 @@ package com.blubin.promotionservice.model; -import com.blubin.productservice.model.ProductCategory; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import java.util.UUID; @Getter @Setter @@ -13,13 +16,10 @@ public class PromotionCategory { @EmbeddedId private PromotionCategoryId id; - @MapsId("categoryId") - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "category_id", nullable = false) - private ProductCategory category; @MapsId("promotionId") @ManyToOne(fetch = FetchType.LAZY, optional = false) + @OnDelete(action = OnDeleteAction.CASCADE) @JoinColumn(name = "promotion_id", nullable = false) private Promotion promotion; diff --git a/promotion-service/src/main/java/com/blubin/promotionservice/model/PromotionCategoryId.java b/promotion-service/src/main/java/com/blubin/promotionservice/model/PromotionCategoryId.java index e3431a5..2cbfc98 100644 --- a/promotion-service/src/main/java/com/blubin/promotionservice/model/PromotionCategoryId.java +++ b/promotion-service/src/main/java/com/blubin/promotionservice/model/PromotionCategoryId.java @@ -8,6 +8,7 @@ import org.hibernate.Hibernate; import java.util.Objects; +import java.util.UUID; @Getter @Setter @@ -16,11 +17,11 @@ public class PromotionCategoryId implements java.io.Serializable { private static final long serialVersionUID = -2552771402027667829L; @NotNull @Column(name = "category_id", nullable = false) - private Integer categoryId; + private UUID categoryId; @NotNull @Column(name = "promotion_id", nullable = false) - private Integer promotionId; + private UUID promotionId; @Override public boolean equals(Object o) { diff --git a/promotion-service/src/main/resources/application.properties b/promotion-service/src/main/resources/application.properties deleted file mode 100644 index 38f5b01..0000000 --- a/promotion-service/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=promotion-service diff --git a/promotion-service/src/main/resources/application.yml b/promotion-service/src/main/resources/application.yml index ff64b34..184aa0c 100644 --- a/promotion-service/src/main/resources/application.yml +++ b/promotion-service/src/main/resources/application.yml @@ -1,6 +1,9 @@ +server: + port: 8084 + spring: application: - name: user_service + name: promotion_service datasource: url: jdbc:postgresql://localhost:5432/ecommerce username: postgres diff --git a/rating-service/pom.xml b/rating-service/pom.xml index 35cc6a0..ed79a8c 100644 --- a/rating-service/pom.xml +++ b/rating-service/pom.xml @@ -48,45 +48,27 @@ com.blubin - product-service - ${revision} - compile - - - com.blubin - user-service + common-service ${revision} compile - - - - - - - - - - - - - - - - - - - - - - - - - - + + + org.springframework.boot + spring-boot-maven-plugin + 3.3.5 + + + + repackage + + + + + diff --git a/rating-service/src/main/java/com/blubin/ratingservice/RatingServiceApplication.java b/rating-service/src/main/java/com/blubin/ratingservice/RatingServiceApplication.java index 07e8390..97e4457 100644 --- a/rating-service/src/main/java/com/blubin/ratingservice/RatingServiceApplication.java +++ b/rating-service/src/main/java/com/blubin/ratingservice/RatingServiceApplication.java @@ -3,7 +3,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"com.blubin.ratingservice", + "com.blubin.commonservice"}) public class RatingServiceApplication { public static void main(String[] args) { diff --git a/rating-service/src/main/java/com/blubin/ratingservice/model/ProductReview.java b/rating-service/src/main/java/com/blubin/ratingservice/model/ProductReview.java index ec08943..d9673b9 100644 --- a/rating-service/src/main/java/com/blubin/ratingservice/model/ProductReview.java +++ b/rating-service/src/main/java/com/blubin/ratingservice/model/ProductReview.java @@ -1,7 +1,5 @@ package com.blubin.ratingservice.model; -import com.blubin.productservice.model.Product; -import com.blubin.userservice.model.SiteUser; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; @@ -9,6 +7,7 @@ import lombok.Setter; import java.time.LocalDate; +import java.util.UUID; @Getter @Setter @@ -16,17 +15,15 @@ @Table(name = "product_review") public class ProductReview { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "review_id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "review_id",updatable = false, nullable = false) + private UUID id; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "product_id") - private Product product; + @Column(name = "product_id") + private UUID product; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private SiteUser user; + @Column(name = "user_id") + private UUID user; @Size(max = 100) @Column(name = "review_title", length = 100) diff --git a/rating-service/src/main/java/com/blubin/ratingservice/model/ProductReviewImage.java b/rating-service/src/main/java/com/blubin/ratingservice/model/ProductReviewImage.java index da4bdd0..519a2c0 100644 --- a/rating-service/src/main/java/com/blubin/ratingservice/model/ProductReviewImage.java +++ b/rating-service/src/main/java/com/blubin/ratingservice/model/ProductReviewImage.java @@ -7,15 +7,17 @@ import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "product_review_image") public class ProductReviewImage { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "image_id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "image_id",updatable = false, nullable = false) + private UUID id; @ManyToOne(fetch = FetchType.LAZY) @OnDelete(action = OnDeleteAction.CASCADE) diff --git a/rating-service/src/main/resources/application.properties b/rating-service/src/main/resources/application.properties deleted file mode 100644 index 18e59f5..0000000 --- a/rating-service/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=rating-service diff --git a/rating-service/src/main/resources/application.yml b/rating-service/src/main/resources/application.yml index ff64b34..7071981 100644 --- a/rating-service/src/main/resources/application.yml +++ b/rating-service/src/main/resources/application.yml @@ -1,6 +1,9 @@ +server: + port: 8087 + spring: application: - name: user_service + name: rating_service datasource: url: jdbc:postgresql://localhost:5432/ecommerce username: postgres diff --git a/tempo-data/blocks/tempo_cluster_seed.json b/tempo-data/blocks/tempo_cluster_seed.json new file mode 100644 index 0000000..b0a0ca8 --- /dev/null +++ b/tempo-data/blocks/tempo_cluster_seed.json @@ -0,0 +1 @@ +{"UID":"e7aa87c8-7a44-4dc2-9b68-d30dc24a11a8","created_at":"2025-03-06T14:28:27.103972891Z","version":{"version":"","revision":"fd5743d5d","branch":"HEAD","buildUser":"","buildDate":"","goVersion":"go1.18.5"}} \ No newline at end of file diff --git a/user-service/Dockerfile b/user-service/Dockerfile new file mode 100644 index 0000000..77deae2 --- /dev/null +++ b/user-service/Dockerfile @@ -0,0 +1,4 @@ +FROM eclipse-temurin:21-jre-alpine +LABEL authors="blubin" +COPY target/user-service*.jar app.jar +ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file diff --git a/user-service/pom.xml b/user-service/pom.xml index 1cbbd7f..badbcf2 100644 --- a/user-service/pom.xml +++ b/user-service/pom.xml @@ -50,21 +50,13 @@ 10.0.0 provided - - - - - - - - - - - - - - - + + com.blubin + common-service + ${revision} + compile + + @@ -73,10 +65,14 @@ org.springframework.boot spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-compiler-plugin + 3.3.5 + + + + repackage + + + diff --git a/user-service/src/main/java/com/blubin/userservice/UserServiceApplication.java b/user-service/src/main/java/com/blubin/userservice/UserServiceApplication.java index 0ffd466..d19c671 100644 --- a/user-service/src/main/java/com/blubin/userservice/UserServiceApplication.java +++ b/user-service/src/main/java/com/blubin/userservice/UserServiceApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = {"com.blubin.userservice", + "com.blubin.commonservice"}) public class UserServiceApplication { public static void main(String[] args) { diff --git a/user-service/src/main/java/com/blubin/userservice/controller/CountryController.java b/user-service/src/main/java/com/blubin/userservice/controller/CountryController.java index 5180b46..07e156e 100644 --- a/user-service/src/main/java/com/blubin/userservice/controller/CountryController.java +++ b/user-service/src/main/java/com/blubin/userservice/controller/CountryController.java @@ -1,5 +1,4 @@ package com.blubin.userservice.controller; - import com.blubin.userservice.model.Country; import com.blubin.userservice.service.CountryService; import com.blubin.userservice.viewmodel.country.CountryRequestVM; diff --git a/user-service/src/main/java/com/blubin/userservice/model/Address.java b/user-service/src/main/java/com/blubin/userservice/model/Address.java index 33b3ab8..78d70e7 100644 --- a/user-service/src/main/java/com/blubin/userservice/model/Address.java +++ b/user-service/src/main/java/com/blubin/userservice/model/Address.java @@ -7,15 +7,17 @@ import lombok.Setter; import org.hibernate.annotations.ColumnDefault; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "address") public class Address { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "address_id",updatable = false , nullable = false) + private UUID id; @Size(max = 20) @Column(name = "unit_number", length = 20) diff --git a/user-service/src/main/java/com/blubin/userservice/model/Country.java b/user-service/src/main/java/com/blubin/userservice/model/Country.java index f331024..0fd303f 100644 --- a/user-service/src/main/java/com/blubin/userservice/model/Country.java +++ b/user-service/src/main/java/com/blubin/userservice/model/Country.java @@ -6,15 +6,17 @@ import lombok.Getter; import lombok.Setter; +import java.util.UUID; + @Getter @Setter @Entity @Table(name = "country") public class Country { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Integer id; + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "country_id",updatable = false, nullable = false) + private UUID id; @Size(max = 255) @NotNull diff --git a/user-service/src/main/java/com/blubin/userservice/model/Gender.java b/user-service/src/main/java/com/blubin/userservice/model/Gender.java new file mode 100644 index 0000000..d6d9308 --- /dev/null +++ b/user-service/src/main/java/com/blubin/userservice/model/Gender.java @@ -0,0 +1,6 @@ +package com.blubin.userservice.model; + +public enum Gender { + MALE, + FEMALE +} diff --git a/user-service/src/main/java/com/blubin/userservice/model/SiteUser.java b/user-service/src/main/java/com/blubin/userservice/model/SiteUser.java index c37dc66..590f556 100644 --- a/user-service/src/main/java/com/blubin/userservice/model/SiteUser.java +++ b/user-service/src/main/java/com/blubin/userservice/model/SiteUser.java @@ -1,79 +1,48 @@ -package com.blubin.userservice.model; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import lombok.Getter; -import lombok.Setter; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; - -import java.util.Collection; -import java.util.List; - -@Getter -@Setter -@Entity -@Table(name = "site_user") -public class SiteUser implements UserDetails { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", nullable = false) - private Integer id; - - @Size(max = 255) - @NotNull - @Column(name = "user_name", nullable = false) - private String userName; - - @Size(max = 255) - @NotNull - @Column(name = "email_address", nullable = false) - private String emailAddress; - - @Size(max = 20) - @Column(name = "phone_number", length = 20) - private String phoneNumber; - - @Size(max = 255) - @NotNull - @Column(name = "password", nullable = false) - private String password; - - @NotNull - @Enumerated(EnumType.STRING) - @Column(name = "role",nullable = false) - private UserRole role = UserRole.USER; - - @Override - public Collection getAuthorities() { - return List.of(new SimpleGrantedAuthority(role.toString())); - } - - @Override - public String getUsername() { - return ""; - } - - @Override - public boolean isAccountNonExpired() { - return UserDetails.super.isAccountNonExpired(); - } - - @Override - public boolean isAccountNonLocked() { - return UserDetails.super.isAccountNonLocked(); - } - - @Override - public boolean isCredentialsNonExpired() { - return UserDetails.super.isCredentialsNonExpired(); - } - - @Override - public boolean isEnabled() { - return UserDetails.super.isEnabled(); - } -} \ No newline at end of file +//package com.blubin.userservice.model; +// +//import jakarta.persistence.*; +//import jakarta.validation.constraints.NotNull; +//import jakarta.validation.constraints.Size; +//import lombok.Getter; +//import lombok.Setter; +//import org.hibernate.annotations.ColumnDefault; +// +//import java.time.Instant; +//import java.util.UUID; +// +//@Getter +//@Setter +//@Entity +//@Table(name = "site_user", schema = "public", uniqueConstraints = { +// @UniqueConstraint(name = "site_user_email_address_key", columnNames = {"email_address"}) +//}) +//public class SiteUser { +// @Id +// @Column(name = "id", nullable = false) +// private UUID id; +// +// @Size(max = 255) +// @NotNull +// @Column(name = "email_address", nullable = false) +// private String emailAddress; +// +// @Size(max = 20) +// @Column(name = "phone_number", length = 20) +// private String phoneNumber; +// +// @Size(max = 255) +// @NotNull +// @Column(name = "password", nullable = false) +// private String password; +// +// @Size(max = 50) +// @NotNull +// @ColumnDefault("'USER'") +// @Column(name = "role", nullable = false, length = 50) +// private String role; +// +// @ColumnDefault("CURRENT_TIMESTAMP") +// @Column(name = "created_at") +// private Instant createdAt; +// +//} \ No newline at end of file diff --git a/user-service/src/main/java/com/blubin/userservice/model/UserAddress.java b/user-service/src/main/java/com/blubin/userservice/model/UserAddress.java index 164e5b2..1337c25 100644 --- a/user-service/src/main/java/com/blubin/userservice/model/UserAddress.java +++ b/user-service/src/main/java/com/blubin/userservice/model/UserAddress.java @@ -15,8 +15,8 @@ public class UserAddress { @MapsId("userId") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "user_id", nullable = false) - private SiteUser user; + @JoinColumn(name = "user_profile_id", nullable = false) + private UserProfile user; @MapsId("addressId") @ManyToOne(fetch = FetchType.LAZY, optional = false) diff --git a/user-service/src/main/java/com/blubin/userservice/model/UserAddressId.java b/user-service/src/main/java/com/blubin/userservice/model/UserAddressId.java index 36b1a74..8d0e8a7 100644 --- a/user-service/src/main/java/com/blubin/userservice/model/UserAddressId.java +++ b/user-service/src/main/java/com/blubin/userservice/model/UserAddressId.java @@ -8,6 +8,7 @@ import org.hibernate.Hibernate; import java.util.Objects; +import java.util.UUID; @Getter @Setter @@ -16,11 +17,11 @@ public class UserAddressId implements java.io.Serializable { private static final long serialVersionUID = -7363347071720835091L; @NotNull @Column(name = "user_id", nullable = false) - private Integer userId; + private UUID userId; @NotNull @Column(name = "address_id", nullable = false) - private Integer addressId; + private UUID addressId; @Override public boolean equals(Object o) { diff --git a/user-service/src/main/java/com/blubin/userservice/model/UserProfile.java b/user-service/src/main/java/com/blubin/userservice/model/UserProfile.java new file mode 100644 index 0000000..8cb9110 --- /dev/null +++ b/user-service/src/main/java/com/blubin/userservice/model/UserProfile.java @@ -0,0 +1,49 @@ +package com.blubin.userservice.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import java.time.LocalDate; +import java.util.UUID; + +@Getter +@Setter +@Entity +@Table(name = "user_profile", schema = "public", uniqueConstraints = { + @UniqueConstraint(name = "user_profile_user_id_key", columnNames = {"user_id"}) +}) +public class UserProfile { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "user_profile_id" ,updatable = false , nullable = false) + private UUID id; + + @Size(max = 100) + @NotNull + @Column(name = "first_name", nullable = false, length = 100) + private String firstName; + + @Size(max = 100) + @NotNull + @Column(name = "last_name", nullable = false, length = 100) + private String lastName; + + @Column(name = "date_of_birth") + private LocalDate dateOfBirth; + + @Enumerated(EnumType.STRING) + @Column(name = "gender", length = 10, nullable = false) + private Gender gender; + + @Column(name = "profile_avatars", length = Integer.MAX_VALUE) + private String profileAvatars; + + @NotNull + @Column(name = "user_id") + private UUID userId; +} \ No newline at end of file diff --git a/user-service/src/main/resources/application.yml b/user-service/src/main/resources/application.yml index fa46cae..b29d07d 100644 --- a/user-service/src/main/resources/application.yml +++ b/user-service/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8082 + port: 8081 spring: application: diff --git a/user-service/src/main/resources/database.sql b/user-service/src/main/resources/database.sql index c96f8c9..4133fc5 100644 --- a/user-service/src/main/resources/database.sql +++ b/user-service/src/main/resources/database.sql @@ -36,12 +36,12 @@ DROP TABLE IF EXISTS address; DROP TABLE IF EXISTS country; -- Country Table CREATE TABLE country ( - id BIGINT PRIMARY KEY, + country_id UUID PRIMARY KEY, country_name VARCHAR(255) NOT NULL ); -- Address Table CREATE TABLE address ( - id BIGINT PRIMARY KEY, + address_id UUID PRIMARY KEY, unit_number VARCHAR(20), street_number VARCHAR(20), address_line1 VARCHAR(255) NOT NULL, @@ -49,49 +49,73 @@ CREATE TABLE address ( city VARCHAR(100) NOT NULL, region VARCHAR(100), postal_code VARCHAR(20), - country_id BIGINT, - FOREIGN KEY (country_id) REFERENCES country(id) + country_id UUID, + FOREIGN KEY (country_id) REFERENCES country(country_id) ); -- Site User Table CREATE TABLE site_user ( - id BIGINT PRIMARY KEY, + site_user_id UUID PRIMARY KEY, email_address VARCHAR(255) UNIQUE NOT NULL, phone_number VARCHAR(20), - password VARCHAR(255) NOT NULL + password VARCHAR(255) NOT NULL, + role VARCHAR(50) NOT NULL DEFAULT 'USER', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + +); + +-- User Profile +CREATE TABLE user_profile( + user_profile_id UUID PRIMARY KEY, + first_name VARCHAR(100) NOT NULL, + last_name VARCHAR(100) NOT NULL, + date_of_birth DATE, + gender VARCHAR(10) CHECK ( gender IN ('MALE', 'FEMALE') ), + profile_avatars TEXT, + site_user_id UUID UNIQUE NOT NULL, + CONSTRAINT fk_user_profile_user FOREIGN KEY (site_user_id) REFERENCES site_user(site_user_id) ON DELETE CASCADE ); + -- User Address Table CREATE TABLE user_address ( - user_id BIGINT, - address_id BIGINT, + user_id UUID, + address_id UUID, is_default BOOLEAN DEFAULT FALSE, PRIMARY KEY (user_id, address_id), - FOREIGN KEY (user_id) REFERENCES site_user(id), - FOREIGN KEY (address_id) REFERENCES address(id) + FOREIGN KEY (user_id) REFERENCES user_profile(user_profile_id) ON DELETE CASCADE, + FOREIGN KEY (address_id) REFERENCES address(address_id) ON DELETE CASCADE ); -- Brand Table CREATE TABLE brand ( - brand_id BIGINT PRIMARY KEY, + brand_id UUID PRIMARY KEY, brand_name VARCHAR(200) NOT NULL, brand_description TEXT ); -- Colour Table CREATE TABLE colour ( - colour_id BIGINT PRIMARY KEY, + colour_id UUID PRIMARY KEY, colour_name VARCHAR(100) NOT NULL, hex_code VARCHAR(7) NOT NULL UNIQUE ); -- Product Category Table +-- CREATE TABLE product_category ( +-- product_category_id UUID PRIMARY KEY, +-- category_name VARCHAR(100) NOT NULL, +-- category_image VARCHAR(400), +-- category_description TEXT, +-- parent_product_category_id UUID, +-- FOREIGN KEY (parent_product_category_id) REFERENCES product_category(product_category_id) +-- ); CREATE TABLE product_category ( - product_category_id BIGINT PRIMARY KEY, + product_category_id UUID PRIMARY KEY, category_name VARCHAR(100) NOT NULL, category_image VARCHAR(400), category_description TEXT, - parent_product_category_id BIGINT, - FOREIGN KEY (parent_product_category_id) REFERENCES product_category(product_category_id) + parent_product_category_id UUID REFERENCES product_category(product_category_id) ); + -- Promotion Table CREATE TABLE promotion ( - id BIGINT PRIMARY KEY, + promotion_id UUID PRIMARY KEY, name VARCHAR(200) NOT NULL, description TEXT, discount_rate DECIMAL(5, 2) NOT NULL, @@ -100,220 +124,214 @@ CREATE TABLE promotion ( ); -- Promotion Category Table CREATE TABLE promotion_category ( - category_id BIGINT, - promotion_id BIGINT, + category_id UUID, + promotion_id UUID, PRIMARY KEY (category_id, promotion_id), - FOREIGN KEY (category_id) REFERENCES product_category(product_category_id), - FOREIGN KEY (promotion_id) REFERENCES promotion(id) + FOREIGN KEY (promotion_id) REFERENCES promotion(promotion_id) ON DELETE CASCADE ); -- Product Table CREATE TABLE product ( - product_id BIGINT PRIMARY KEY, + product_id UUID PRIMARY KEY, product_name VARCHAR(500) NOT NULL, - product_category_id BIGINT, + product_category_id UUID, product_description TEXT, - brand_id BIGINT, + brand_id UUID, model_height VARCHAR(50), model_wearing VARCHAR(50), care_instructions TEXT, about TEXT, - FOREIGN KEY (product_category_id) REFERENCES product_category(product_category_id), - FOREIGN KEY (brand_id) REFERENCES brand(brand_id) -); --- Product Image Table -CREATE TABLE product_image ( - image_id BIGINT PRIMARY KEY, - product_id BIGINT, - image_filename VARCHAR(400) NOT NULL, - product_item_id BIGINT, - FOREIGN KEY (product_id) REFERENCES product(product_id), - FOREIGN KEY (product_item_id) REFERENCES product_item(product_item_id) + FOREIGN KEY (product_category_id) REFERENCES product_category(product_category_id) ON DELETE CASCADE, + FOREIGN KEY (brand_id) REFERENCES brand(brand_id) ON DELETE CASCADE ); + -- Product Item Table CREATE TABLE product_item ( - product_item_id BIGINT PRIMARY KEY, - product_id BIGINT, - colour_id BIGINT, + product_item_id UUID PRIMARY KEY, + product_id UUID, + colour_id UUID, original_price DECIMAL(10, 2), sale_price DECIMAL(10, 2), product_code VARCHAR(20) NOT NULL, - FOREIGN KEY (product_id) REFERENCES product(product_id), - FOREIGN KEY (colour_id) REFERENCES colour(colour_id) + FOREIGN KEY (product_id) REFERENCES product(product_id) ON DELETE CASCADE, + FOREIGN KEY (colour_id) REFERENCES colour(colour_id) ON DELETE CASCADE +); + +-- Product Image Table +CREATE TABLE product_image ( + image_id UUID PRIMARY KEY, + product_id UUID, + image_filename VARCHAR(400) NOT NULL, + product_item_id UUID, + FOREIGN KEY (product_id) REFERENCES product(product_id) ON DELETE CASCADE, + FOREIGN KEY (product_item_id) REFERENCES product_item(product_item_id) ON DELETE CASCADE ); -- Attribute Type Table CREATE TABLE attribute_type ( - attribute_type_id BIGINT PRIMARY KEY, + attribute_type_id UUID PRIMARY KEY, attribute_name VARCHAR(100) NOT NULL ); -- Attribute Option Table CREATE TABLE attribute_option ( - attribute_option_id BIGINT PRIMARY KEY, - attribute_type_id BIGINT, + attribute_option_id UUID PRIMARY KEY, + attribute_type_id UUID, attribute_option_name VARCHAR(100) NOT NULL, - FOREIGN KEY (attribute_type_id) REFERENCES attribute_type(attribute_type_id) + FOREIGN KEY (attribute_type_id) REFERENCES attribute_type(attribute_type_id) ON DELETE CASCADE ); -- Product Attribute Table -CREATE TABLE product_attribute ( - product_id BIGINT, - attribute_option_id BIGINT, - PRIMARY KEY (product_id, attribute_option_id), - FOREIGN KEY (product_id) REFERENCES product(product_id), - FOREIGN KEY (attribute_option_id) REFERENCES attribute_option(attribute_option_id) +CREATE TABLE size_category ( + category_id UUID PRIMARY KEY, + category_name VARCHAR(100) NOT NULL ); -- -- Product Review Table -- CREATE TABLE product_review ( --- review_id BIGINT PRIMARY KEY, --- product_id BIGINT, +-- review_id UUID PRIMARY KEY, +-- product_id UUID, -- review_title VARCHAR(100), --- review_rating BIGINT CHECK (review_rating BETWEEN 1 AND 5), +-- review_rating UUID CHECK (review_rating BETWEEN 1 AND 5), -- review_comment TEXT, -- review_date DATE NOT NULL, -- FOREIGN KEY (product_id) REFERENCES product(product_id) -- ); -- Size Category Table -CREATE TABLE size_category ( - category_id BIGINT PRIMARY KEY, - category_name VARCHAR(100) NOT NULL +CREATE TABLE product_attribute ( + product_id UUID, + attribute_option_id UUID, + PRIMARY KEY (product_id, attribute_option_id), + FOREIGN KEY (product_id) REFERENCES product(product_id) ON DELETE CASCADE, + FOREIGN KEY (attribute_option_id) REFERENCES attribute_option(attribute_option_id) ON DELETE CASCADE ); -- Size Option Table CREATE TABLE size_option ( - size_id BIGINT PRIMARY KEY, + size_id UUID PRIMARY KEY, size_name VARCHAR(100) NOT NULL, - sort_order BIGINT, - size_category_id BIGINT, - FOREIGN KEY (size_category_id) REFERENCES size_category(category_id) + sort_order UUID, + size_category_id UUID, + FOREIGN KEY (size_category_id) REFERENCES size_category(category_id) ON DELETE CASCADE ); -- Product Variation Table CREATE TABLE product_variation ( - variation_id BIGINT PRIMARY KEY, - product_item_id BIGINT, - size_id BIGINT, - qty_in_stock BIGINT, - FOREIGN KEY (product_item_id) REFERENCES product_item(product_item_id), - FOREIGN KEY (size_id) REFERENCES size_option(size_id) + variation_id UUID PRIMARY KEY, + product_item_id UUID, + size_id UUID, + qty_in_stock UUID, + FOREIGN KEY (product_item_id) REFERENCES product_item(product_item_id) ON DELETE CASCADE, + FOREIGN KEY (size_id) REFERENCES size_option(size_id) ON DELETE CASCADE ); -- Payment Type Table CREATE TABLE payment_type ( - id BIGINT PRIMARY KEY, + id UUID PRIMARY KEY, value VARCHAR(100) NOT NULL ); -- User Payment Method Table CREATE TABLE user_payment_method ( - id BIGINT PRIMARY KEY, - user_id BIGINT, - payment_type_id BIGINT, + id UUID PRIMARY KEY, + user_id UUID NOT NULL , + payment_type_id UUID, provider VARCHAR(100), account_number VARCHAR(50), expiry_date DATE, is_default BOOLEAN DEFAULT FALSE, - FOREIGN KEY (user_id) REFERENCES site_user(id), - FOREIGN KEY (payment_type_id) REFERENCES payment_type(id) + FOREIGN KEY (payment_type_id) REFERENCES payment_type(id) ON DELETE CASCADE ); -- Shopping Cart Table CREATE TABLE shopping_cart ( - cart_id BIGINT PRIMARY KEY, - user_id BIGINT, - FOREIGN KEY (user_id) REFERENCES site_user(id) + cart_id UUID PRIMARY KEY, + user_id UUID NOT NULL ); -- Shopping Cart Item Table CREATE TABLE shopping_cart_item ( - cart_id BIGINT, - product_item_id BIGINT, - quantity BIGINT, + cart_id UUID, + product_item_id UUID, + quantity INTEGER NOT NULL CHECK (quantity >= 0), PRIMARY KEY (cart_id, product_item_id), - FOREIGN KEY (cart_id) REFERENCES shopping_cart(cart_id), - FOREIGN KEY (product_item_id) REFERENCES product_item(product_item_id) + FOREIGN KEY (cart_id) REFERENCES shopping_cart(cart_id) ON DELETE CASCADE ); -- Shipping Method Table CREATE TABLE shipping_method ( - id BIGINT PRIMARY KEY, + id UUID PRIMARY KEY, method_name VARCHAR(100) NOT NULL ); -- Order Status Table CREATE TABLE order_status ( - id BIGINT PRIMARY KEY, + id UUID PRIMARY KEY, status_name VARCHAR(100) NOT NULL ); -- Shop Order Table CREATE TABLE shop_order ( - order_id BIGINT PRIMARY KEY, - user_id BIGINT, + order_id UUID PRIMARY KEY, + user_id UUID, order_date TIMESTAMP NOT NULL, - shipping_method_id BIGINT, - order_status_id BIGINT, + shipping_method_id UUID, + order_status_id UUID, total_amount DECIMAL(10, 2), - FOREIGN KEY (user_id) REFERENCES site_user(id), - FOREIGN KEY (shipping_method_id) REFERENCES shipping_method(id), - FOREIGN KEY (order_status_id) REFERENCES order_status(id) + FOREIGN KEY (shipping_method_id) REFERENCES shipping_method(id) ON DELETE CASCADE, + FOREIGN KEY (order_status_id) REFERENCES order_status(id) ON DELETE CASCADE ); -- Order Line Table CREATE TABLE order_line ( - order_line_id BIGINT PRIMARY KEY, - order_id BIGINT, - product_item_id BIGINT, - quantity BIGINT, + order_line_id UUID PRIMARY KEY, + order_id UUID, + product_item_id UUID, + quantity UUID, unit_price DECIMAL(10, 2), - FOREIGN KEY (order_id) REFERENCES shop_order(order_id), - FOREIGN KEY (product_item_id) REFERENCES product_item(product_item_id) + FOREIGN KEY (order_id) REFERENCES shop_order(order_id) ON DELETE CASCADE ); -- -- User Review Table -- CREATE TABLE user_review ( --- review_id BIGINT PRIMARY KEY, +-- review_id UUID PRIMARY KEY, -- review_title VARCHAR(100), -- review_comment TEXT, -- review_date TIMESTAMP NOT NULL, --- rating BIGINT CHECK (rating BETWEEN 1 AND 5), --- user_id BIGINT, +-- rating UUID CHECK (rating BETWEEN 1 AND 5), +-- user_id UUID, -- FOREIGN KEY (user_id) REFERENCES site_user(id) -- ); -- Product Review Table CREATE TABLE product_review ( - review_id BIGINT PRIMARY KEY, - product_id BIGINT, - user_id BIGINT, + review_id UUID PRIMARY KEY, + product_id UUID, + user_id UUID, review_title VARCHAR(100), review_rating BIGINT CHECK (review_rating BETWEEN 1 AND 5), review_comment TEXT, - review_date DATE NOT NULL, - FOREIGN KEY (product_id) REFERENCES product(product_id), - FOREIGN KEY (user_id) REFERENCES site_user(id) + review_date DATE NOT NULL ); -- Product Review Image Table CREATE TABLE product_review_image ( - image_id BIGINT PRIMARY KEY, - review_id BIGINT, - image_url TEXT NOT NULL, - FOREIGN KEY (review_id) REFERENCES product_review(review_id) ON DELETE CASCADE + image_id UUID PRIMARY KEY, + review_id UUID, + image_url TEXT NOT NULL, + FOREIGN KEY (review_id) REFERENCES product_review(review_id) ON DELETE CASCADE ); -- -- User Review Table (Modified to link with Product Review) -- CREATE TABLE user_review ( --- review_id BIGINT PRIMARY KEY, --- user_id BIGINT, --- product_review_id BIGINT, +-- review_id UUID PRIMARY KEY, +-- user_id UUID, +-- product_review_id UUID, -- review_title VARCHAR(100), -- review_comment TEXT, -- review_date TIMESTAMP NOT NULL, --- rating BIGINT CHECK (rating BETWEEN 1 AND 5), +-- rating UUID CHECK (rating BETWEEN 1 AND 5), -- FOREIGN KEY (user_id) REFERENCES site_user(id), -- FOREIGN KEY (product_review_id) REFERENCES product_review(review_id) -- ); -- -- Rating Type Table -- CREATE TABLE rating_type ( --- rating_type_id BIGINT PRIMARY KEY, +-- rating_type_id UUID PRIMARY KEY, -- rating_name VARCHAR(20) NOT NULL, -- label_min VARCHAR(20), -- label_max VARCHAR(20) -- ); -- -- Review Rating Type Table -- CREATE TABLE review_rating_type ( --- review_id BIGINT, --- rating_type_id BIGINT, --- rating_value BIGINT, +-- review_id UUID, +-- rating_type_id UUID, +-- rating_value UUID, -- PRIMARY KEY (review_id, rating_type_id), -- FOREIGN KEY (rating_type_id) REFERENCES rating_type(rating_type_id), -- FOREIGN KEY (review_id) REFERENCES product_review(review_id)