Backend API untuk:
- Autentikasi user (register, login, logout, refresh token)
- Manajemen berita (CRUD)
- Manajemen user dan role
- Ringkasan berita menggunakan Gemini API
- Silahkan download template disini jika anda mau mencoba coding dan tidak langsung terima jadi!
- Node.js + Express
- Sequelize + MySQL
- JWT (access token + refresh token via cookie)
- Joi (validasi)
index.js-> entry point serversrc/config-> konfigurasi databasesrc/models-> model Sequelize (users, roles, news)src/controllers-> logika endpointsrc/routes-> daftar route APIsrc/middlewares-> authentication + authorizationbe_studyjam.sql-> dump database
- Install dependency:
npm install- Buat file
.envdi root project:
DB_HOST=localhost
DB_PORT=3306
DB_DBNAME=be_studyjam
DB_USER=root
DB_PASS=your_password
ACCESS_TOKEN_SECRET=your_access_secret
REFRESH_TOKEN_SECRET=your_refresh_secret
GEMINI_API_KEY=your_gemini_api_key-
Import database dari file
be_studyjam.sql. -
Jalankan server:
node index.jsServer berjalan di:
http://localhost:3000
- Login menghasilkan cookie:
accessToken(15 menit)refreshToken(7 hari)
- Route berikut butuh login (authentication middleware):
/news/*/users/*/gemini/*
- Otorisasi per role dicek dari permission di tabel
roles.
Catatan:
- Cookie diset
secure: true, jadi untuk development lokal tanpa HTTPS cookie bisa tidak tersimpan di browser/client.
POST /register- body:
username,email,password,confirm_password
- body:
POST /login- body:
email,password
- body:
POST /logoutGET /refresh
GET /newsGET /news/:news_idPOST /news- body:
headline,content
- body:
PUT /news/:news_id- body:
headline,content
- body:
DELETE /news/:news_id
GET /usersGET /users/:user_idPUT /users/:user_id- body:
role_id
- body:
DELETE /users/:user_id
POST /gemini- body:
news_ids - format
news_ids: string id dipisahkan koma, contoh"1,2,3"
- body:
- Gunakan file Postman collection:
Fullstack StudyJam.postman_collection.json
Format respons umumnya:
{
"status": "success | error | Unauthorized | Forbidden",
"message": "...",
"data": {}
}Beberapa endpoint menambahkan field khusus seperti user, news_content, atau summarize_result.