{"openapi":"3.0.0","info":{"title":"Accounting Service API (Sprint 1)","version":"1.0.0"},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Enter the Access Token obtained from Login (used to extract farmer_id)"}},"schemas":{"Category":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string","example":"Food"},"account_type":{"type":"string","enum":["HOUSEHOLD","AGRICULTURAL"]},"action_type":{"type":"string","enum":["INCOME","EXPENSE"]}}},"Unit":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string","example":"Kilogram"}}},"TransactionRequest":{"type":"object","required":["action_type","transactions"],"properties":{"action_type":{"type":"string","enum":["INCOME","EXPENSE"],"example":"EXPENSE"},"transactions":{"type":"array","description":"รายการธุรกรรมที่จะบันทึก (Bulk Insert)","items":{"type":"object","required":["name","quantity","price","category_id","unit_id","transaction_date"],"properties":{"name":{"type":"string","description":"ชื่อรายการ (ตรงกับ db)","example":"ข้าวไก่ทอด"},"quantity":{"type":"number","format":"float","description":"จำนวน (ตรงกับ db)","example":1.0},"price":{"type":"number","format":"float","description":"ราคา/ยอดเงิน (ตรงกับ db)","example":60.0},"category_id":{"type":"integer","description":"รหัสหมวดหมู่ (ตรงกับ db)","example":12},"unit_id":{"type":"integer","description":"รหัสหน่วย (ตรงกับ db)","example":3},"transaction_date":{"type":"string","format":"date-time","description":"วันที่ทำรายการ (ตรงกับ db)","example":"2026-03-23T11:30:00Z"}}}}}},"TransactionResponse":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"action_type":{"type":"string"},"quantity":{"type":"number","format":"float"},"price":{"type":"number","format":"float"},"category_id":{"type":"integer"},"unit_id":{"type":"integer"},"transaction_date":{"type":"string","format":"date-time"}}}}},"security":[{"bearerAuth":[]}],"paths":{"/accounts/overview":{"get":{"tags":["Dashboard"],"parameters":[{"in":"query","name":"start_date","schema":{"type":"string","format":"date"},"example":"2026-01-01"},{"in":"query","name":"end_date","schema":{"type":"string","format":"date"},"example":"2026-01-31"}],"responses":{"200":{"description":"Success","content":{"application/json":{"example":{"total_balance_all_accounts":4410.0,"accounts":[{"account_id":1,"account_type":"HOUSEHOLD","balance":4410.0,"summary":{"total_income":5000.0,"total_expense":590.0,"expense_chart":[{"category_name":"Food","amount":60.0,"percentage":10.16},{"category_name":"Shopping","amount":350.0,"percentage":59.32}]}},{"account_id":2,"account_type":"AGRICULTURAL","balance":0.0,"summary":{"total_income":0.0,"total_expense":0.0,"expense_chart":[]}}]}}}}}}},"/accounts/{account_id}/overview":{"get":{"tags":["Dashboard"],"parameters":[{"in":"path","name":"account_id","required":true,"schema":{"type":"integer"}},{"in":"query","name":"start_date","schema":{"type":"string","format":"date"}},{"in":"query","name":"end_date","schema":{"type":"string","format":"date"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"example":{"account_id":1,"balance":4410.0,"summary":{"total_income":5000.0,"total_expense":590.0},"calendar_daily_stats":[{"date":"2026-01-14","income":0.0,"expense":60.0},{"date":"2026-01-13","income":0.0,"expense":500.0}]}}}}}}},"/categories":{"get":{"tags":["Master Data"],"parameters":[{"in":"query","name":"account_type","schema":{"type":"string","enum":["HOUSEHOLD","AGRICULTURAL"]}},{"in":"query","name":"action_type","schema":{"type":"string","enum":["INCOME","EXPENSE"]}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Category"}}}}}}}},"/units":{"get":{"tags":["Master Data"],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Unit"}}}}}}}},"/accounts/{account_id}/transactions":{"post":{"tags":["Transaction"],"parameters":[{"in":"path","name":"account_id","required":true,"schema":{"type":"integer"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionRequest"}}}},"responses":{"201":{"description":"Created successfully","content":{"application/json":{"example":{"message":"Created successfully","id":101}}}}}},"get":{"tags":["Transaction"],"parameters":[{"in":"path","name":"account_id","required":true,"schema":{"type":"integer"}},{"in":"query","name":"action_type","schema":{"type":"string","enum":["INCOME","EXPENSE"]}},{"in":"query","name":"mode","description":"Pagination mode (always use 'cursor' for Mobile)","schema":{"type":"string","example":"cursor"}},{"in":"query","name":"first","description":"Number of items to retrieve (limit)","schema":{"type":"integer","example":20}},{"in":"query","name":"after","description":"Cursor (latest id). Leave empty for the first load.","schema":{"type":"string","example":"185"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"example":{"transactions":[{"id":184,"name":"ข้าวไก่ทอด","category_name":"Food","price":60.0,"action_type":"EXPENSE","transaction_date":"2026-03-23T11:30:00Z"},{"id":183,"name":"น้ำมันรถ","category_name":"Travel","price":500.0,"action_type":"EXPENSE","transaction_date":"2026-03-22T08:30:00Z"}],"page_info":{"has_next_page":true,"start_cursor":"11","end_cursor":"19"}}}}}}}},"/accounts/{account_id}/transactions/{transaction_id}":{"get":{"tags":["Transaction"],"parameters":[{"in":"path","name":"account_id","required":true,"schema":{"type":"integer"}},{"in":"path","name":"transaction_id","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransactionResponse"}}}}}}}},"servers":[{"description":"SwaggerHub API Auto Mocking","url":"https://virtserver.swaggerhub.com/myself-757/test2/1.0.0"}]}