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

Begin adding Purchase Method to item purchase details #124

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

katosdev
Copy link
Contributor

@katosdev katosdev commented Jul 12, 2024

What type of PR is this?

  • feature

What this PR does / why we need it:

Adds support for Purchase Method, as requested in #117. This is a first-version PR with an MVP implementation.

Which issue(s) this PR fixes:

Fixes #117

Special notes for your reviewer:

Please take special care to review migrations, as I am more than likely going to be breaking implementations if the databases are not properly migrated to include the new tables.

Summary by CodeRabbit

  • New Features
    • Added purchaseMethod field across various components for better tracking of item purchase methods.
    • Enhanced CSV import functionality to include the new purchaseMethod field.
  • Bug Fixes
    • Resolved duplicated field definition in Swagger documentation.
  • Documentation
    • Updated API and CSV import documentation to include the new purchaseMethod field.
  • Tests
    • Added test coverage for the purchaseMethod field in item repository updates.

Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Warning

Rate limit exceeded

@katosdev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 49 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between ae8f568 and 809b0db.

Walkthrough

Walkthrough

The recent changes primarily involve introducing and integrating a new field, purchaseMethod, across various components in the codebase. This new field replaces the previously used PurchasePrice or PurchaseTime fields in certain contexts. The modifications span database schema updates, API definitions, service layer adjustments, data repository changes, and test cases to ensure the new field is adequately handled. The overarching goal is to track the method used for purchasing items, as requested in issue #117.

Changes

Files/Paths Change Summary
backend/app/api/static/docs/swagger.json Removed duplicate purchaseFrom field definition.
backend/app/api/static/docs/swagger.yaml, openapi-2.0.json Added a new purchaseMethod field of type string to the API definitions.
backend/internal/core/services/reporting/io_sheet.go, service_items.go Renamed PurchasePrice to PurchaseMethod in various methods and updated data mapping.
backend/internal/data/ent/schema/item.go Added optional purchase_method field to the Item schema.
backend/internal/data/migrations/migrations/20220929052825_init.sql Added purchase_method column to the items table in the database schema.
backend/internal/data/repo/repo_items.go Renamed PurchaseTime to PurchaseMethod, updated struct field order, and modified mapping functions.
backend/internal/data/repo/repo_items_test.go Added PurchaseMethod field to test data creation and assertions in the TestItemsRepository_Update function.
docs/en/import-csv.md Documented the new purchase_method field for CSV import functionality.
frontend/lib/api/__test__/user/stats.test.ts Added purchase_method field to ImportObj interface and updated importFileGenerator function to generate it.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant Database

    User ->> Frontend: Input purchase method
    Frontend ->> Backend: Submit item with purchase method
    Backend ->> Database: Store purchase method in items table
    Database ->> Backend: Acknowledge storage
    Backend ->> Frontend: Confirm item registration
    Frontend ->> User: Display confirmation
Loading

Assessment against linked issues

Objective (Issue #117) Addressed Explanation
Add a simple text field for purchase method
Reflect new field in database schema
Update API definitions to include purchase method
Modify service layer to handle purchase method
Update CSV import/export functionality

Poem

A method now tracks how you bought,
In code, this change we've wrought,
From YAML to the database table,
Ensuring your tracking is stable.
With tests and docs all in play,
Your warranties are just a click away. 🚀


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 self-assigned this Jul 12, 2024
@katosdev
Copy link
Contributor Author

CC @brenletheninja - WIP but just to keep you in the loop :)

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

Outside diff range, codebase verification and nitpick comments (1)
backend/internal/core/services/reporting/io_sheet.go (1)

205-208: Potential misassignment of PurchaseMethod in service_items.go.

It appears that in backend/internal/core/services/service_items.go, the PurchaseFrom field is being assigned the value of row.PurchaseMethod. This might be an error. Please verify and correct this assignment if necessary.

  • File: backend/internal/core/services/service_items.go
  • Line: PurchaseFrom: row.PurchaseMethod
Analysis chain

Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field appears to be correctly integrated into the ReadItems method. Ensure that this field is consistently used across the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the `PurchaseMethod` field across the codebase.

# Test: Search for the `PurchaseMethod` field usage. Expect: Consistent usage across the codebase.
rg --type go 'PurchaseMethod'

Length of output: 747

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 625730f and da78f13.

Files selected for processing (11)
  • backend/app/api/static/docs/swagger.json (1 hunks)
  • backend/app/api/static/docs/swagger.yaml (1 hunks)
  • backend/internal/core/services/reporting/io_sheet.go (1 hunks)
  • backend/internal/core/services/service_items.go (1 hunks)
  • backend/internal/data/ent/schema/item.go (1 hunks)
  • backend/internal/data/migrations/migrations/20220929052825_init.sql (1 hunks)
  • backend/internal/data/repo/repo_items.go (4 hunks)
  • backend/internal/data/repo/repo_items_test.go (2 hunks)
  • docs/docs/api/openapi-2.0.json (1 hunks)
  • docs/en/import-csv.md (1 hunks)
  • frontend/lib/api/test/user/stats.test.ts (2 hunks)
Files skipped from review due to trivial changes (3)
  • backend/app/api/static/docs/swagger.json
  • backend/app/api/static/docs/swagger.yaml
  • docs/docs/api/openapi-2.0.json
Additional comments not posted (10)
backend/internal/data/ent/schema/item.go (1)

79-80: Addition of purchase_method field is appropriate.

The purchase_method field has been added as an optional string field, which aligns with the existing schema design.

docs/en/import-csv.md (1)

66-66: Addition of HB.purchase_method column is appropriate.

The HB.purchase_method column has been added to the CSV reference with a clear description, aligning with the documentation style.

frontend/lib/api/__test__/user/stats.test.ts (2)

19-19: Addition of HB.purchase_method field in ImportObj interface is appropriate.

The HB.purchase_method field has been added to the ImportObj interface, aligning with the existing structure.


66-66: Addition of HB.purchase_method field in importFileGenerator function is appropriate.

The HB.purchase_method field has been added to the importFileGenerator function, generating a value using faker data, which aligns with the existing structure.

backend/internal/data/migrations/migrations/20220929052825_init.sql (1)

20-20: Addition of purchase_method column in items table is appropriate.

The purchase_method column has been added as a nullable text field, aligning with the existing table structure.

backend/internal/core/services/service_items.go (1)

301-301: Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field appears to be correctly integrated into the CsvImport method. Ensure that this field is consistently used across the codebase.

Verification successful

Integration of PurchaseMethod field is correct and consistent.

The PurchaseMethod field is appropriately integrated and consistently used across the codebase. The field appears in service methods, tests, and data structures without any issues.

  • backend/internal/core/services/service_items.go
  • backend/internal/data/repo/repo_items_test.go
  • backend/internal/data/repo/repo_items.go
  • backend/internal/core/services/reporting/io_sheet.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the `PurchaseMethod` field across the codebase.

# Test: Search for the `PurchaseMethod` field usage. Expect: Consistent usage across the codebase.
rg --type go 'PurchaseMethod'

Length of output: 747


Script:

#!/bin/bash
# Description: Gather context around the usage of the `PurchaseMethod` field in the identified files.

# Extract 5 lines before and after the match for better context.
rg --type go --context 5 'PurchaseMethod' backend/internal/core/services/service_items.go
rg --type go --context 5 'PurchaseMethod' backend/internal/data/repo/repo_items_test.go
rg --type go --context 5 'PurchaseMethod' backend/internal/data/repo/repo_items.go
rg --type go --context 5 'PurchaseMethod' backend/internal/core/services/reporting/io_sheet.go

Length of output: 3533

backend/internal/data/repo/repo_items_test.go (1)

239-239: Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field appears to be correctly integrated into the TestItemsRepository_Update method. Ensure that this field is consistently used across the codebase.

Also applies to: 266-266

Verification successful

Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field appears to be correctly integrated into the TestItemsRepository_Update method and other parts of the codebase. The field is consistently used across the data structures, service logic, and test cases.

  • backend/internal/data/repo/repo_items.go
  • backend/internal/data/repo/repo_items_test.go
  • backend/internal/core/services/service_items.go
  • backend/internal/core/services/reporting/io_sheet.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the `PurchaseMethod` field across the codebase.

# Test: Search for the `PurchaseMethod` field usage. Expect: Consistent usage across the codebase.
rg --type go 'PurchaseMethod'

Length of output: 747


Script:

#!/bin/bash
# Description: Gather context around the usages of the `PurchaseMethod` field in the identified files.

# Fetch lines around the usage in backend/internal/data/repo/repo_items.go
rg --type go --context 5 'PurchaseMethod' backend/internal/data/repo/repo_items.go

# Fetch lines around the usage in backend/internal/data/repo/repo_items_test.go
rg --type go --context 5 'PurchaseMethod' backend/internal/data/repo/repo_items_test.go

# Fetch lines around the usage in backend/internal/core/services/service_items.go
rg --type go --context 5 'PurchaseMethod' backend/internal/core/services/service_items.go

# Fetch lines around the usage in backend/internal/core/services/reporting/io_sheet.go
rg --type go --context 5 'PurchaseMethod' backend/internal/core/services/reporting/io_sheet.go

Length of output: 3533

backend/internal/data/repo/repo_items.go (3)

600-600: Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field appears to be correctly integrated into the UpdateByGroup method. Ensure that this field is consistently used across the codebase.

Verification successful

Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field appears to be correctly integrated into the UpdateByGroup method. Ensure that this field is consistently used across the codebase.

  • backend/internal/core/services/service_items.go: Line PurchaseFrom: row.PurchaseMethod,
  • backend/internal/core/services/reporting/io_sheet.go: Line PurchaseMethod: item.PurchaseMethod,
  • backend/internal/data/repo/repo_items_test.go: Lines PurchaseMethod: fk.Str(10), and assert.Equal(t, updateData.PurchaseMethod, got.PurchaseMethod)
  • backend/internal/data/repo/repo_items.go: Lines PurchaseMethod string json:"purchaseMethod"andSetPurchaseMethod(data.PurchaseMethod).`

Category:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the `PurchaseMethod` field across the codebase.

# Test: Search for the `PurchaseMethod` field usage. Expect: Consistent usage across the codebase.
rg --type go 'PurchaseMethod'

Length of output: 747


151-151: Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field appears to be correctly integrated into the ItemOut struct. Ensure that this field is consistently used across the codebase.

Verification successful

Integration of PurchaseMethod field is correct and consistent.

The PurchaseMethod field is consistently used across the codebase in various contexts, including tests, data repository, services, and reporting. This indicates a thorough integration of the new field.

  • backend/internal/data/repo/repo_items_test.go
  • backend/internal/data/repo/repo_items.go
  • backend/internal/core/services/service_items.go
  • backend/internal/core/services/reporting/io_sheet.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the `PurchaseMethod` field across the codebase.

# Test: Search for the `PurchaseMethod` field usage. Expect: Consistent usage across the codebase.
rg --type go 'PurchaseMethod'

Length of output: 747


94-94: Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field appears to be correctly integrated into the ItemUpdate struct. Ensure that this field is consistently used across the codebase.

Verification successful

Integration of PurchaseMethod field is correct.

The addition of the PurchaseMethod field is consistently used across the codebase in various contexts such as testing, service layer operations, and reporting. The integration appears to be correct and does not introduce any issues.

  • repo_items_test.go: Used for testing the PurchaseMethod field.
  • repo_items.go: Properly defined and assigned within the struct.
  • service_items.go: Utilized in service layer operations.
  • io_sheet.go: Used in reporting.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the `PurchaseMethod` field across the codebase.

# Test: Search for the `PurchaseMethod` field usage. Expect: Consistent usage across the codebase.
rg --type go 'PurchaseMethod'

Length of output: 747


Script:

#!/bin/bash
# Description: Verify the context of `PurchaseMethod` field usage in relevant files.

# Check the context of `PurchaseMethod` in repo_items_test.go
rg --type go --context 5 'PurchaseMethod' backend/internal/data/repo/repo_items_test.go

# Check the context of `PurchaseMethod` in repo_items.go
rg --type go --context 5 'PurchaseMethod' backend/internal/data/repo/repo_items.go

# Check the context of `PurchaseMethod` in service_items.go
rg --type go --context 5 'PurchaseMethod' backend/internal/core/services/service_items.go

# Check the context of `PurchaseMethod` in io_sheet.go
rg --type go --context 5 'PurchaseMethod' backend/internal/core/services/reporting/io_sheet.go

Length of output: 3533

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 da78f13 and 8772534.

Files selected for processing (1)
  • backend/internal/data/repo/repo_items.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • backend/internal/data/repo/repo_items.go

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 8772534 and ae8f568.

Files ignored due to path filters (1)
  • frontend/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (1)
  • backend/internal/data/repo/repo_items.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • backend/internal/data/repo/repo_items.go

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.

Track “Purchase method” for each item
1 participant