From 3b596372260b37411fdaebd5af7191ecae6b6d7b Mon Sep 17 00:00:00 2001 From: Davis Tibbz Date: Wed, 28 Aug 2024 13:12:39 +0800 Subject: [PATCH 01/16] migrate all javax.* to jakarta.* for Springboot 3 --- pom.xml | 20 ++++++++++++------- .../config/CustomAuthSuccessHandler.java | 6 +++--- .../config/CustomLoginHandler.java | 7 +++---- .../controllers/AuthController.java | 3 +-- .../controllers/CartController.java | 4 ++-- .../controllers/CheckoutController.java | 4 ++-- .../controllers/CourseController.java | 4 ++-- .../controllers/EnrollmentController.java | 6 +++--- .../controllers/LessonController.java | 2 +- .../controllers/ObjectivesController.java | 2 +- .../controllers/ProfileController.java | 4 ++-- .../controllers/ReviewController.java | 4 ++-- .../controllers/SalesController.java | 5 ++--- .../controllers/WishlistController.java | 4 ++-- .../wedemyserver/dto/CheckoutRequest.java | 6 +++--- .../wedemyserver/dto/LoginRequest.java | 7 +++---- .../wedemyserver/dto/ObjectivesDTO.java | 4 ++-- .../wedemyserver/dto/ReviewRequest.java | 3 +-- .../wedemyserver/dto/VideoRequest.java | 5 ++--- .../wedemyserver/dto/VideoResponse.java | 3 +-- .../wedemyserver/dto/WatchStatus.java | 3 +-- .../davistiba/wedemyserver/models/Cart.java | 4 ++-- .../davistiba/wedemyserver/models/Course.java | 10 +++++----- .../wedemyserver/models/CourseObjective.java | 4 ++-- .../wedemyserver/models/EnrollProgress.java | 2 +- .../wedemyserver/models/Enrollment.java | 7 +++---- .../davistiba/wedemyserver/models/Lesson.java | 8 ++++---- .../wedemyserver/models/OrderItem.java | 2 +- .../davistiba/wedemyserver/models/Review.java | 6 +++--- .../davistiba/wedemyserver/models/Sales.java | 8 ++++---- .../davistiba/wedemyserver/models/User.java | 10 +++++----- .../wedemyserver/models/Wishlist.java | 2 +- .../repository/CourseRepository.java | 2 +- .../service/EnrollProgressService.java | 2 +- .../service/MyUserDetailsService.java | 4 ++-- .../wedemyserver/service/ProfileService.java | 2 +- src/main/resources/application-prod.yml | 2 +- src/main/resources/application.yml | 2 +- 38 files changed, 90 insertions(+), 93 deletions(-) diff --git a/pom.xml b/pom.xml index b37a46b..c2c5733 100644 --- a/pom.xml +++ b/pom.xml @@ -6,25 +6,25 @@ org.springframework.boot spring-boot-starter-parent - 2.7.18 + 3.3.3 com.davistiba wedemyserver - 1.2 + 2.0.0 wedemyserver Wedemy clone server, built with Spring Boot https://github.com/longwater1234/WedemyServer - 11 - 11 - 11 + 17 + 17 + 17 - javax.validation - validation-api + jakarta.validation + jakarta.validation-api org.hibernate.validator @@ -136,6 +136,11 @@ braintree-java 3.35.0 + + org.springframework.boot + spring-boot-properties-migrator + runtime + com.davistiba From 6b16f8351629805fc21c5cd750094b1f70a9227e Mon Sep 17 00:00:00 2001 From: Davis Tibbz Date: Mon, 9 Dec 2024 19:29:39 +0300 Subject: [PATCH 12/16] set arraylist size for CheckoutService --- .../davistiba/wedemyserver/service/CheckoutService.java | 8 ++++---- .../com/davistiba/wedemyserver/service/ReviewService.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/davistiba/wedemyserver/service/CheckoutService.java b/src/main/java/com/davistiba/wedemyserver/service/CheckoutService.java index cda5dfb..4570f18 100644 --- a/src/main/java/com/davistiba/wedemyserver/service/CheckoutService.java +++ b/src/main/java/com/davistiba/wedemyserver/service/CheckoutService.java @@ -46,15 +46,15 @@ public class CheckoutService { public MyCustomResponse processCheckoutDatabase(String transactionId, @NotNull CheckoutRequest request, User user) { - - List orderItemList = new ArrayList<>(); - List enrollments = new ArrayList<>(); Page coursePage = courseRepository.getCartListByUser(user.getId(), Pageable.unpaged()); //===== begin DB OPERATIONS ======== Sales savedSale = salesRepository.save( new Sales(transactionId, user, request.getTotalAmount(), request.getPaymentMethod())); + ArrayList orderItemList = new ArrayList<>(coursePage.getTotalPages()); + ArrayList enrollments = new ArrayList<>(coursePage.getTotalPages()); + coursePage.get().forEach(course -> { OrderItem o = new OrderItem(savedSale, course); orderItemList.add(o); @@ -63,7 +63,7 @@ public MyCustomResponse processCheckoutDatabase(String transactionId, enrollments.add(e); }); - List courseIds = coursePage.get().map(Course::getId).collect(Collectors.toUnmodifiableList()); + List courseIds = coursePage.get().map(Course::getId).toList(); orderItemRepository.saveAll(orderItemList); enrollmentRepository.saveAll(enrollments); diff --git a/src/main/java/com/davistiba/wedemyserver/service/ReviewService.java b/src/main/java/com/davistiba/wedemyserver/service/ReviewService.java index 07f3314..3f8d8de 100644 --- a/src/main/java/com/davistiba/wedemyserver/service/ReviewService.java +++ b/src/main/java/com/davistiba/wedemyserver/service/ReviewService.java @@ -28,7 +28,7 @@ public class ReviewService { /** * Insert new review. - * Then, calculate and update AVG rating for course. + * Then, re-calculate and update AVG rating for course. * All in single DB transaction * * @param request from frontend @@ -48,7 +48,7 @@ public void addCourseRating(ReviewRequest request, Integer userId) { } /** - * EDIT existing review, and modify AVG course rating + * UPDATE existing review, and modify AVG course rating */ @Transactional public void updateCourseRating(Integer reviewId, ReviewRequest request) { From 0eda864b576b011227279a39ca5b527ad5713ffb Mon Sep 17 00:00:00 2001 From: Davis Tibbz Date: Mon, 9 Dec 2024 19:33:11 +0300 Subject: [PATCH 13/16] ProfileService minor cleanup --- .../java/com/davistiba/wedemyserver/service/ProfileService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/davistiba/wedemyserver/service/ProfileService.java b/src/main/java/com/davistiba/wedemyserver/service/ProfileService.java index 40159be..58df2a6 100644 --- a/src/main/java/com/davistiba/wedemyserver/service/ProfileService.java +++ b/src/main/java/com/davistiba/wedemyserver/service/ProfileService.java @@ -23,7 +23,7 @@ public class ProfileService { * Custom service to return a Student's summary */ public List getUserSummaryList(@NotNull User user) { - List summaryList = new ArrayList<>(3); + ArrayList summaryList = new ArrayList<>(3); long owned = enrollmentRepository.countEnrollmentByUser(user); StudentSummary s1 = new StudentSummary(SummaryTitle.OWNING, owned, "courses"); summaryList.add(s1); From e59f4e3075195b2ad848d4c65fdd06352b73d5b5 Mon Sep 17 00:00:00 2001 From: Davis Tibbz Date: Thu, 12 Dec 2024 19:37:11 +0300 Subject: [PATCH 14/16] preparing for release --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f22fa39..07f3cc7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # WedemyServer -(updated 2024-08) - -[![Static Badge](https://img.shields.io/badge/API_docs-v1.2-red)](https://longwater1234.github.io/WedemyServer/) +[![Static Badge](https://img.shields.io/badge/API_docs-v2.0-red)](https://longwater1234.github.io/WedemyServer/) [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/Longwater1234/WedemyServer/graphs/commit-activity) [![License: MIT](https://img.shields.io/github/license/Longwater1234/WedemyServer)](https://github.com/Longwater1234/WedemyServer/blob/master/LICENSE) [![Static Badge](https://img.shields.io/badge/reference-help.md-orange)](HELP.md) @@ -19,7 +17,7 @@ Click to view [Frontend Repo](https://github.com/Longwater1234/WedemyClient) and Typescript. However, you may use any other frontend stack with this project. See the [OpenAPI Docs](https://longwater1234.github.io/WedemyServer/) for this project. -## Requirements +## Minimum Requirements - Java 17 or newer - MySQL 8.0.x or newer From ec8ff7fa5a9f419770b21781792473a1abe13086 Mon Sep 17 00:00:00 2001 From: Davis Tibbz Date: Thu, 12 Dec 2024 19:48:36 +0300 Subject: [PATCH 15/16] fixed #261 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07f3cc7..963cc44 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ java -jar target/wedemyserver.jar ### With Docker -I have attached [Dockerfile](Dockerfile) for the Springboot server only (slim image). You will need to set up MySQL & +I have attached [Dockerfile](Dockerfile) for the Springboot server only. You will need to set up MySQL & Redis separately. Refer to official Docker docs on how to pass ENV variables listed above. ```bash From b069c1aa2850d54bf1ad11073254065c9c67f975 Mon Sep 17 00:00:00 2001 From: Davis Tibbz Date: Thu, 12 Dec 2024 19:54:00 +0300 Subject: [PATCH 16/16] added equals and hashcode to MainUserDetails --- .../wedemyserver/config/MainUserDetails.java | 13 +++++++++++++ .../wedemyserver/models/CustomOAuthUser.java | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/com/davistiba/wedemyserver/config/MainUserDetails.java b/src/main/java/com/davistiba/wedemyserver/config/MainUserDetails.java index f49b6e0..daac3e4 100644 --- a/src/main/java/com/davistiba/wedemyserver/config/MainUserDetails.java +++ b/src/main/java/com/davistiba/wedemyserver/config/MainUserDetails.java @@ -11,6 +11,7 @@ import java.io.Serializable; import java.util.Collection; import java.util.Collections; +import java.util.Objects; @Getter public class MainUserDetails implements UserDetails, Serializable { @@ -67,4 +68,16 @@ public boolean isEnabled() { return user.getEnabled(); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MainUserDetails that = (MainUserDetails) o; + return Objects.equals(user.getEmail(), that.user.getEmail()); + } + + @Override + public int hashCode() { + return Objects.hashCode(user.getEmail()); + } } diff --git a/src/main/java/com/davistiba/wedemyserver/models/CustomOAuthUser.java b/src/main/java/com/davistiba/wedemyserver/models/CustomOAuthUser.java index 6d783fe..309f44d 100644 --- a/src/main/java/com/davistiba/wedemyserver/models/CustomOAuthUser.java +++ b/src/main/java/com/davistiba/wedemyserver/models/CustomOAuthUser.java @@ -11,6 +11,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.Objects; /** * [NOT A TABLE] @@ -67,5 +68,17 @@ public String getEmail() { return oidcUser.getAttribute("email"); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + CustomOAuthUser that = (CustomOAuthUser) o; + return Objects.equals(oidcUser.getEmail(), that.oidcUser.getEmail()); + } + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), oidcUser); + } }