Penghitung Sembako API Documentation

Base URL:

https://sembako.sendiko.my.id/

Get One User

GET /user/:id

Retrieves a registered user in the system.

Path Parameters

  • id (string): The unique identifier of the user. Example: 3

Headers

{
  "Content-Type": "application/json"
}

Response (Success)

{
    "status": 200,
    "user": {
        "id": 3,
        "username": "Rizky Sendiko",
        "email": "example@gmail.com",
        "profileUrl": "https://example.com/profile.jpg",
        "createdAt": "2025-05-27T17:24:39.000Z",
        "updatedAt": "2025-05-27T17:24:39.000Z"
    }
}

Create User

POST /users

Creates a new user with the provided details.

Headers

{
  "Content-Type": "application/json"
}

Request Body

{
    "username": "Sendiko",
    "email": "awokwokwok5@gmail.com",
    "profileUrl": "https://example.com/profile.jpg"
}

Response (Success)

{
    "status": 201,
    "message": "User created successfully",
    "user": {
        "id": 8,
        "username": "Sendiko",
        "email": "awokwokwok5@gmail.com",
        "profileUrl": "https://example.com/profile.jpg",
        "updatedAt": "2025-06-08T15:37:54.199Z",
        "createdAt": "2025-06-08T15:37:54.199Z"
    }
}

Grocery Endpoints

Get All Groceries for User

GET /grocery/:userId

Retrieves a list of all groceries associated with a specific user ID.

Path Parameters

  • userId (string): The unique identifier of the user. Example: 3

Headers

{
  "Content-Type": "application/json"
}

Response (Success)

{
    "status": 200,
    "groceries": [
        {
            "id": 17,
            "userId": 3,
            "name": "Beras Raja Platinum",
            "unit": "Kg",
            "price": 19000,
            "imageUrl": "http://sembako.sendiko.my.id/public/groceries/1749017019124-beras raja platinum",
            "createdAt": "2025-05-30T08:30:33.000Z",
            "updatedAt": "2025-06-04T06:03:39.000Z"
        },
        {
            "id": 18,
            "userId": 3,
            "name": "Minyak Bimoli",
            "unit": "Lt",
            "price": 26000,
            "imageUrl": "http://sembako.sendiko.my.id/public/groceries/1748593904619-minyak bimoli",
            "createdAt": "2025-05-30T08:31:44.000Z",
            "updatedAt": "2025-05-30T08:37:05.000Z"
        }
    ]
}

Create Grocery

POST /grocery

Adds a new grocery item to the system.

Request Body (Form Data)

  • userId (string, required): The ID of the user creating the grocery.
  • name (string, required): The name of the grocery item.
  • unit (string, required): The unit of measurement (e.g., "Kg", "Lt").
  • price (number, required): The price of the grocery item.
  • image (file, optional): An image file for the grocery item.

Response (Success)

{
    "status": 201,
    "message": "Grocery created successfully",
    "grocery": {
        "id": 24,
        "userId": "4",
        "name": "Telur Anomali",
        "unit": "Kg",
        "price": "1000000",
        "imageUrl": "http://sembako.sendiko.my.id/public/groceries/1749397455180-telur.jpg",
        "updatedAt": "2025-06-08T15:44:15.201Z",
        "createdAt": "2025-06-08T15:44:15.201Z"
    }
}

Update Grocery

PUT /grocery/:id

Updates an existing grocery item by its unique ID. All fields are optional for partial updates.

Path Parameters

  • id (string): The unique identifier of the grocery item. Example: 24

Request Body (Form Data - Optional Fields)

  • userId (string, optional): The ID of the user associated with the grocery.
  • name (string, optional): The updated name of the grocery item.
  • unit (string, optional): The updated unit of measurement.
  • price (number, optional): The updated price of the grocery item.
  • image (file, optional): A new image file for the grocery item.

Response (Success)

{
    "status": 200,
    "message": "Grocery updated successfully",
    "grocery": {
        "id": 24,
        "userId": 4,
        "name": "Telur Anomali 2",
        "unit": "Kg",
        "price": 1000000,
        "imageUrl": "http://sembako.sendiko.my.id/public/groceries/1749397455180-telur.jpg",
        "createdAt": "2025-06-08T15:44:15.000Z",
        "updatedAt": "2025-06-08T15:46:23.436Z"
    }
}

Delete Grocery

DELETE /grocery/:id

Deletes a specific grocery item from the system by its unique ID.

Path Parameters

  • id (string): The unique identifier of the grocery item to delete. Example: 24

Headers

{
  "Content-Type": "application/json"
}

Response (Success)

{
    "status": 200,
    "message": "Grocery deleted successfully"
}

History Endpoints

Get All History for User

GET /history/:userId

Retrieves a list of all transaction history records for a specific user ID.

Path Parameters

  • userId (string): The unique identifier of the user. Example: 3

Headers

{
  "Content-Type": "application/json"
}

Response (Success)

{
    "status": 200,
    "history": [
        {
            "id": 6,
            "groceryId": 17,
            "userId": 3,
            "quantity": 15,
            "totalPrice": 285000,
            "createdAt": "2025-05-30T09:15:20.000Z",
            "updatedAt": "2025-05-30T09:15:20.000Z",
            "Grocery": {
                "id": 17,
                "userId": 3,
                "name": "Beras Raja Platinum",
                "unit": "Kg",
                "price": 19000,
                "imageUrl": "http://sembako.sendiko.my.id/public/groceries/1749017019124-beras raja platinum",
                "createdAt": "2025-05-30T08:30:33.000Z",
                "updatedAt": "2025-06-04T06:03:39.000Z"
            }
        },
        {
            "id": 7,
            "groceryId": 18,
            "userId": 3,
            "quantity": 3,
            "totalPrice": 78000,
            "createdAt": "2025-05-30T09:15:47.000Z",
            "updatedAt": "2025-05-30T09:15:47.000Z",
            "Grocery": {
                "id": 18,
                "userId": 3,
                "name": "Minyak Bimoli",
                "unit": "Lt",
                "price": 26000,
                "imageUrl": "http://sembako.sendiko.my.id/public/groceries/1748593904619-minyak bimoli",
                "createdAt": "2025-05-30T08:31:44.000Z",
                "updatedAt": "2025-05-30T08:37:05.000Z"
            }
        },
    ]
}

Create History

POST /history

Creates a new transaction history record.

Headers

{
  "Content-Type": "application/json"
}

Request Body

{
    "groceryId": 19,
    "userId": 3,
    "quantity": 4.5,
    "totalPrice": 126000
}

Response (Success)

{
    "status": 201,
    "message": "History created successfully",
    "history": {
        "id": 13,
        "groceryId": 19,
        "userId": 3,
        "quantity": 4.5,
        "totalPrice": 126000,
        "updatedAt": "2025-06-08T15:50:00.000Z",
        "createdAt": "2025-06-08T15:50:00.000Z"
    }
}

Statistics Endpoints

Get Statistics

GET /stats/:userId

Retrieves various statistics related to grocery items and user activity.

Path Parameters

  • userId (string): The unique identifier of the user for whom to retrieve statistics. Example: 3

Headers

{
  "Content-Type": "application/json"
}

Response (Success)

{
    "status": 200,
    "message": "Grocery count retrieved successfully",
    "statistics": {
        "groceryCount": 5,
        "totalSales": 1090000,
        "totalHistory": 6
    }
}