Skip to content

Commit

Permalink
refactor: update contract and user usecases
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemarlon committed Nov 18, 2024
1 parent a8a78e4 commit 685cd3f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 38 deletions.
4 changes: 2 additions & 2 deletions internal/domain/entity/crowdfunding.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type CrowdfundingRepository interface {
FindCrowdfundingsByInvestor(investor common.Address) ([]*Crowdfunding, error)
FindCrowdfundingById(id uint) (*Crowdfunding, error)
FindAllCrowdfundings() ([]*Crowdfunding, error)
CloseCrowdfunding(id uint) ([]*Order, error)
SettleCrowdfunding(id uint) ([]*Order, error)
CloseCrowdfunding(id uint) ([]*Crowdfunding, error)
SettleCrowdfunding(id uint) ([]*Crowdfunding, error)
UpdateCrowdfunding(crowdfunding *Crowdfunding) (*Crowdfunding, error)
DeleteCrowdfunding(id uint) error
}
Expand Down
4 changes: 2 additions & 2 deletions internal/infra/repository/crowdfunding_repository_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ func (r *CrowdfundingRepositorySqlite) FindCrowdfundingsByInvestor(investor comm
return crowdfundings, nil
}

func (r *CrowdfundingRepositorySqlite) CloseCrowdfunding(crowdfundingId uint) ([]*entity.Order, error) {
func (r *CrowdfundingRepositorySqlite) CloseCrowdfunding(crowdfundingId uint) ([]*entity.Crowdfunding, error) {
return nil, nil
}

func (r *CrowdfundingRepositorySqlite) SettleCrowdfunding(crowdfundingId uint) ([]*entity.Order, error) {
func (r *CrowdfundingRepositorySqlite) SettleCrowdfunding(crowdfundingId uint) ([]*entity.Crowdfunding, error) {
return nil, nil
}

Expand Down
21 changes: 13 additions & 8 deletions internal/usecase/user_usecase/create_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package user_usecase

import (
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
"github.com/rollmelette/rollmelette"
"github.com/tribeshq/tribes/internal/domain/entity"
)
Expand All @@ -12,10 +13,12 @@ type CreateUserInputDTO struct {
}

type CreateUserOutputDTO struct {
Id uint `json:"id"`
Role string `json:"role"`
Address common.Address `json:"address"`
CreatedAt int64 `json:"created_at"`
Id uint `json:"id"`
Role string `json:"role"`
Address common.Address `json:"address"`
InvestmentLimit *uint256.Int `json:"investment_limit,omitempty" gorm:"type:bigint"`
DebtIssuanceLimit *uint256.Int `json:"debt_issuance_limit,omitempty" gorm:"type:bigint"`
CreatedAt int64 `json:"created_at"`
}

type CreateUserUseCase struct {
Expand All @@ -38,9 +41,11 @@ func (u *CreateUserUseCase) Execute(input *CreateUserInputDTO, metadata rollmele
return nil, err
}
return &CreateUserOutputDTO{
Id: res.Id,
Role: res.Role,
Address: res.Address,
CreatedAt: res.CreatedAt,
Id: res.Id,
Role: res.Role,
Address: res.Address,
InvestmentLimit: res.InvestmentLimit,
DebtIssuanceLimit: res.DebtIssuanceLimit,
CreatedAt: res.CreatedAt,
}, nil
}
12 changes: 7 additions & 5 deletions internal/usecase/user_usecase/find_all_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ func (u *FindAllUsersUseCase) Execute() (*FindAllUsersOutputDTO, error) {
output := make(FindAllUsersOutputDTO, len(res))
for i, user := range res {
output[i] = &FindUserOutputDTO{
Id: user.Id,
Role: user.Role,
Address: user.Address,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
Id: user.Id,
Role: user.Role,
Address: user.Address,
InvestmentLimit: user.InvestmentLimit,
DebtIssuanceLimit: user.DebtIssuanceLimit,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
}
}
return &output, nil
Expand Down
12 changes: 7 additions & 5 deletions internal/usecase/user_usecase/find_user_by_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ func (u *FindUserByAddressUseCase) Execute(input *FindUserByAddressInputDTO) (*F
return nil, err
}
return &FindUserOutputDTO{
Id: res.Id,
Role: res.Role,
Address: res.Address,
CreatedAt: res.CreatedAt,
UpdatedAt: res.UpdatedAt,
Id: res.Id,
Role: res.Role,
Address: res.Address,
InvestmentLimit: res.InvestmentLimit,
DebtIssuanceLimit: res.DebtIssuanceLimit,
CreatedAt: res.CreatedAt,
UpdatedAt: res.UpdatedAt,
}, nil
}
25 changes: 16 additions & 9 deletions internal/usecase/user_usecase/find_user_by_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type FindUserByRoleInputDTO struct {
Role string `json:"role"`
}

type FindUserByRoleOutputDTO []*FindUserOutputDTO

type FindUserByRoleUseCase struct {
userRepository entity.UserRepository
}
Expand All @@ -19,16 +21,21 @@ func NewFindUserByRoleUseCase(userRepository entity.UserRepository) *FindUserByR
}

func (u *FindUserByRoleUseCase) Execute(input *FindUserByRoleInputDTO) ([]*FindUserOutputDTO, error) {
_, err := u.userRepository.FindUsersByRole(input.Role)
res, err := u.userRepository.FindUsersByRole(input.Role)
if err != nil {
return nil, err
}
// return &FindUserOutputDTO{
// Id: res.Id,
// Role: res.Role,
// Address: res.Address,
// CreatedAt: res.CreatedAt,
// UpdatedAt: res.UpdatedAt,
// }, nil
return nil, nil
output := make(FindUserByRoleOutputDTO, len(res))
for i, user := range res {
output[i] = &FindUserOutputDTO{
Id: user.Id,
Role: user.Role,
Address: user.Address,
InvestmentLimit: user.InvestmentLimit,
DebtIssuanceLimit: user.DebtIssuanceLimit,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
}
}
return output, nil
}
17 changes: 11 additions & 6 deletions internal/usecase/user_usecase/general_dto.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package user_usecase

import "github.com/ethereum/go-ethereum/common"
import (
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
)

type FindUserOutputDTO struct {
Id uint `json:"id"`
Role string `json:"role"`
Address common.Address `json:"address"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
Id uint `json:"id"`
Role string `json:"role"`
Address common.Address `json:"address"`
InvestmentLimit *uint256.Int `json:"investment_limit,omitempty" gorm:"type:bigint"`
DebtIssuanceLimit *uint256.Int `json:"debt_issuance_limit,omitempty" gorm:"type:bigint"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
1 change: 0 additions & 1 deletion internal/usecase/user_usecase/update_user.go

This file was deleted.

0 comments on commit 685cd3f

Please sign in to comment.