Skip to content

Latest commit

 

History

History
241 lines (200 loc) · 4.08 KB

README.md

File metadata and controls

241 lines (200 loc) · 4.08 KB

OPH-2025 Backend

Stack

  • Go (Golang)
  • Fiber (Go Web Framework)
  • PostgreSQL

Getting Started

Prerequisites

  • Go 1.22 or later
  • Docker
  • Makefile

Installation

  1. Clone the repository:

    git clone https://github.com/isd-sgcu/cutu2025-backend.git
    cd cutu2025-backend
  2. Setup environment:

    cp .env.example .env
    # Edit .env file with your configurations
  3. Install dependencies:

    go mod download

Running

Start Database:

docker-compose up -d

Run Server:

make server  # Normal mode

Re-create doc

swag init -g cmd/main.go  # Normal mode

API Documentation

User Management

1. Register New User Need Implementation

Endpoint: POST /api/users/register
Request Format (multipart/form-data):

name: string
phone: string (format: 0812345678)
province: string
school: string
firstInterest: string
secondInterest: string
thirdInterest: string
other...

Success Response (201):

{
  "accessToken": "string",
  "userId": "string"
}

2. Get All Users

Endpoint: GET /api/users
Permissions: Bearer Token (Staff/Admin)
Query Parameters:

  • name: Filter by name

Success Response (200):

[
  {
    "id": "string",
    "name": "string",
    "phone": "+66812345678",
    "province": "Bangkok",
    "school": "Chulalongkorn University"
  }
]

3. Get User by ID

Endpoint: GET /api/users/{id}
Permissions: Bearer Token

Success Response (200):

{
  "id": "string",
  "uid": "string",
  "name": "string",
  "phone": "+66812345678",
  "province": "Bangkok",
  "school": "Chulalongkorn University",
  "firstInterest": "Technology",
  "secondInterest": "Design",
  "thirdInterest": "Business"
}

4. Update User

Endpoint: PATCH /api/users/{id}
Permissions: Bearer Token
Request Body:

{
  "email": "[email protected]",
  "birthDate": "2000-01-01T00:00:00Z",
  "school": "New University"
}

Success Response: 204 No Content


QR Code Management

5. Scan QR Code

Endpoint: POST /api/users/qr/{id}
Permissions: Bearer Token (Staff/Admin)

Success Response (200):

{
  "id": "string",
  "name": "string",
  "lastEntered": "2024-01-01T12:00:00Z"
}

Error Response (400):

{
  "error": "User has already entered",
  "message": "2024-01-01 12:00:00 +0000 UTC"
}

Admin Operations

6. Add Staff Member

Endpoint: PATCH /api/users/addstaff/{phone}
Permissions: Bearer Token (Admin)

Success Response: 204 No Content


Data Structures

User Model

type User struct {
    ID              string     `json:"id"`
    UID             string     `json:"uid"`
    Name            string     `json:"name"`
    Email           *string    `json:"email"`
    Phone           string     `json:"phone"`
    BirthDate       *time.Time `json:"birthDate"`
    Role            Role       `json:"role"`
    Province        string     `json:"province"`
    School          string     `json:"school"`
    SelectedSources []string   `json:"selectedSources"`
    OtherSource     *string    `json:"otherSource"`
    FirstInterest   string     `json:"firstInterest"`
    SecondInterest  string     `json:"secondInterest"`
    ThirdInterest   string     `json:"thirdInterest"`
    Objective       string     `json:"objective"`
    RegisteredAt    *time.Time `json:"registerAt"`
    LastEntered     *time.Time `json:"lastEntered"`
}

Enumerations

User Roles:

type Role string
const (
    Member Role = "member"
    Staff  Role = "staff"
    Admin  Role = "admin"
)

Error Handling

Common Responses

400 Bad Request:

{
  "error": "Invalid phone number format"
}

401 Unauthorized:

{
  "error": "Missing or invalid token"
}

403 Forbidden:

{
  "error": "Insufficient permissions"
}

404 Not Found:

{
  "error": "User not found"
}

500 Internal Server Error:

{
  "error": "Database connection failed"
}