Skip to content

Commit

Permalink
Merge pull request #13 from LerianStudio/feature/account-module
Browse files Browse the repository at this point in the history
Refactored Account Module
  • Loading branch information
caioaletroca authored Nov 12, 2024
2 parents bda80c6 + 00007cd commit 1fd4103
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 149 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { container } from '@/core/infrastructure/container-registry/container-registry'
import { apiErrorHandler } from '@/app/api/utils/api-error-handler'
import { DeleteAccount } from '@/core/application/use-cases/accounts/delete-account-use-case'
import { FetchAccountById } from '@/core/application/use-cases/accounts/fetch-account-by-id-use-case'
import { UpdateAccount } from '@/core/application/use-cases/accounts/update-account-use-case'
import {
container,
Registry
} from '@/core/infrastructure/container-registry/container-registry'
DeleteAccount,
DeleteAccountUseCase
} from '@/core/application/use-cases/accounts/delete-account-use-case'
import {
FetchAccountById,
FetchAccountByIdUseCase
} from '@/core/application/use-cases/accounts/fetch-account-by-id-use-case'
import {
UpdateAccount,
UpdateAccountUseCase
} from '@/core/application/use-cases/accounts/update-account-use-case'
import { NextResponse } from 'next/server'

const updateAccountUseCase: UpdateAccount = container.get<UpdateAccount>(
Registry.UpdateAccountUseCase
)
const updateAccountUseCase: UpdateAccount =
container.get<UpdateAccount>(UpdateAccountUseCase)

const deleteAccountUseCase: DeleteAccount = container.get<DeleteAccount>(
Registry.DeleteAccountUseCase
)
const deleteAccountUseCase: DeleteAccount =
container.get<DeleteAccount>(DeleteAccountUseCase)

const getAccountByIdUseCase: FetchAccountById = container.get<FetchAccountById>(
Registry.FetchAccountByIdUseCase
FetchAccountByIdUseCase
)

export async function GET(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { container } from '@/core/infrastructure/container-registry/container-registry'
import { apiErrorHandler } from '@/app/api/utils/api-error-handler'
import { CreateAccount } from '@/core/application/use-cases/accounts/create-account-use-case'
import { FetchAllAccounts } from '@/core/application/use-cases/accounts/fetch-all-account-use-case'
// Update import statements

import {
container,
Registry
} from '@/core/infrastructure/container-registry/container-registry'
CreateAccount,
CreateAccountUseCase
} from '@/core/application/use-cases/accounts/create-account-use-case'
import {
FetchAllAccounts,
FetchAllAccountsUseCase
} from '@/core/application/use-cases/accounts/fetch-all-account-use-case'

import { NextResponse } from 'next/server'

// Update use case references
const createAccountUseCase: CreateAccount = container.get<CreateAccount>(
Registry.CreateAccountUseCase
)
const createAccountUseCase: CreateAccount =
container.get<CreateAccount>(CreateAccountUseCase)

const fetchAllAccountsUseCase: FetchAllAccounts =
container.get<FetchAllAccounts>(Registry.FetchAllAccountsUseCase)
container.get<FetchAllAccounts>(FetchAllAccountsUseCase)

export async function GET(
request: Request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CreateAccountsRepository } from '@/core/domain/repositories/accounts/cr
import { CreateAccountDto, AccountResponseDto } from '../../dto/account-dto'
import { AccountEntity } from '@/core/domain/entities/account-entity'
import { AccountMapper } from '../../mappers/account-mapper'
import { inject, injectable } from 'inversify'

export interface CreateAccount {
execute: (
Expand All @@ -12,8 +13,10 @@ export interface CreateAccount {
) => Promise<AccountResponseDto>
}

@injectable()
export class CreateAccountUseCase implements CreateAccount {
constructor(
@inject(CreateAccountsRepository)
private readonly createAccountRepository: CreateAccountsRepository
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DeleteAccountsRepository } from '@/core/domain/repositories/accounts/delete-accounts-repository'
import { inject, injectable } from 'inversify'

export interface DeleteAccount {
execute: (
Expand All @@ -9,8 +10,10 @@ export interface DeleteAccount {
) => Promise<void>
}

@injectable()
export class DeleteAccountUseCase implements DeleteAccount {
constructor(
@inject(DeleteAccountsRepository)
private readonly deleteAccountRepository: DeleteAccountsRepository
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FetchAccountByIdRepository } from '@/core/domain/repositories/accounts/fetch-account-by-id-repository'
import { AccountResponseDto } from '../../dto/account-dto'
import { AccountMapper } from '../../mappers/account-mapper'
import { inject, injectable } from 'inversify'

export interface FetchAccountById {
execute: (
Expand All @@ -11,8 +12,10 @@ export interface FetchAccountById {
) => Promise<AccountResponseDto>
}

@injectable()
export class FetchAccountByIdUseCase implements FetchAccountById {
constructor(
@inject(FetchAccountByIdRepository)
private readonly fetchAccountByIdRepository: FetchAccountByIdRepository
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AccountMapper } from '../../mappers/account-mapper'
import { AccountEntity } from '@/core/domain/entities/account-entity'
import { AccountResponseDto } from '../../dto/account-dto'
import { FetchAllAccountsRepository } from '@/core/domain/repositories/accounts/fetch-all-accounts-repository'
import { inject, injectable } from 'inversify'

export interface FetchAllAccounts {
execute: (
Expand All @@ -15,8 +16,10 @@ export interface FetchAllAccounts {
) => Promise<PaginationDto<AccountResponseDto>>
}

@injectable()
export class FetchAllAccountsUseCase implements FetchAllAccounts {
constructor(
@inject(FetchAllAccountsRepository)
private readonly fetchAllAccountsRepository: FetchAllAccountsRepository
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { UpdateAccountsRepository } from '@/core/domain/repositories/accounts/up
import { AccountResponseDto, UpdateAccountDto } from '../../dto/account-dto'
import { AccountMapper } from '../../mappers/account-mapper'
import { AccountEntity } from '@/core/domain/entities/account-entity'
import { inject, injectable } from 'inversify'

export interface UpdateAccount {
execute: (
Expand All @@ -13,8 +14,10 @@ export interface UpdateAccount {
) => Promise<AccountResponseDto>
}

@injectable()
export class UpdateAccountUseCase implements UpdateAccount {
constructor(
@inject(UpdateAccountsRepository)
private readonly updateAccountRepository: UpdateAccountsRepository
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { PortfolioEntity } from '@/core/domain/entities/portfolios-entity'
import { AccountEntity } from '../../entities/account-entity'

export interface CreateAccountsRepository {
create: (
export abstract class CreateAccountsRepository {
abstract create: (
organizationId: string,
ledgerId: string,
portfolioId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface DeleteAccountsRepository {
delete: (
export abstract class DeleteAccountsRepository {
abstract delete: (
organizationId: string,
ledgerId: string,
portfolioId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AccountEntity } from '../../entities/account-entity'

export interface FetchAccountByIdRepository {
fetchById: (
export abstract class FetchAccountByIdRepository {
abstract fetchById: (
organizationId: string,
ledgerId: string,
portfolioId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AccountEntity } from '../../entities/account-entity'
import { PaginationEntity } from '../../entities/pagination-entity'

export interface FetchAllAccountsRepository {
fetchAll: (
export abstract class FetchAllAccountsRepository {
abstract fetchAll: (
organizationId: string,
ledgerId: string,
portfolioId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AccountEntity } from '../../entities/account-entity'

export interface UpdateAccountsRepository {
update: (
export abstract class UpdateAccountsRepository {
abstract update: (
organizationId: string,
ledgerId: string,
portfolioId: string,
Expand Down
110 changes: 0 additions & 110 deletions src/core/infrastructure/container-registry/account-module.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
} from '@/core/application/use-cases/portfolios-accounts/fetch-portfolios-accounts-use-case'
import { AuthModule, AuthRegistry } from './auth-module'

import { AccountModule, AccountRegistry } from './account-module'
import { AssetModule, AssetRegistry } from './asset-module'
import { ProductRegistry, ProductModule } from './product-module'

Expand All @@ -23,10 +22,10 @@ import { MidazFetchAllAssetsRepository } from '../midaz/assets/midaz-fetch-all-a
import { MidazFetchAllPortfoliosRepository } from '../midaz/portfolios/midaz-fetch-all-portfolio-repository'
import { MidazFetchAllAccountsRepository } from '../midaz/accounts/midaz-fetch-all-accounts-repository'
import { PortfolioUseCaseModule } from './use-cases/portfolios-module'
import { AccountUseCaseModule } from './use-cases/account-module'

export const Registry = {
...AuthRegistry,
...AccountRegistry,
...AssetRegistry,
...ProductRegistry,

Expand All @@ -43,9 +42,9 @@ container.load(MidazModule)
container.load(OrganizationUseCaseModule)
container.load(LedgerUseCaseModule)
container.load(PortfolioUseCaseModule)
container.load(AccountUseCaseModule)

container.container.load(AuthModule)
container.container.load(AccountModule)
container.container.load(AssetModule)
container.container.load(ProductModule)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Container, ContainerModule } from '../../utils/di/container'

import {
FetchAllAccounts,
FetchAllAccountsUseCase
} from '@/core/application/use-cases/accounts/fetch-all-account-use-case'
import {
CreateAccount,
CreateAccountUseCase
} from '@/core/application/use-cases/accounts/create-account-use-case'
import {
FetchAccountById,
FetchAccountByIdUseCase
} from '@/core/application/use-cases/accounts/fetch-account-by-id-use-case'
import {
UpdateAccount,
UpdateAccountUseCase
} from '@/core/application/use-cases/accounts/update-account-use-case'
import {
DeleteAccount,
DeleteAccountUseCase
} from '@/core/application/use-cases/accounts/delete-account-use-case'

export const AccountUseCaseModule = new ContainerModule(
(container: Container) => {
container.bind<FetchAllAccounts>(FetchAllAccountsUseCase).toSelf()
container.bind<CreateAccount>(CreateAccountUseCase).toSelf()
container.bind<FetchAccountById>(FetchAccountByIdUseCase).toSelf()
container.bind<UpdateAccount>(UpdateAccountUseCase).toSelf()
container.bind<DeleteAccount>(DeleteAccountUseCase).toSelf()
}
)
Loading

0 comments on commit 1fd4103

Please sign in to comment.