-
Notifications
You must be signed in to change notification settings - Fork 0
Model data #12
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
Model data #12
Conversation
WalkthroughThis pull request introduces significant changes to the cart and data model functionality in the application. The changes include renaming fields from Changes
Sequence DiagramsequenceDiagram
participant User
participant DataModelCartController
participant ModelCartService
participant CartRepository
participant DataModelRepository
User->>DataModelCartController: Add item to cart
DataModelCartController->>ModelCartService: addToCartByUsernameAndTag
ModelCartService->>DataModelRepository: findByTag
DataModelRepository-->>ModelCartService: Return DataModel
ModelCartService->>CartRepository: Save/Update Cart
CartRepository-->>ModelCartService: Confirm Cart update
ModelCartService-->>DataModelCartController: Return updated Cart
DataModelCartController-->>User: Respond with Cart
Possibly related PRs
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
src/main/java/com/example/redunm/cart/DataModelCartController.java (3)
11-12: Autowiring the service
Using field injection is functional, but constructor injection is typically recommended for better testability and immutability.- @Autowired - private ModelCartService modelCartService; + private final ModelCartService modelCartService; + public DataModelCartController(ModelCartService modelCartService) { + this.modelCartService = modelCartService; + }
21-24: Remove item endpoint
Uses@DeleteMappingwith correct path variables. Consider validating if tag is non-existent or user is not the owner.
33-36: Calculate total endpoint
Endpoint is correct. Consider potential concurrency issues if cart changes while calculating total.src/main/java/com/example/redunm/cart/ModelCartService.java (1)
51-53: Clear cart method
Clears items from an existing cart. Confirm if logging or user feedback are required.src/main/java/com/example/redunm/cart/Cart.java (1)
66-77: removeItemByTag
Removes matching item by tag. Debug prints are helpful but consider using logger instead ofSystem.out.- System.out.println("Before removal: " + items); + logger.debug("Before removal: {}", items);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
src/main/java/com/example/redunm/CartDataInitializer.java(1 hunks)src/main/java/com/example/redunm/InitializeModels.java(1 hunks)src/main/java/com/example/redunm/cart/Cart.java(5 hunks)src/main/java/com/example/redunm/cart/CartItem.java(1 hunks)src/main/java/com/example/redunm/cart/CartRepository.java(1 hunks)src/main/java/com/example/redunm/cart/DataModelCartController.java(1 hunks)src/main/java/com/example/redunm/cart/ModelCartService.java(2 hunks)src/main/java/com/example/redunm/config/SecurityConfig.java(1 hunks)src/main/java/com/example/redunm/dto/AddModel.java(0 hunks)src/main/java/com/example/redunm/dto/ModelImgDto.java(0 hunks)src/main/java/com/example/redunm/modellist/DataModel.java(2 hunks)src/main/java/com/example/redunm/modellist/DataModelCartController.java(0 hunks)src/main/java/com/example/redunm/modellist/DataModelRepository.java(1 hunks)
💤 Files with no reviewable changes (3)
- src/main/java/com/example/redunm/dto/ModelImgDto.java
- src/main/java/com/example/redunm/modellist/DataModelCartController.java
- src/main/java/com/example/redunm/dto/AddModel.java
✅ Files skipped from review due to trivial changes (2)
- src/main/java/com/example/redunm/CartDataInitializer.java
- src/main/java/com/example/redunm/cart/CartItem.java
🔇 Additional comments (35)
src/main/java/com/example/redunm/cart/CartRepository.java (1)
10-10: Use consistent domain terminology or ensure it's well-documented.
Renaming findByUserId to findByUsername is a good move for improved clarity, but be mindful of any external references still using userId. If this is the final approach, consider verifying that all domain documentation, references, and downstream usage are updated to match the new naming convention.
src/main/java/com/example/redunm/modellist/DataModelRepository.java (3)
4-4: Thank you for adding the @repository annotation.
This improves clarity and ensures Spring picks up this interface as a bean.
8-8: No functional changes needed.
Having the repository clearly annotated increases maintainability.
11-11: Ensure proper usage and test coverage of the new method.
The findByTag(String tag) method is a welcome addition. To avoid potential issues:
- Validate that
tagisn't null or empty when calling the method. - Consider adding a unit or integration test to verify the method returns the expected results.
src/main/java/com/example/redunm/InitializeModels.java (1)
1-22: All lines are commented out—verify if this is intentional.
It seems this file is currently inactive. If it’s a placeholder for future initialization logic:
- Confirm whether
InitializeModelsis intended for production or testing. - Un-comment or remove the code if it’s no longer needed.
Would you like help refactoring and enabling this class so that models are only initialized when appropriate (e.g., on application startup in a development environment)?
src/main/java/com/example/redunm/modellist/DataModel.java (3)
14-14: Added description field looks good.
Thank you for including descriptive data. This is useful for user-facing context or advanced queries.
18-22: Constructor additions are aligned.
Accepting a description param is consistent with the new field.
57-62: Methods for handling description are correct.
The getters and setters are well-formed and straightforward. Ensure coverage in unit tests, especially if additional logic around description is introduced later (e.g. non-empty constraints or length checks).
[approve]
src/main/java/com/example/redunm/cart/DataModelCartController.java (5)
1-2: Use consistent package naming for clarity
The package name is clear, but make sure the rest of the application consistently references redunm without typos (like reduNm vs. redunm).
3-5: Ensure necessary imports are used
All imports appear necessary for this controller. No issues found.
7-9: Class definition is well-structured
Annotations and mapping are correct, forming a clear REST controller for cart APIs.
15-18: Add to cart endpoint
Method properly uses @PostMapping and extracts path variables. Ensure validation if tag might be empty.
27-30: Get cart endpoint
Method logic is straightforward. Ensure a fallback scenario or exception handling if the cart is consistently empty.
src/main/java/com/example/redunm/cart/ModelCartService.java (8)
1-1: Package migration note
Package location has been updated from modellist to cart. Confirm that older references in other classes are also updated.
17-18: Method name clarity
Renaming from addToCartByUsernameAndModelName to addToCartByUsernameAndTag is consistent with the updated naming convention for tags.
19-19: Initialize new cart if not found
Creating a new cart for a new user is a good approach. Ensure there's no requirement for user registration checks prior.
21-22: Handling missing DataModel
Throws IllegalArgumentException if model is not found. This is acceptable; ensure the calling code gracefully handles this exception.
28-30: Method rename for remove operation
Refactor to removeItemByUsernameAndTag is consistent with the new approach of using tags.
33-33: Remove item from cart
Uses cart’s removeItemByTag. Ensure no concurrency issues if multiple removals happen simultaneously.
37-39: Calculate total method
Retrieves cart by username and defers the calculation to cart. This separation of concerns is good.
45-47: Get cart method
Returns a new cart if none exists. This is consistent with the add method’s logic.
src/main/java/com/example/redunm/config/SecurityConfig.java (4)
23-23: CORS defaults
Keeping CORS on defaults is typically fine. Confirm the required origins are set if cross-domain requests are expected.
35-35: Require authentication
All other endpoints require authentication by default. This is standard practice.
38-43: Form login configuration
Customizing login page and processing URL is correctly set. The default success URL is /home. Ensure /home endpoint is available and not restricted unexpectedly.
46-47: Logout URL
/api/auth/logout is set, with success redirect to root. This is clear to users.
src/main/java/com/example/redunm/cart/Cart.java (10)
1-1: Package definition
File properly scoped under cart package. No issues.
10-10: Document annotation
Uses @Document("cart"), making it a dedicated MongoDB collection. Minimal risk.
16-16: Field rename from userId to username
This aligns with the new naming convention. Make sure external references are updated.
24-26: Constructor alignment
Constructor sets username and initializes items. This is consistent with other references.
39-40: Getter rename
getUsername instead of getUserId. This is consistent with the rename.
43-44: Setter rename
setUsername also consistent with the rename.
58-58: Adding item logic
Checks if item already exists by matching tags. This is correct usage.
93-93: equals method
Uses username for equality. This is correct because the cart is now identified by username.
98-98: hashCode method
Also uses username. Consistent with equals.
106-106: toString method
Reflects updated username field. Good for debugging.
| "/api/auth/signup/**", // 회원가입 관련 요청 허용 | ||
| "/api/auth/login/**", // 로그인 관련 요청 허용 | ||
| "/api/cart/**", // 장바구니 API 요청 허용 | ||
| "/api/data-models/**", // 데이터 모델 API 요청 허용 | ||
| "/css/**", // 정적 리소스 허용 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public endpoints
Allowing signup, login, cart, and data-models. Double-check for potential security concerns around the cart endpoints if an account is not mandatory.
Consider restricting cart operations to authenticated users only.
Summary by CodeRabbit
New Features
DataModelclass with a newdescriptionfield.Bug Fixes
Documentation
Chores