Skip to content

Conversation

@jyx0615
Copy link
Contributor

@jyx0615 jyx0615 commented Apr 21, 2025

Description

This pull request defines interfaces for interacting with both the database and the cache for investment-related operations.

Key Features:

  • Repository Interface:

    • CreateUserInvestment: Adds a new user investment to the database.
    • GetUserInvestments: Retrieves all investments associated with a specific user.
    • GetOpportunities: Retrieves all available investment opportunities for a user.
  • TransactionStore Interface:

    • GetOpportunities: Retrieves cached opportunities for a specific user.
    • GetInvestments: Retrieves cached investments for a specific user.
    • SetOpportunities: Caches opportunities for a specific user.
    • SetInvestments: Caches investments for a specific user.
    • DeleteOpportunities: Removes cached opportunities for a specific user.
    • DeleteInvestments: Removes cached investments for a specific user.

Tests

  • Manual testing
  • Unit tests

Other Changes

  • Fixed type mismatches in the entities.Investment, entities.transaction, and entities.goals by standardizing primitive.ObjectID for ID, OpportunityID, userID fields.
  • Updated related tests to reflect the type changes.
  • Fix package typo by changing responde to respond.

@jyx0615 jyx0615 requested review from Rice9547 and Copilot April 21, 2025 07:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces interfaces and implementations for handling investment-related operations with both database and cache, while updating data types (using primitive.ObjectID) and adding corresponding tests. Key changes include:

  • New Repository and InvestmentStore interfaces for database and cache operations.
  • Updates to tests and DTOs to reflect changes from string IDs to primitive.ObjectID.
  • Additions and modifications in HTTP handlers and routes to support investment opportunity creation and retrieval.

Reviewed Changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/module/investment/repository/repository.go New interfaces for Repository and InvestmentStore added.
internal/module/investment/domain/* Domain interfaces and corresponding mocks updated.
internal/interfaces/http/* Tests and HTTP handlers updated to work with ObjectID types.
internal/infrastructure/persistence/redis/* Redis persistence implementations and tests for investments added.
internal/infrastructure/persistence/mongodb/* MongoDB persistence implementations and tests updated with ObjectIDs.
internal/entities/* Entities updated to use primitive.ObjectID for ID fields.
cmd/server/route.go New route added for CreateOpportunity.
Comments suppressed due to low confidence (2)

internal/infrastructure/persistence/mongodb/investment.go:12

  • There is a typo in the type name 'MongoInvestmentResporitory'; consider renaming it to 'MongoInvestmentRepository' to improve clarity and consistency.
type MongoInvestmentResporitory struct {

internal/interfaces/http/investment.go:104

  • The InvestmentResponse no longer includes the investment ID. If clients rely on this ID for identification or further operations, consider including investment.ID in the response.
-		ID:            investment.ID,

@Rice9547
Copy link
Member

The current implementation looks good overall.

As you proceed with implementing the service layer, please pay attention to ensuring the cache reflects the correct state after database operations. Given the scale of the project, we don’t need to worry too much about high-concurrency scenarios for now.

To handle cases like user-initiated updates and ensure fresh data is served, it would be sufficient to simply invalidate the relevant cache entries at the time of update.

@jyx0615 jyx0615 force-pushed the feat/implement_investment_service branch from c089b15 to 1d04662 Compare April 24, 2025 00:43
@jyx0615 jyx0615 requested review from Rice9547 and Copilot April 24, 2025 01:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the interfaces and persistence layers for investment-related operations by standardizing the use of primitive.ObjectID and by adding support for creating investment opportunities.

  • Updated type definitions and conversions for IDs in investments, goals, and transactions.
  • Fixed the package typo from “responde” to “respond” across multiple files.
  • Added CreateOpportunity endpoints and corresponding tests for investments.

Reviewed Changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/interfaces/http/respond/respond.go Fixed package name typo.
internal/interfaces/http/investment_test.go Updated tests to use primitive.ObjectID and hex conversions.
internal/interfaces/http/investment_mock.go Updated mock methods and comments.
internal/interfaces/http/investment.go Added CreateOpportunity interface and updated error handling with the new “respond” package.
internal/interfaces/http/goals*.go, gacha.go, auth.go Updated package name fixes and ID conversions.
internal/infrastructure/persistence/redis/* Adjusted tests and methods to use primitive IDs.
internal/infrastructure/persistence/mongodb/* Updated tests and repository implementations for investments and transactions.
internal/entities/* Updated entity definitions to use primitive.ObjectID.
cmd/server/route.go Added CreateOpportunity route.
Comments suppressed due to low confidence (1)

internal/infrastructure/persistence/mongodb/investment.go:12

  • The struct name 'MongoInvestmentResporitory' appears to be misspelled. Consider renaming it to 'MongoInvestmentRepository' for consistency and clarity.
type MongoInvestmentResporitory struct {

@Rice9547 Rice9547 merged commit 0d31314 into master Apr 25, 2025
1 check passed
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.

3 participants