Skip to content

overmindtech/technical-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Management API

A simple REST API for managing users built with Go and SQLite.

Quick Start

# Install dependencies
go mod tidy

# Run the server
go run cmd/server/main.go

The server will start on http://localhost:8080.

API Endpoints

Get User by ID

GET /api/v1/users/{id}

Response:

{
  "user_id": 123,
  "user_name": "john_doe",
  "email_address": "john@example.com",
  "full_name": "John Doe",
  "registration_date": "2023-01-15T10:30:00Z",
  "user_age": 25,
  "is_active": true
}

Error Response:

{
  "error": {
    "message": "User not found",
    "code": "USER_NOT_FOUND"
  }
}

List All Users

GET /api/v1/users

Response:

[
  {
    "user_id": 123,
    "user_name": "john_doe",
    "email_address": "john@example.com",
    "full_name": "John Doe",
    "registration_date": "2023-01-15T10:30:00Z",
    "user_age": 25,
    "is_active": true
  }
]

Create User

POST /api/v1/users

Request Body:

{
  "user_name": "newuser",
  "email_address": "user@example.com",
  "full_name": "New User",
  "user_age": 30,
  "is_active": true
}

Response: 201 Created

{
  "user_id": 124,
  "user_name": "newuser",
  "email_address": "user@example.com",
  "full_name": "New User",
  "registration_date": "2023-04-01T12:00:00Z",
  "user_age": 30,
  "is_active": true
}

Update User

PUT /api/v1/users/{id}

Request Body: (all fields optional)

{
  "user_name": "updateduser",
  "email_address": "updated@example.com",
  "full_name": "Updated User",
  "user_age": 35,
  "is_active": false
}

Response: 200 OK

{
  "user_id": 123,
  "user_name": "updateduser",
  "email_address": "updated@example.com",
  "full_name": "Updated User",
  "registration_date": "2023-01-15T10:30:00Z",
  "user_age": 35,
  "is_active": false
}

Delete User

DELETE /api/v1/users/{id}

Response: 204 No Content

Error Handling

The API returns appropriate HTTP status codes:

  • 200 OK - Success
  • 201 Created - Resource created successfully
  • 204 No Content - Resource deleted successfully
  • 400 Bad Request - Invalid request data
  • 404 Not Found - Resource not found
  • 422 Unprocessable Entity - Validation errors
  • 500 Internal Server Error - Server errors

All error responses follow this format:

{
  "error": {
    "message": "Descriptive error message",
    "code": "ERROR_CODE"
  }
}

Database Schema

The API uses SQLite with the following schema:

CREATE TABLE users (
    user_id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_name TEXT NOT NULL UNIQUE,
    email_address TEXT NOT NULL,
    full_name TEXT NOT NULL,
    registration_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    user_age INTEGER NOT NULL,
    is_active BOOLEAN DEFAULT TRUE
);

Sample Data

The database comes pre-populated with sample users:

user_id user_name email_address full_name user_age is_active
1 john_doe john@example.com John Doe 25 true
2 jane_smith jane@example.com Jane Smith 30 false
3 bob_wilson bob@example.com Bob Wilson 28 true

Testing

You can test the API using curl:

# Get all users
curl http://localhost:8080/api/v1/users

# Get user by ID
curl http://localhost:8080/api/v1/users/1

# Create a new user
curl -X POST http://localhost:8080/api/v1/users \
  -H "Content-Type: application/json" \
  -d '{
    "user_name": "testuser",
    "email_address": "test@example.com",
    "full_name": "Test User",
    "user_age": 25,
    "is_active": true
  }'

# Update a user
curl -X PUT http://localhost:8080/api/v1/users/1 \
  -H "Content-Type: application/json" \
  -d '{
    "full_name": "John Updated Doe"
  }'

# Delete a user
curl -X DELETE http://localhost:8080/api/v1/users/1

Architecture

The application follows a clean architecture pattern:

  • cmd/server/main.go - Application entry point
  • pkg/api/handlers.go - HTTP request handlers
  • pkg/api/types.go - Data structures and types
  • pkg/api/database.go - Database operations
  • data/users.db - SQLite database file (created automatically)

The API is built using Go's standard net/http library with manual routing and JSON handling.

About

Technical challenges for interviews

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages