From 9c49adbaf18730c9100587e98f6db156c6659c41 Mon Sep 17 00:00:00 2001 From: Mohamad Fadhil Date: Thu, 10 Jul 2025 05:48:23 +0800 Subject: [PATCH] update question --- README.md | 32 ++++++++++++++++++++++++++++++++ fastapi-python/README.md | 4 ++-- fastapi-python/main.py | 10 ++++++---- go-stdlib/README.md | 7 +++++++ go-stdlib/main.go | 2 ++ hono/README.md | 8 ++++---- hono/src/index.ts | 3 ++- 7 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 README.md create mode 100644 go-stdlib/README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..10b1115 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Junior Backend Engineer Interview + +Imagine that you're building a fintech system. You're now building a small microservice that allow people to send money to each other. + +## Instructions + +1. Checkout into a new git branch with name like `YYYY-MM-DD-nickname` + +1. Navigate into any language directory you're comfortable with + +1. Implement the `POST /transfer` API endpoint that allows you to transfer money from one account to another. + + The account balance has to reflect the new balance after transfer for both accounts and the transaction has to be recorded. + + Example request look like below: + + ``` + curl -X POST http://localhost:3000/transfer \ + -H "Content-Type: application/json" \ + -d '{"amount": 100, "sender": "1", "receiver": "2"}' + ``` + +1. Implement a new API endpoint `GET /all-transactions` that shows all transactions in the system. + +1. Commit & push your changes to the git upstream. + +Bonus points: + +- Implement the requests validation +- Handle errors appropriately + +Good luck! diff --git a/fastapi-python/README.md b/fastapi-python/README.md index ebc630e..3a6c4c0 100644 --- a/fastapi-python/README.md +++ b/fastapi-python/README.md @@ -1,6 +1,6 @@ # Get started ```sh - -fastapi dev main.py +uv venv +uv run fastapi dev main.py ``` diff --git a/fastapi-python/main.py b/fastapi-python/main.py index d4648d3..ac14cd2 100644 --- a/fastapi-python/main.py +++ b/fastapi-python/main.py @@ -5,16 +5,18 @@ from pydantic import BaseModel class Transfer(BaseModel): amount: int - sender: int - receiver: int + sender: str + receiver: str app = FastAPI() accounts = { - '1': {'amount': 1000}, - '2': {'amount': 1000}, + '1': 1000, + '2': 1000, } +transactions: list[Transfer] = [] + @app.post("/transfer") def transfer(transfer: Transfer): amount = transfer.amount diff --git a/go-stdlib/README.md b/go-stdlib/README.md new file mode 100644 index 0000000..b51dcfa --- /dev/null +++ b/go-stdlib/README.md @@ -0,0 +1,7 @@ +# Instructions + +Start the API server using the following command: + +```sh +go run . +``` \ No newline at end of file diff --git a/go-stdlib/main.go b/go-stdlib/main.go index a413229..7c5952f 100644 --- a/go-stdlib/main.go +++ b/go-stdlib/main.go @@ -18,6 +18,8 @@ var accounts = map[int]int{ 2: 1000, } +var transactions = []Transfer{} + func main() { fmt.Println("Starting server on port 8080") http.HandleFunc("/transfer", transfer) diff --git a/hono/README.md b/hono/README.md index e12b31d..88b921f 100644 --- a/hono/README.md +++ b/hono/README.md @@ -1,8 +1,8 @@ +# Instructions + +Start the API server using the following command: + ``` npm install npm run dev ``` - -``` -open http://localhost:3000 -``` diff --git a/hono/src/index.ts b/hono/src/index.ts index c03f3dc..0ed3340 100644 --- a/hono/src/index.ts +++ b/hono/src/index.ts @@ -8,6 +8,8 @@ const accounts = { '2': {amount: 1000}, } +const transactions = [] + app.post('/transfer', async (c) => { const body = await c.req.json(); const { amount, sender, receiver } = body; @@ -23,7 +25,6 @@ app.post('/transfer', async (c) => { } console.log('transfer', transfe); - return c.json(transfer) })