Added @GetMapping, prepped for new category/balance api
Build and Deploy Web App / build-and-deploy (push) Successful in 47s Details
Build and Deploy API / build-and-deploy (push) Successful in 1m48s Details

This commit is contained in:
Andrew Lalis 2026-02-12 12:21:56 -05:00
parent 711e420c61
commit 6d1af2f46d
2 changed files with 14 additions and 5 deletions

View File

@ -1,11 +1,11 @@
module data_api; module data_api;
import handy_http_primitives; import handy_http_primitives;
import handy_http_handlers.path_handler : PathMapping; import handy_http_handlers.path_handler : GetMapping;
import handy_http_data; import handy_http_data;
import util.money; import util.money;
@PathMapping(HttpMethod.GET, "/api/currencies") @GetMapping("/api/currencies")
void handleGetCurrencies(ref ServerHttpRequest request, ref ServerHttpResponse response) { void handleGetCurrencies(ref ServerHttpRequest request, ref ServerHttpResponse response) {
writeJsonBody(response, ALL_CURRENCIES); writeJsonBody(response, ALL_CURRENCIES);
} }

View File

@ -135,24 +135,33 @@ private ulong getVendorId(in ServerHttpRequest request) {
// Categories API // Categories API
@PathMapping(HttpMethod.GET, PROFILE_PATH ~ "/categories") @GetMapping(PROFILE_PATH ~ "/categories")
void handleGetCategories(ref ServerHttpRequest request, ref ServerHttpResponse response) { void handleGetCategories(ref ServerHttpRequest request, ref ServerHttpResponse response) {
TransactionCategoryTree[] categories = getCategories(getProfileDataSource(request)); TransactionCategoryTree[] categories = getCategories(getProfileDataSource(request));
writeJsonBody(response, categories); writeJsonBody(response, categories);
} }
@PathMapping(HttpMethod.GET, PROFILE_PATH ~ "/categories/:categoryId:ulong") @GetMapping(PROFILE_PATH ~ "/categories/:categoryId:ulong")
void handleGetCategory(ref ServerHttpRequest request, ref ServerHttpResponse response) { void handleGetCategory(ref ServerHttpRequest request, ref ServerHttpResponse response) {
auto category = getCategory(getProfileDataSource(request), getCategoryId(request)); auto category = getCategory(getProfileDataSource(request), getCategoryId(request));
writeJsonBody(response, category); writeJsonBody(response, category);
} }
@PathMapping(HttpMethod.GET, PROFILE_PATH ~ "/categories/:categoryId:ulong/children") @GetMapping(PROFILE_PATH ~ "/categories/:categoryId:ulong/children")
void handleGetChildCategories(ref ServerHttpRequest request, ref ServerHttpResponse response) { void handleGetChildCategories(ref ServerHttpRequest request, ref ServerHttpResponse response) {
auto children = getChildCategories(getProfileDataSource(request), getCategoryId(request)); auto children = getChildCategories(getProfileDataSource(request), getCategoryId(request));
writeJsonBody(response, children); writeJsonBody(response, children);
} }
@GetMapping(PROFILE_PATH ~ "/categories/:categoryId:ulong/balances")
void handleGetCategoryBalances(ref ServerHttpRequest request, ref ServerHttpResponse response) {
response.status = HttpStatus.NOT_IMPLEMENTED;
// TODO: Add an API endpoint to provide a "balance" for the category.
// This would be the sum of credits and debits for all transactions set
// to this category or any child of it, over a specified interval, or for
// some default interval if none is provided.
}
struct CategoryPayload { struct CategoryPayload {
string name; string name;
string description; string description;