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

Add total pricing to Homebox locations #42

Merged
merged 12 commits into from
Jun 29, 2024
Merged

Conversation

katosdev
Copy link
Contributor

@katosdev katosdev commented Jun 22, 2024

What type of PR is this?

  • feature

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

    • Introduced calculation and display of total price for items and locations.
    • Added totalPrice field to various API responses and data models.
    • Enhanced API documentation to include totalPrice fields.
  • UI Enhancements

    • Updated label and location pages to display total price information.
  • Documentation

    • Updated API documentation to reflect new totalPrice fields.

Copy link
Contributor

coderabbitai bot commented Jun 22, 2024

Walkthrough

Walkthrough

The updates introduce a TotalPrice field to several key structures, enabling automatic calculation and summation of the total prices of items and their sub-items, both in items and locations. This results in a more efficient way to determine the value of parent items and locations by aggregating the prices of their respective child items.

Changes

Files Change Summary
backend/app/api/handlers/v1/v1_ctrl_items.go, v1_ctrl_locations.go Added calculations for TotalPrice to consolidate item and location values, and introduced recursion for nested items.
backend/app/api/static/docs/swagger.json, docs/docs/api/openapi-2.0.json Added totalPrice field in API documentation for items and locations.
backend/internal/data/repo/pagination.go, repo_locations.go Introduced TotalPrice field in response structures for pagination and location summaries.
frontend/lib/api/types/data-contracts.ts Added totalPrice field to TypeScript interfaces for item and location data contracts.
frontend/pages/label/[id].vue, frontend/pages/location/[id].vue Updated Vue components to handle and display the TotalPrice information for labels and locations respectively.

Sequence Diagrams

Items Price Calculation Flow

sequenceDiagram
    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
Loading

Location Price Calculation Flow

sequenceDiagram
    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
Loading

Assessment against linked issues

Objective Addressed Explanation
Add TotalPrice field to parent items and locations to sum child item values (Issue #40)

Poem

In code's embrace, values entwine,
Summing treasures, line by line.
From item roots to location's crest,
Prices flow, calculations blessed.
No longer count with weary mind,
For in this change, solutions find.
Enhanced now, the system gleams,
Automated, like heroes' dreams. 🌟


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@katosdev katosdev added the review needed A review is needed on this PR or Issue label Jun 22, 2024
@katosdev katosdev self-assigned this Jun 22, 2024
@katosdev katosdev marked this pull request as ready for review June 22, 2024 16:16
Copy link

cloudflare-workers-and-pages bot commented Jun 22, 2024

Deploying homebox-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 30abdd4
Status: ✅  Deploy successful!
Preview URL: https://a1a92b6e.homebox-docs.pages.dev
Branch Preview URL: https://katos-location-prices.homebox-docs.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 the LocationOut 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

Commits

Files that changed from the base of the PR and between 2a54933 and b57efa0.

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 PaginationResult

Sir, the addition of the TotalPrice field to the PaginationResult 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 logic

Mr. Stark, the adjustment made here to return resp.data instead of resp.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 price

Indeed, 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 structure

Well done on ensuring that the items.items structure is utilized correctly in the ItemViewSelectable 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 interface

A most fitting update, Mr. Stark. The inclusion of the totalPrice field in the LocationOut interface aligns seamlessly with the backend enhancements, ensuring that the frontend can display the aggregated financial data effectively.


333-333: Inclusion of totalPrice in PaginationResultItemSummary

Indeed, adding the totalPrice field to the PaginationResultItemSummary 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 the Float64 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 LocationOut

The addition of the totalPrice field to the LocationOut object is consistent with the PR's objective to display the total price of items at various locations. This field is correctly typed as number, 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 the LocationOut object.

backend/app/api/static/docs/swagger.json (2)

2472-2474: Well done on the totalPrice addition to repo.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 of totalPrice to pagination results.

The integration of the totalPrice field into the repo.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>
@tankerkiller125 tankerkiller125 self-requested a review June 22, 2024 20:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between b57efa0 and 30abdd4.

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

@icanc0
Copy link
Contributor

icanc0 commented Jun 24, 2024

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.

@katosdev katosdev merged commit 0f482ae into main Jun 29, 2024
6 checks passed
@katosdev katosdev deleted the katos/location-prices branch June 29, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review needed A review is needed on this PR or Issue
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Roll up subitem's value into parent item/location
3 participants