This repository was archived by the owner on Feb 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add list accounts with pagination #24
Open
Faell4328
wants to merge
3
commits into
mitgdev:main
Choose a base branch
from
Faell4328:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
apps/api/src/application/usecases/account/listAccounts/contract.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type z from "zod"; | ||
| import { ListAccountSchema } from "@/shared/schemas/ListAccounts"; | ||
| import { createPaginateSchema, InputPageSchema } from "@/shared/utils/paginate"; | ||
|
|
||
| export const ListAccountsContractSchema = { | ||
| input: InputPageSchema, | ||
| output: createPaginateSchema(ListAccountSchema), | ||
| }; | ||
|
|
||
| export type ListAccountsContractInput = z.infer< | ||
| typeof ListAccountsContractSchema.input | ||
| >; | ||
|
|
||
| export type ListAccountsContractOutput = z.infer< | ||
| typeof ListAccountsContractSchema.output | ||
| >; |
34 changes: 34 additions & 0 deletions
34
apps/api/src/application/usecases/account/listAccounts/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { inject, injectable } from "tsyringe"; | ||
| import type { AccountsService } from "@/application/services"; | ||
| import type { Pagination } from "@/domain/modules"; | ||
| import { TOKENS } from "@/infra/di/tokens"; | ||
| import type { UseCase } from "@/shared/interfaces/usecase"; | ||
| import type { | ||
| ListAccountsContractInput, | ||
| ListAccountsContractOutput, | ||
| } from "./contract"; | ||
|
|
||
| @injectable() | ||
| export class ListAccountsUseCase | ||
| implements UseCase<ListAccountsContractInput, ListAccountsContractOutput> | ||
| { | ||
| constructor( | ||
| @inject(TOKENS.AccountsService) | ||
| private readonly accountsService: AccountsService, | ||
| @inject(TOKENS.Pagination) private readonly pagination: Pagination, | ||
| ) {} | ||
|
|
||
| async execute( | ||
| input: ListAccountsContractInput, | ||
| ): Promise<ListAccountsContractOutput> { | ||
| const { storeHistory, total } = await this.accountsService.listAccounts({ | ||
| pagination: input, | ||
| }); | ||
|
|
||
| return this.pagination.paginate(storeHistory, { | ||
| page: input.page ?? 1, | ||
| size: input.size ?? 10, | ||
| total, | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,6 +210,27 @@ export class AccountRepository { | |
| }; | ||
| } | ||
|
|
||
| async listAccounts(opts?: { pagination: PaginationInput }) { | ||
| const page = opts?.pagination.page ?? 1; | ||
| const size = opts?.pagination.size ?? 10; | ||
|
|
||
| const [storeHistory, total] = await Promise.all([ | ||
| this.prisma.accounts.findMany({ | ||
| orderBy: { | ||
| name: "desc", | ||
| }, | ||
| skip: (page - 1) * size, | ||
| take: size, | ||
| }), | ||
| this.prisma.accounts.count(), | ||
| ]); | ||
|
|
||
| return { | ||
| storeHistory, | ||
|
||
| total, | ||
| }; | ||
| } | ||
|
|
||
| async details(email: string) { | ||
| return this.prisma.accounts.findFirst({ | ||
| where: { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { base } from "@/infra/rpc/base"; | ||
| import { listAccountsRouter } from "./list"; | ||
|
|
||
| export const adminAccountsRouter = base.prefix("/accounts").router({ | ||
| list: listAccountsRouter, | ||
| }); |
22 changes: 22 additions & 0 deletions
22
apps/api/src/presentation/v1/routes/admin/accounts/list/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { ListAccountsContractSchema } from "@/application/usecases/account/listAccounts/contract"; | ||
| import { isPermissionedProcedure } from "@/presentation/procedures/isPermissioned"; | ||
|
|
||
| export const listAccountsRouter = isPermissionedProcedure | ||
| .meta({ | ||
| permission: { | ||
| type: "GAME_MASTER", | ||
| }, | ||
| }) | ||
| .route({ | ||
| method: "GET", | ||
| path: "/list", | ||
| summary: "List Accounts", | ||
| successStatus: 200, | ||
| description: | ||
| "Retrieves a list of accounts registered on the server. Only GAME_MASTER and ADMIN users are allowed to perform this action", | ||
| }) | ||
| .input(ListAccountsContractSchema.input) | ||
| .output(ListAccountsContractSchema.output) | ||
| .handler(async ({ context, input }) => { | ||
| return await context.usecases.account.listAccounts.execute(input); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { base } from "@/infra/rpc/base"; | ||
| import { adminAccountsRouter } from "./accounts"; | ||
|
|
||
| export const adminRouter = base.prefix("/admin").tag("Admin").router({ | ||
| accounts: adminAccountsRouter, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import z from "zod"; | ||
|
|
||
| export const ListAccountSchema = z.object({ | ||
| id: z.number(), | ||
| name: z.string().nullable(), | ||
| email: z.email(), | ||
| type: z.number(), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| VITE_SHOW_DEVTOOLS=true | ||
|
|
||
| # ==== RPC ==== # | ||
| VITE_MIFORGE_RPC_URL="http://localhost:4000" | ||
| VITE_MIFORGE_RPC_PATH="/v1/rpc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,20 +1,33 @@ | ||||||
| import type { LinkProps } from "@tanstack/react-router"; | ||||||
| import { MenuBox } from "@/components/Box/Menu"; | ||||||
| import { MenuItem } from "./Item"; | ||||||
|
|
||||||
| export const Menu = () => { | ||||||
| export const Icons = { | ||||||
| management: "/assets/icons/32/loremaster_doll.gif", | ||||||
| news: "/assets/icons/32/news-menu.gif", | ||||||
| sphere: "/assets/icons/32/armillary_sphere.gif", | ||||||
| munster: "/assets/icons/32/baby_munster.gif", | ||||||
| }; | ||||||
|
|
||||||
| interface MenuProps { | ||||||
| items: Array<{ | ||||||
| label: string; | ||||||
| icon: keyof typeof Icons; | ||||||
| menus: Array<{ | ||||||
| label: string; | ||||||
| to: LinkProps["to"]; | ||||||
| hot?: boolean; | ||||||
| }>; | ||||||
| }>; | ||||||
| } | ||||||
|
|
||||||
| export const Menu = ({ items }: MenuProps) => { | ||||||
| return ( | ||||||
| <div className="flex"> | ||||||
| <MenuBox> | ||||||
| <MenuItem | ||||||
| label="News" | ||||||
| icon="news" | ||||||
| menus={[{ label: "Latest News", to: "/terms" }]} | ||||||
| /> | ||||||
| <MenuItem | ||||||
| label="Sphere" | ||||||
| icon="sphere" | ||||||
| menus={[{ label: "Updates", to: "/", hot: true }]} | ||||||
| /> | ||||||
| {items.map((item) => ( | ||||||
| <MenuItem label={item.label} icon={item.icon} menus={item.menus} /> | ||||||
|
Check warning on line 29 in apps/web/src/components/Menu/index.tsx
|
||||||
|
||||||
| <MenuItem label={item.label} icon={item.icon} menus={item.menus} /> | |
| <MenuItem key={item.label} label={item.label} icon={item.icon} menus={item.menus} /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name
storeHistoryis misleading and inconsistent with the function's purpose. This method lists accounts, not store history. Rename toaccountsfor clarity.