From 13aadc2358f623335c723fbf68b29641ef2fd054 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 27 Jun 2026 21:59:05 -0400 Subject: [PATCH] Updated API client code to match new API endpoints. --- web-app/src/api/account.ts | 7 + web-app/src/api/transaction.ts | 152 +++++++++++++++--- web-app/src/components/LineItemCard.vue | 4 +- web-app/src/components/LineItemsEditor.vue | 4 +- .../src/pages/forms/EditTransactionPage.vue | 4 +- 5 files changed, 143 insertions(+), 28 deletions(-) diff --git a/web-app/src/api/account.ts b/web-app/src/api/account.ts index fcc57c4..2ba5c7a 100644 --- a/web-app/src/api/account.ts +++ b/web-app/src/api/account.ts @@ -59,6 +59,13 @@ export interface Account { currentBalance: number | null } +export interface SimpleAccountResponse { + id: number + name: string + type: string + numberSuffix: string +} + export interface AccountCreationPayload { type: string numberSuffix: string diff --git a/web-app/src/api/transaction.ts b/web-app/src/api/transaction.ts index ff74b2f..072843f 100644 --- a/web-app/src/api/transaction.ts +++ b/web-app/src/api/transaction.ts @@ -1,8 +1,28 @@ +import type { SimpleAccountResponse } from './account' import type { Attachment } from './attachment' import { ApiClient } from './base' import type { Currency } from './data' import { type Page, type PageRequest } from './pagination' +export interface SimpleVendorResponse { + id: number + name: string +} + +export interface SimpleCategoryResponse { + id: number + name: string + color: string +} + +export interface TransactionLineItemResponse { + idx: number + valuePerItem: number + quantity: number + description: string + category: TransactionCategory | null +} + export interface TransactionVendor { id: number name: string @@ -47,10 +67,10 @@ export interface TransactionsListItem { currency: Currency description: string internalTransfer: boolean - vendor: TransactionsListItemVendor | null - category: TransactionsListItemCategory | null - creditedAccount: TransactionsListItemAccount | null - debitedAccount: TransactionsListItemAccount | null + vendor: SimpleVendorResponse | null + category: SimpleCategoryResponse | null + creditedAccount: SimpleAccountResponse | null + debitedAccount: SimpleAccountResponse | null tags: string[] } @@ -82,28 +102,13 @@ export interface TransactionDetail { internalTransfer: boolean vendor: TransactionVendor | null category: TransactionCategory | null - creditedAccount: TransactionDetailAccount | null - debitedAccount: TransactionDetailAccount | null + creditedAccount: SimpleAccountResponse | null + debitedAccount: SimpleAccountResponse | null tags: string[] - lineItems: TransactionDetailLineItem[] + lineItems: TransactionLineItemResponse[] attachments: Attachment[] } -export interface TransactionDetailAccount { - id: number - name: string - type: string - numberSuffix: string -} - -export interface TransactionDetailLineItem { - idx: number - valuePerItem: number - quantity: number - description: string - category: TransactionCategory | null -} - export interface AddTransactionPayload { timestamp: string amount: number @@ -144,6 +149,56 @@ export interface AggregateTransactionData { currencies: AggregateTransactionCurrencyData[] } +export interface TransactionDraftListItem { + id: number + addedAt: string + templateName: string | null + timestamp: string | null + amount: number | null + currency: Currency | null + description: string | null + internalTransfer: boolean | null + vendor: SimpleVendorResponse | null + category: SimpleCategoryResponse | null + creditedAccount: SimpleAccountResponse | null + debitedAccount: SimpleAccountResponse | null + tags: string[] +} + +export interface TransactionDraftResponse { + id: number + addedAt: string + templateName: string | null + timestamp: string | null + amount: number | null + currency: Currency | null + description: string | null + internalTransfer: boolean | null + vendor: SimpleVendorResponse | null + category: SimpleCategoryResponse | null + creditedAccount: SimpleAccountResponse | null + debitedAccount: SimpleAccountResponse | null + tags: string[] + lineItems: TransactionLineItemResponse[] + attachments: Attachment[] +} + +export interface TransactionDraftPayload { + templateName: string | null + timestamp: string | null + amount: number | null + currencyCode: string | null + description: string | null + internalTransfer: boolean | null + vendorId: number | null + categoryId: number | null + creditedAccountId: number | null + debitedAccountId: number | null + tags: string[] + lineItems: AddTransactionPayloadLineItem[] + attachmentIdsToRemove: number[] +} + export class TransactionApiClient extends ApiClient { readonly path: string @@ -277,4 +332,57 @@ export class TransactionApiClient extends ApiClient { getAllTags(): Promise { return super.getJson(this.path + '/transaction-tags') } + + // Drafts: + + getDrafts( + paginationOptions: PageRequest | undefined = undefined, + ): Promise> { + return super.getJsonPage(this.path + '/transaction-drafts', paginationOptions) + } + + getTemplateDrafts( + paginationOptions: PageRequest | undefined = undefined, + ): Promise> { + const params = new URLSearchParams() + params.append('template', 'true') + if (paginationOptions !== undefined) { + params.append('page', paginationOptions.page + '') + params.append('size', paginationOptions.size + '') + for (const sort of paginationOptions.sorts) { + params.append('sort', sort.attribute + ',' + sort.dir) + } + } + return super.getJson(this.path + '/transaction-drafts?' + params.toString()) + } + + getDraft(id: number): Promise { + return super.getJson(this.path + '/transaction-drafts/' + id) + } + + addDraft(data: TransactionDraftPayload, files: File[] = []): Promise { + const formData = new FormData() + formData.append('payload', JSON.stringify(data)) + for (const file of files) { + formData.append('file', file) + } + return super.postFormData(this.path + '/transaction-drafts', formData) + } + + updateDraft( + id: number, + data: TransactionDraftPayload, + files: File[] = [], + ): Promise { + const formData = new FormData() + formData.append('payload', JSON.stringify(data)) + for (const file of files) { + formData.append('file', file) + } + return super.putFormData(this.path + '/transaction-drafts/' + id, formData) + } + + deleteDraft(id: number): Promise { + return super.delete(this.path + '/transaction-drafts/' + id) + } } diff --git a/web-app/src/components/LineItemCard.vue b/web-app/src/components/LineItemCard.vue index 423f326..e700ce9 100644 --- a/web-app/src/components/LineItemCard.vue +++ b/web-app/src/components/LineItemCard.vue @@ -1,10 +1,10 @@