CakeVille

Project Overview:
Repo: https://github.com/Rafli-Dewanto/lsp-programmer

this is the backend of the cakevillle project, for the frontend, please visit here

This is a Cake Store API built with Go using Fiber as the web framework and GORM as the ORM. The application provides functionality for managing cakes, customers, orders, and payments. It uses MySQL (via Docker) as the primary database and SQLite for unit testing.

Features

  • User authentication and authorization (JWT)
  • Customer registration and profile management
  • Create, read, update, and delete cakes
  • Order management system
  • Payment integration with Midtrans
  • Uses MySQL as the database (via Docker container)
  • Unit testing

Prerequisites

Setup & Installation

1. Clone the repository

git clone https://github.com/Rafli-Dewanto/lsp-programmer.git cakestore-be
cd cakestore-be

2. Create a .env file

touch .env.example .env

3. Run with Docker

docker compose up -d --build

4. Install dependencies

go mod tidy

5. Start the application

go run main.go

The API will be available at http://localhost:8080.

API Endpoints

Public Routes

MethodEndpointDescription
POST/registerRegister a new customer
POST/loginCustomer login
POST/payment/notificationMidtrans payment webhook

Protected Routes (Requires JWT Authentication)

Customer Routes

MethodEndpointDescription
GET/customers/meGet current customer profile
PUT/customers/:idUpdate customer profile

Cake Routes

MethodEndpointDescription
GET/cakesGet all cakes
GET/cakes/:idGet a specific cake
POST/cakesCreate a new cake
PUT/cakes/:idUpdate cake details
DELETE/cakes/:idDelete a cake

Order Routes

MethodEndpointDescription
POST/ordersCreate a new order
GET/ordersGet all customer orders
GET/orders/:idGet specific order by ID

Example Requests

Register Customer

curl --location 'http://127.0.0.1:8080/register' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "name",
    "email": "[email protected]",
    "password": "password123@Q",
    "address": "sudirman"
}'

Create Cake (Protected Route)

curl --location 'http://127.0.0.1:8080/cakes' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21lcl9pZCI6MSwiZW1haWwiOiJ0ZXN0NEBlbWFpbC5jb20iLCJleHAiOjE3NDQ4MTI1Nzd9.c5nWXiG0yf97LnLDnZjP_N7YJ8hQmxHII-RAgetmI3Q' \
--data '{
    "title": "Lemon cheesecake",
    "description": "A cheesecake made of lemon",
    "rating": 7,
    "image": "https://img.taste.com.au/ynYrqkOs/w720-h480-cfill-q8"
}'

Running Tests

Unit tests.

go test ./...

To run tests with detailed output:

go test -v ./...

License

This project is licensed under the MIT License.