Skip to content

Latest commit

 

History

History
155 lines (109 loc) · 2.9 KB

Ledger-API-documentation.md

File metadata and controls

155 lines (109 loc) · 2.9 KB

Ledger API Documentation

API Endpoints

1. Upload Ledger Information

Endpoint: /api/ledgers/upload-ledger
Method: POST
Description: Uploads a ledger entry along with an associated invoice file.

Request

Headers:

  • Content-Type: multipart/form-data

Body:

  • file: Multipart file containing the invoice.
  • ledger: JSON object containing the ledger details.

Ledger DTO JSON Structure:

{
  "item": "Item description",
  "amount": 100.00,
  "expenseDate": "2023-07-31",
  "notes": "Additional notes"
}

Response

  • true if the upload was successful.
  • false if there was an error during the upload process.

2. Fetch All Ledger Entries

Endpoint: /api/ledgers/get-all
Method: POST
Description: Retrieves a list of all ledger entries.

Request

No parameters or body required.

Response

  • Returns a JSON array of all ledger entries.

Example Response:

[
  {
    "id": 1,
    "item": "Office Supplies",
    "amount": 150.75,
    "expenseDate": "2024-07-31",
    "invoiceUrl": "random_uuid_invoice.jpg",
    "notes": "Purchased new office supplies"
  },
  ...
]

3. Get Invoice by File Name

Endpoint: /api/ledgers/invoice/{fileName}
Method: GET
Description: Retrieves the invoice file by its name.

Request

Path Parameter:

  • fileName: The name of the file to retrieve.

Example Request using curl:

curl -X GET "https://api.utmcaps.com/api/ledgers/invoice/random_uuid_invoice.jpg"

Response

  • Returns the invoice file if it exists.
  • 404 status code if the file does not exist or cannot be read.

4. Delete Ledger by ID

  • Endpoint: /api/ledgers/del-ledger/{ledgerID}
  • Method: GET
  • Description: Deletes a ledger entry by its ID.

Request

Path Parameter:

  • ledgerID: The ID of the ledger entry to delete.

Example Request using curl:

curl -X GET "https://api.utmcaps.com/api/ledgers/del-ledger/1"

Response

No content even if the deletion was successful.


Data Models

LedgerDTO

The LedgerDTO is a Data Transfer Object used for transferring ledger information.

public class LedgerDTO {
    private String item;
    private BigDecimal amount;
    private LocalDate expenseDate;
    private String notes;
}

Ledger Entity

The Ledger entity represents the ledger table in the database.

@Entity
@Table(name = "ledger")
public class Ledger {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(nullable = false, name="item")
    private String item;

    @Column(nullable = false, name = "amount")
    private BigDecimal amount;

    @Column(nullable = false, name = "expense_date")
    private LocalDate expenseDate;

    @Column(name = "invoice_url")
    private String invoiceUrl;

    @Column(name = "notes")
    private String notes;
}