Skip to content

Commit

Permalink
feat: make route to add money to wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
patricks-js committed Nov 22, 2024
1 parent 4e35a15 commit 8189f90
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/infra/factories/make-add-money-to-wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AddMoneyToWalletUseCase } from "@/application/use-cases/add-money-to-wallet";
import { DrizzleWalletRepository } from "../repositories/drizzle/drizzle-wallet-repository";

export function makeAddMoneyToWalletUseCase(): AddMoneyToWalletUseCase {
const walletRepository = new DrizzleWalletRepository();
return new AddMoneyToWalletUseCase(walletRepository);
}
28 changes: 28 additions & 0 deletions src/presentation/controllers/add-money-to-wallet.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { makeAddMoneyToWalletUseCase } from "@/infra/factories/make-add-money-to-wallet";
import type { FastifyReply, FastifyRequest } from "fastify";
import { z } from "zod";

export async function addMoneyToWalletController(
request: FastifyRequest,
reply: FastifyReply,
) {
const bodySchema = z.object({
amount: z.coerce.number().positive(),
});

const paramsSchema = z.object({
walletId: z.string(),
});

const body = bodySchema.parse(request.body);
const params = paramsSchema.parse(request.params);

const addMoneyToWallet = makeAddMoneyToWalletUseCase();

await addMoneyToWallet.execute({
amount: body.amount,
walletId: params.walletId,
});

return reply.status(204).send();
}
3 changes: 2 additions & 1 deletion src/presentation/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import type { FastifyInstance } from "fastify";

import { authenticateController } from "@/presentation/controllers/authenticate.controller";
import { registerUserController } from "@/presentation/controllers/register-user.controller";
import { addMoneyToWalletController } from "../controllers/add-money-to-wallet.controller";

export async function routes(app: FastifyInstance) {
app.post("/users", registerUserController);
app.post("/sessions", authenticateController);
app.post("/wallets/:walletId/deposits", addMoneyToWalletController);
app.post("/wallets/:walletId/transfers", async () => {});
app.post("/wallets/:walletId/deposits", async () => {});
app.get("/wallets/:walletId/transfers", async () => {});
}

0 comments on commit 8189f90

Please sign in to comment.