Skip to content

Sadmood/user-auth-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Authentication & Authorization System

ระบบ User Authentication และ Role-Based Access Control (RBAC) พัฒนาด้วยภาษา Go (Golang) โดยออกแบบโครงสร้างซอฟต์แวร์แบบ Hexagonal Architecture (Ports & Adapters)

🛠 Tech Stack

  • Language: Go (Golang)
  • Framework: Gin (HTTP Web Framework)
  • Database: PostgreSQL 15
  • ORM: GORM
  • Infrastructure: Docker & Docker Compose
  • Security: JWT (JSON Web Token), bcrypt (Password Hashing)

🏗 Architecture (Hexagonal Architecture)

โปรเจกต์ถูกแบ่งออกเป็น Layer อย่างชัดเจน และสื่อสารกันผ่าน Interface (Dependency Injection):

  • Domain: Entity หลักของระบบ (User, Role)
  • Ports: Interface สำหรับเชื่อมต่อ Inbound (Services) และ Outbound (Repositories)
  • Adapters: - Inbound: HTTP Handlers (Gin)
    • Outbound: PostgreSQL Repositories (GORM)
  • Services: Business Logic ของระบบ

🚀 How to Run (วิธีรันโปรเจกต์)

ระบบถูกตั้งค่าให้อำนวยความสะดวกในการใช้งานผ่าน Docker โดยจะทำการ Auto Migrate ตารางและ Seed ข้อมูลเริ่มต้นให้ทันที

  1. เปิดโปรแกรม Docker Desktop ให้ทำงาน
  2. เปิด Terminal ในโฟลเดอร์โปรเจกต์ แล้วรันคำสั่ง:
    docker-compose up -d --build
    
  3. ระบบจะรัน API ที่พอร์ต http://localhost:8080 และ Database ที่พอร์ต 5432

🔑 Seed Data (ข้อมูลเริ่มต้น) เมื่อระบบรันสำเร็จ จะมีข้อมูล Admin เริ่มต้นให้ใช้งาน (สำหรับให้กรรมการตรวจงานทดสอบระบบ):

Email: admin@example.com

Password: admin123

📡 API Endpoints & Testing

  1. Public Endpoints (ไม่ต้องใช้ Token) POST /register - สมัครสมาชิกใหม่

POST /login - เข้าสู่ระบบและรับ JWT Token

  1. Protected Endpoints (ต้องแนบ JWT Token ใน Header Authorization: Bearer ) GET /users - ดูข้อมูล User ทั้งหมดแบบมี Pagination

GET /users/:id - ดูข้อมูล User ตาม ID

PUT /users/:id - แก้ไขข้อมูล User (เฉพาะ Admin)

DELETE /users/:id - ลบข้อมูล User (เฉพาะ Admin)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors