An open API service indexing awesome lists of open source software.

https://github.com/dimdevs/sentuh-interview-go-test

sentuh-interview-go-test
https://github.com/dimdevs/sentuh-interview-go-test

Last synced: 9 months ago
JSON representation

sentuh-interview-go-test

Awesome Lists containing this project

README

          

# ๐Ÿ“ฆ Proyek REST API Golang โ€“ GO-TEST

RESTful API sederhana menggunakan **Golang**, **Echo**, **GORM**, **MySQL**, dan **JWT**. Proyek ini mendukung autentikasi, manajemen user, produk, dan kategori lengkap dengan fitur pagination dan pencarian.

---

## ๐Ÿ“ Struktur Folder Proyek

```
GO-TEST/
โ”œโ”€โ”€ config/ # Konfigurasi database
โ”œโ”€โ”€ controllers/ # Handler untuk setiap endpoint API
โ”œโ”€โ”€ logs/ # File log
โ”œโ”€โ”€ middleware/ # Middleware untuk JWT & logging
โ”œโ”€โ”€ models/ # Model untuk GORM
โ”œโ”€โ”€ routes/ # Routing semua endpoint
โ”œโ”€โ”€ utils/ # Fungsi utilitas (contoh: hash password)
โ”œโ”€โ”€ .env # Variabel environment
โ”œโ”€โ”€ main.go # Entry point aplikasi
โ”œโ”€โ”€ go.mod # File modul Go
โ””โ”€โ”€ README.md # Dokumentasi proyek
```

---

## ๐Ÿš€ Cara Menjalankan Aplikasi

### 1. Clone repository
```bash
git clone https://github.com/username/go-test.git
cd go-test
```

### 2. Install dependency
```bash
go mod tidy
```

### 3. Konfigurasi file `.env`
```env
DB_USER=mascen
DB_PASS=mascen
DB_NAME=test_db
DB_HOST=127.0.0.1
DB_PORT=3306
JWT_SECRET=kangen_mas_cen
```

### 4. Jalankan aplikasi
```bash
go run main.go
```
Aplikasi akan berjalan di http://localhost:5050.

---

## โœ… Fitur

- ๐Ÿ” Autentikasi JWT (Login & Register)
- ๐Ÿ‘ค CRUD untuk User
- ๐Ÿ“ฆ CRUD untuk Produk (dengan kategori)
- ๐Ÿ—‚๏ธ CRUD untuk Kategori
- ๐Ÿ” Pencarian produk berdasarkan nama/kategori
- ๐Ÿ“„ Pagination
- ๐Ÿ“‹ GORM Hooks
- ๐Ÿ“ Logging ke file
- ๐Ÿงผ Struktur folder clean code

---

## ๐Ÿ” Autentikasi

### Register
```http
POST /register
```
**Body:**
```json
{
"name": "Nama Kamu",
"email": "email@example.com",
"password": "123456"
}
```

### Login
```http
POST /login
```
**Body:**
```json
{
"email": "email@example.com",
"password": "123456"
}
```

**Response:**
```json
{
"token": "token_jwt_mas_cendi"
}
```

> Gunakan token di header Authorization:
```
Authorization: Bearer token_jwt_mas_cendi
```

---

## ๐Ÿ‘ฅ Endpoint User (`/api/users`)
| Method | Endpoint | Keterangan |
|--------|------------------|--------------------|
| POST | `/api/users` | Tambah user |
| GET | `/api/users/:id` | Ambil user by ID |
| PUT | `/api/users/:id` | Update user |
| DELETE | `/api/users/:id` | Hapus user |

---

## ๐Ÿ“ฆ Endpoint Produk (`/api/products`)
| Method | Endpoint | Keterangan |
|--------|----------------------|--------------------------------|
| POST | `/api/products` | Tambah produk |
| GET | `/api/products/:id` | Ambil produk by ID |
| PUT | `/api/products/:id` | Update produk |
| DELETE | `/api/products/:id` | Hapus produk |
| GET | `/api/products` | Ambil semua produk (dengan filter dan pagination) |

**Query Parameters (opsional):**
- `page`: halaman keberapa
- `limit`: jumlah data per halaman
- `name`: filter berdasarkan nama produk
- `category`: filter berdasarkan nama kategori

---

## ๐Ÿ—‚๏ธ Endpoint Kategori (`/api/categories`)
| Method | Endpoint | Keterangan |
|--------|------------------------|------------------------|
| POST | `/api/categories` | Tambah kategori |
| GET | `/api/categories` | Ambil semua kategori |
| GET | `/api/categories/:id` | Ambil kategori by ID |
| PUT | `/api/categories/:id` | Update kategori |
| DELETE | `/api/categories/:id` | Hapus kategori |

---

## ๐Ÿงช Testing API

Info tools :
- [Postman](https://warped-rocket-810602.postman.co/workspace/My-Workspace~cba4b606-39dd-4c77-860e-37b6bf7186b6/folder/22097543-ab04b4ee-4cc8-4033-982c-607ecc4a30e2)
- [curl](https://curl.se/)
- Swagger (dalam pengembangan)

---

## ๐Ÿ“ Log File

Semua log disimpan otomatis ke dalam:
```
logs/server.log
```

---

## ๐Ÿ‘จโ€๐Ÿ’ป Developer

**dimdevs**
Instagram: [https://www.instagram.com/dimdevs_/](https://www.instagram.com/dimdevs_/)