-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add total pricing to Homebox locations #42
Conversation
WalkthroughWalkthroughThe updates introduce a Changes
Sequence DiagramsItems Price Calculation FlowsequenceDiagram
participant Client
participant API
participant Controller
participant Database
Client->>API: Request all items
API->>Controller: HandleItemsGetAll()
Controller->>Database: Fetch items
Database-->>Controller: Return items
Controller->>Controller: Calculate TotalPrice
Controller-->>API: Return items with TotalPrice
API-->>Client: Response with items and TotalPrice
Location Price Calculation FlowsequenceDiagram
participant Client
participant API
participant Controller
participant Database
Client->>API: Request location with ID
API->>Controller: GetLocationWithPrice(GID, ID)
Controller->>Database: Fetch location and items
Database-->>Controller: Return location and items
Controller->>Controller: Calculate TotalPrice recursively
Controller-->>API: Return location with TotalPrice
API-->>Client: Response with location and TotalPrice
Assessment against linked issues
PoemIn code's embrace, values entwine, 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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
a374527
to
b57efa0
Compare
Deploying homebox-docs with Cloudflare Pages
|
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
Outside diff range and nitpick comments (1)
backend/internal/data/repo/repo_locations.go (1)
52-52
: Ensure consistency in data representation.Master Stark, I've noticed the addition of the
TotalPrice
field to theLocationOut
struct. It is crucial to ensure that this field is consistently updated across all operations that modify the location's data, particularly in methods that might affect the number of items or their prices within a location. This might require additional logic in update and delete operations to recalculate this field accurately.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- backend/app/api/handlers/v1/v1_ctrl_items.go (2 hunks)
- backend/app/api/handlers/v1/v1_ctrl_locations.go (3 hunks)
- backend/app/api/static/docs/swagger.json (3 hunks)
- backend/internal/data/repo/pagination.go (1 hunks)
- backend/internal/data/repo/repo_locations.go (1 hunks)
- docs/docs/api/openapi-2.0.json (3 hunks)
- frontend/lib/api/types/data-contracts.ts (2 hunks)
- frontend/pages/label/[id].vue (3 hunks)
- frontend/pages/location/[id].vue (1 hunks)
Files skipped from review due to trivial changes (1)
- frontend/pages/location/[id].vue
Additional comments not posted (10)
backend/internal/data/repo/pagination.go (1)
8-8
: TotalPrice field added to PaginationResultSir, the addition of the
TotalPrice
field to thePaginationResult
struct is fitting and aligns well with the feature's requirement to display aggregated financial information. This change should aid in providing comprehensive pagination results with financial data included.frontend/pages/label/[id].vue (3)
91-91
: Update to data fetching logicMr. Stark, the adjustment made here to return
resp.data
instead ofresp.data.items
is crucial for the integration of the new total price functionality. It ensures that the entire data object, including the new total price, is available for further processing.
118-128
: Enhancement in UI to display total priceIndeed, Mr. Stark, this modification in the template to conditionally render the total price is a splendid addition. It effectively utilizes the new
totalPrice
data to enhance the user's visual experience, displaying financial data succinctly and elegantly.
156-156
: Correct integration of item structureWell done on ensuring that the
items.items
structure is utilized correctly in theItemViewSelectable
component. This change is necessary to adapt to the modified data structure returned by the API.frontend/lib/api/types/data-contracts.ts (2)
235-235
: Addition of totalPrice to LocationOut interfaceA most fitting update, Mr. Stark. The inclusion of the
totalPrice
field in theLocationOut
interface aligns seamlessly with the backend enhancements, ensuring that the frontend can display the aggregated financial data effectively.
333-333
: Inclusion of totalPrice in PaginationResultItemSummaryIndeed, adding the
totalPrice
field to thePaginationResultItemSummary
interface is a strategic move. It ensures that the pagination results carry comprehensive financial data, enhancing the clarity and utility of the API responses.backend/app/api/handlers/v1/v1_ctrl_items.go (1)
84-91
: Optimize the total price calculation logic.Sir, while the logic to calculate the total price using the
big
package ensures precision with large numbers, it might be more efficient to perform the multiplication and division outside the loop to reduce computational overhead. Furthermore, the error handling from theFloat64
conversion should not be ignored to prevent potential data inaccuracies.
[REFACTOR_SUGGESTion]totalPrice := new(big.Int) for _, item := range items.Items { itemPrice := big.NewInt(int64(item.PurchasePrice * 100)) totalPrice.Add(totalPrice, itemPrice) } totalPriceFloat := new(big.Float).SetInt(totalPrice) totalPriceFloat.Quo(totalPriceFloat, big.NewFloat(100)) var err error items.TotalPrice, err = totalPriceFloat.Float64() if err != nil { log.Err(err).Msg("Failed to convert total price to float64") return validate.NewRequestError(err, http.StatusInternalServerError) }docs/docs/api/openapi-2.0.json (1)
2472-2474
: Addition of totalPrice field in LocationOutThe addition of the
totalPrice
field to theLocationOut
object is consistent with the PR's objective to display the total price of items at various locations. This field is correctly typed asnumber
, aligning with JSON schema standards for numeric data. Ensure that this field is populated correctly through backend logic and that its presence does not inadvertently affect any existing functionalities or calculations that depend on theLocationOut
object.backend/app/api/static/docs/swagger.json (2)
2472-2474
: Well done on thetotalPrice
addition torepo.LocationOut
.Your addition of the
totalPrice
field is logically sound and aligns with the structure and types used elsewhere in your API documentation. It's a clear and precise implementation. Keep up the excellent work!
2713-2715
: Excellent addition oftotalPrice
to pagination results.The integration of the
totalPrice
field into therepo.PaginationResult-repo_ItemSummary
structure is a thoughtful and useful enhancement. It provides a clear, aggregated view of financial data across items, which enhances the API's utility for end-users analyzing financial summaries. Well-executed!
Code review suggestion Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- backend/app/api/handlers/v1/v1_ctrl_items.go (2 hunks)
- backend/app/api/handlers/v1/v1_ctrl_locations.go (3 hunks)
- docs/docs/api/openapi-2.0.json (4 hunks)
Files skipped from review as they are similar to previous changes (3)
- backend/app/api/handlers/v1/v1_ctrl_items.go
- backend/app/api/handlers/v1/v1_ctrl_locations.go
- docs/docs/api/openapi-2.0.json
The code looks great to me. Not sure if recursively querying the whole location for each request is a good idea. This is probably plenty fast even with a lot of nested items, but some performance numbers would be nice. |
What type of PR is this?
What this PR does / why we need it:
Adds total price to locations to fix #40
Which issue(s) this PR fixes:
Fixes #40
Special notes for your reviewer:
Extensive review and testing required, code may need updating to reflect new docs. Please pay particular attention to formatting and to documentation.
Testing
Need assistance on testing this one please, if anybody is able to assist testing.
Summary by CodeRabbit
New Features
totalPrice
field to various API responses and data models.totalPrice
fields.UI Enhancements
Documentation
totalPrice
fields.