Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Seller Coupon Management REST API #54

Merged
merged 35 commits into from
Mar 26, 2024

Conversation

krkarma777
Copy link
Owner

This pull request introduces a set of RESTful APIs dedicated to managing seller coupons, marking a significant step towards integrating seller management functionalities within our service. The changes are aimed at providing a more flexible, efficient, and scalable way to handle coupon-related operations.

Key Features Implemented:

  • Create Coupon API: Enables sellers to create new coupons with customizable attributes such as discount rates, validity periods, and applicable products.
  • Update Coupon API: Allows for the modification of existing coupons, offering flexibility in managing ongoing promotions.
  • Delete Coupon API: Facilitates the removal of coupons from the system, ensuring that outdated or invalid promotions are cleanly managed.
  • List Coupons API: Provides a comprehensive view of all coupons created by a seller, with filtering capabilities to navigate through promotions easily.
  • Coupon Application API: A specialized endpoint that manages the application of coupons to products, aligning with dynamic business strategies.

These APIs were designed with REST principles in mind, ensuring compatibility and ease of integration with existing and future frontend frameworks. Through rigorous testing and adherence to best practices, the implementation aims to provide a reliable and user-friendly interface for sellers to manage their promotional activities effectively.

Moving forward, this integration lays the groundwork for further enhancements in seller management, opening pathways to more automated and data-driven approaches in managing sales and promotions.

Implemented a new endpoint to retrieve a paginated list of reviews for a given seller, identified by sellerID. The method validates the user's role to ensure they are authorized as a seller before fetching the reviews. It handles pagination and sorting of reviews in descending order based on reviewID. Added error handling for unauthorized access attempts.

- Ensure user role validation for seller-specific actions.
- Utilize pageable for efficient data fetching and pagination.
- Return descriptive error messages for unauthorized requests.
This commit introduces several key changes to the ReviewAPIControllerTest. Notably, it adds new tests for handling reviews by sellers, accommodating the differentiation between authorized seller roles and other user roles. The tests now include scenarios for both valid requests by sellers and unauthorized requests by non-seller roles, ensuring robust access control. Additionally, the ReviewDetailDTO is introduced in tests to better represent review details, aligning with the latest business logic. These modifications enhance test clarity, expand coverage for new functionalities, and improve alignment with current domain models and access control requirements.
Updated the findReviewsBySeller method to include total pages and the list of review details in the response. This change aims to provide clients with more comprehensive data for UI rendering and pagination handling. Now, the response not only contains the list of reviews but also the total number of pages, enabling clients to implement more effective data presentation and navigation features.
…ntent loading

- Refactor SellerReviewManageController to SellerController and adjust its logic to pass sellerID instead of reviews list directly to the model. This change facilitates the front-end to fetch reviews dynamically via an API call.
- Update the corresponding Thymeleaf view to remove static content rendering of reviews. Integrate Axios to fetch reviews data dynamically from the server and implement pagination functionality. This improves the page's responsiveness and scalability by loading reviews content on demand.
- Add Axios script import in the HTML header for making HTTP requests.
- Added GET mapping to fetch coupons associated with a specific seller.
- Validates if the user is authorized as a seller before proceeding.
- Utilizes pagination to manage large result sets.
- Returns a ResponseEntity containing the list of coupons and total pages.
- Changed sorting criteria for coupon list from 'id' to 'couponID'.
- Improved code efficiency by using .toList() method for stream conversion.
- Integrated CouponApplicableProduct entity to reflect real-world applicability scenarios in tests.
- Adopted UserRole enum to enforce role-based testing rigorously.
- Introduced CouponResponseDTO in tests to align with the API response structure, ensuring consistency between test expectations and actual API behavior.
- Revised sorting criteria in listCouponsTest to 'couponID', matching the updated business logic.
- Utilized UUID for coupon codes to simulate realistic test scenarios more closely.
- Enhanced setUp method to include initialization of new attributes, such as applicableProducts, ensuring a comprehensive testing setup.
…type description

- Updated CouponResponseDTO to format date strings using DateTimeFormatter.
- Changed the 'type' field to display the description of the coupon type.
- Refactored CouponAPIController to return CouponResponseDTOs instead of entity objects to improve consistency and maintainability.
- Updated the endpoint logic for finding coupons by seller to utilize DTOs consistently.
…implification

This commit refactors the SellerCouponManageController by cleaning up the routing paths and simplifying the logic within the controller methods. The primary changes include adjusting the request mappings to more accurately reflect the intended actions and streamlining the method implementations for clarity and efficiency. Additionally, unnecessary code and comments have been removed to enhance readability and maintainability.
…ce pagination support.

This change introduces the currentPage variable in the response body of the findListBySeller API method. This enhancement allows the front-end to accurately display the current page number in the pagination component, improving user navigation experience across paginated coupon lists for sellers.
The update involves modifications to the client-side script to dynamically generate pagination buttons based on the currentPage value. This enhancement includes the ability to request and display different pages of coupons without reloading the page, providing a smoother and more responsive user interface for navigating through coupon lists.
…lified date and time parsing for coupon validity periods, and streamlined the handling of coupon-related actions such as creation, editing, and deletion. Removed redundant code and optimized imports for better performance and readability.
…stency.

This update includes optimizations for the coupon management modal's user interactions, ensuring smoother functionality and improved user experience. Changes have been made to modal buttons' order and event handlers for more intuitive navigation and operation. The update aims to provide a more consistent and user-friendly interface across the coupon management features.
Added a new method to handle GET requests at `/searchForCoupon` in the ProductAPIController, enabling sellers to search for products based on a specific query. This functionality supports pagination and returns a list of products matching the query after verifying the seller's permissions. This enhancement is aimed at facilitating more efficient product management for sellers in relation to coupons.
…Controller

- Removed unused imports and dependencies from SellerCouponManageController to simplify the coupon management process.
- Integrated `selectProductForCouponForm` method into SellerController to consolidate endpoints, aligning with RESTful API design principles.
- Enhanced readability and maintainability by reducing redundancy and focusing on streamlined controller actions.

This refactor improves the architecture by adhering more closely to RESTful principles, simplifying future developments and adjustments in the coupon management and review sections.
… enhance product selection for coupons. This commit introduces a dedicated API controller for handling coupon-applicable products, streamlines the process of selecting products for coupons through a RESTful endpoint, and removes outdated methods from the SellerController to align with RESTful practices.
…m CouponAPIController to CouponApplicableProductAPIController and updated SellerController for RESTful compliance. This change enhances modularity and aligns with REST principles, improving maintainability and scalability of coupon-related functionalities.
…onous product search and selection, enhancing user experience.
- Introduced CouponApplicableProductRequestDTO for robust request data validation, utilizing @notempty annotation to prevent missing couponID.
- Added CouponApplicableProductValidator to enforce coupon ownership checks and validate applicability of products to coupons, ensuring data integrity and authorization.
- Refactored CouponApplicableProductAPIController to leverage the new DTO and validator for a cleaner, more maintainable approach to handling coupon-product associations.
- These changes aim to improve the reliability and security of the coupon application process, facilitating easier management and application of products to coupons.
This commit introduces a validation step in the `validateAndApplyProductsToCoupon` method to ensure that the products being applied to a coupon are indeed posted by the current user. This check is crucial for maintaining data integrity and preventing unauthorized coupon applications to products not owned by the user. The method now filters out any products not posted by the user before proceeding with the coupon application process, and throws a `ResponseStatusException` if any discrepancies are found.

- Add a filter to `validateAndApplyProductsToCoupon` to check product ownership.
- Throw `ResponseStatusException` for products not posted by the current user.
- Ensure only products owned by the user are applied to the coupon.

This enhancement strengthens the security and integrity of the coupon application process.
Added a unit test to ensure that the controller method for selecting products applicable to a coupon processes requests correctly when valid data is provided. Mocked necessary dependencies and simulated valid data for the test scenario.
…ollerTest

- Fix incorrect Product instantiation with non-existing constructor by adjusting product IDs.
- Ensure each mocked Product object has a unique ID reflecting the intended test scenario.
- This correction ensures the test setup accurately reflects the real-world scenario where each product has a unique identifier and is associated with a user.
- The changes enhance the reliability of the `selectProductForCoupon_ShouldProcessRequest_WhenGivenValidData` test by ensuring the mocked data setup aligns with expected domain model constraints.
Removed SellerCouponManageController as it is no longer needed after transitioning to API.
…rincipal

- Add a null check for the Principal parameter in the getCurrentUser method to avoid NullPointerException when the Principal is null.
- Throw an Unauthorized status exception if the Principal is null to indicate that no authenticated user information is available.
- Ensure that a meaningful error response is returned when no user context is available in the request.
- Added a global exception handler to handle ResponseStatusException.
- Configured to return a response including the status code and reason when an exception occurs.
Added a constructor with parameters to the Coupon class.
…rror scenarios

This commit overhauls the CouponApplicableProductAPIControllerTest to include comprehensive testing for different error scenarios, including unauthorized access, ownership validation for products, handling of invalid product information, and non-existent coupons. Additionally, it updates the test for successful coupon application to ensure proper validation and processing. The goal is to enhance test coverage and reliability for the coupon application process in the API.
- Added a test for the endpoint that retrieves a list of products applicable to a coupon.
- Improved existing tests by including JSON body content verification.
- Refactored setup method to initialize common objects for tests.
This commit introduces an enhancement to the coupon product selection functionality on the "쿠폰 적용 상품 설정" page. Key improvements include the AJAX-based form submission process, enabling dynamic interaction without page reloads. The form now sends selected product IDs directly to the server-side endpoint via AJAX POST request, streamlining the user experience. Additionally, error handling is enhanced to provide user-friendly feedback using alerts for various error conditions encountered during form submission and data fetching operations. These changes aim to improve the usability and responsiveness of the product selection workflow for coupon application.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant