Skip to content

anuusz/fresoreapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fresore API

Deskripsi

API backend berbasis Django REST Framework untuk aplikasi e-commerce buah dan sayur, mendukung manajemen produk, pesanan, user, serta autentikasi token.


Struktur Proyek

  • core/: Konfigurasi utama Django (ASGI, WSGI, settings, URL routing)
  • products/: Modul produk (kategori, produk, review)
  • orders/: Modul pesanan (order, item order)
  • users/: Modul pengguna dan autentikasi
  • docs/: Dokumentasi dan diagram

Endpoint Utama

1. Products

  • GET /api/products/: Daftar produk (filter, search, order)
  • POST /api/products/: Tambah produk (admin)
  • GET /api/products/{id}/: Detail produk
  • PUT/PATCH/DELETE /api/products/{id}/: Update/hapus produk (admin)
  • POST /api/products/{id}/reviews/: Tambah review produk (user login)

Contoh Request/Response

POST /api/products/

{
  "name": "Apel Fuji",
  "description": "Apel segar dari Malang",
  "category_id": 1,
  "price": "20000.00",
  "stock": 100,
  "freshness": "fresh",
  "is_organic": true
}

Response:

{
  "id": 1,
  "name": "Apel Fuji",
  "description": "Apel segar dari Malang",
  "category": {"id": 1, "name": "Buah", "description": ""},
  "price": "20000.00",
  "stock": 100,
  "freshness": "fresh",
  "is_organic": true,
  "image": null,
  "created_at": "2024-06-01T10:00:00Z",
  "updated_at": "2024-06-01T10:00:00Z"
}

POST /api/products/{id}/reviews/

{
  "rating": 5,
  "comment": "Sangat segar!"
}

2. Orders

  • GET /api/orders/: Daftar pesanan user login
  • POST /api/orders/: Buat pesanan baru
  • GET/PATCH/DELETE /api/orders/{id}/: Detail/update/hapus pesanan user login

POST /api/orders/

{
  "shipping_address": "Jl. Mawar No. 1, Jakarta",
  "items": [
    {"product_id": 1, "quantity": 2},
    {"product_id": 2, "quantity": 1}
  ]
}

Response:

{
  "id": 1,
  "user": "user@email.com",
  "status": "pending",
  "total_price": "60000.00",
  "shipping_address": "Jl. Mawar No. 1, Jakarta",
  "created_at": "2024-06-01T10:00:00Z",
  "updated_at": "2024-06-01T10:00:00Z",
  "items": [
    {"id": 1, "product": {"id": 1, "name": "Apel Fuji", ...}, "quantity": 2, "price": "40000.00"},
    {"id": 2, "product": {"id": 2, "name": "Jeruk", ...}, "quantity": 1, "price": "20000.00"}
  ]
}

3. Users

  • POST /api/auth/register/: Registrasi user baru
  • POST /api/auth/login/: Login, mendapatkan token autentikasi

POST /api/auth/register/

{
  "email": "user@email.com",
  "first_name": "Budi",
  "last_name": "Santoso",
  "password": "passwordku"
}

Response:

{
  "id": 1,
  "email": "user@email.com",
  "first_name": "Budi",
  "last_name": "Santoso"
}

POST /api/auth/login/

{
  "username": "user@email.com",
  "password": "passwordku"
}

Response:

{
  "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "user_id": 1,
  "email": "user@email.com"
}

Diagram Relasi Model

File diagram visual PlantUML tersedia di docs/model_diagram.puml.

Contoh isi:

defaultskin
@startuml
entity "User" as User {
  * id
  * email
  * first_name
  * last_name
}
entity "Order" as Order {
  * id
  * user_id
  * status
  * total_price
  * shipping_address
}
entity "OrderItem" as OrderItem {
  * id
  * order_id
  * product_id
  * quantity
  * price
}
entity "Product" as Product {
  * id
  * name
  * category_id
  * price
  * stock
  * freshness
  * is_organic
}
entity "Category" as Category {
  * id
  * name
}
entity "ProductReview" as ProductReview {
  * id
  * product_id
  * user_id
  * rating
  * comment
}
User ||--o{ Order : "memiliki"
Order ||--o{ OrderItem : "memiliki"
OrderItem }o--|| Product : "produk"
Product }o--|| Category : "kategori"
Product ||--o{ ProductReview : "direview"
User ||--o{ ProductReview : "mereview"
@enduml

Catatan

  • Semua endpoint API menggunakan Django REST Framework dan sebagian besar endpoint membutuhkan autentikasi.
  • Dokumentasi API tersedia di /api/docs/.
  • Struktur modular memudahkan pengembangan dan pemeliharaan.

Cara Menjalankan

  1. Install dependencies:
    pip install -r requirements.txt
  2. Migrasi database:
    python manage.py migrate
  3. Jalankan server:
    python manage.py runserver
  4. Akses dokumentasi API di: http://localhost:8000/api/docs/

Saran Peningkatan

  • Tambahkan pengujian otomatis di setiap modul (tests.py).
  • Terapkan CI/CD untuk deployment otomatis.
  • Gunakan environment variable untuk konfigurasi rahasia.
  • Lengkapi validasi dan error handling pada serializer dan views.
  • Tambahkan fitur pagination, filter, dan search yang lebih advanced jika diperlukan.
  • Dokumentasikan endpoint custom jika ada penyesuaian di masa depan.

About

Api for Fresore Website

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages