A RESTful API for a job application platform built with Go, Gin, GORM, and PostgreSQL.
- User Authentication: JWT-based authentication with role-based access control
- Two User Roles:
- Companies: Can post, update, delete jobs and manage applications
- Applicants: Can browse jobs, apply, and track applications
- Job Management: Full CRUD operations for job postings
- Application System: Apply to jobs with resume upload and cover letters
- Search & Filtering: Search jobs by title, location, and company name
- Pagination: All list endpoints support pagination
- File Upload: Resume upload integration with Cloudinary
- Backend: Go 1.21+
- Framework: Gin Web Framework
- Database: PostgreSQL with GORM ORM
- Authentication: JWT tokens
- File Storage: Cloudinary
- Validation: go-playground/validator
POST /api/auth/signup
- User registrationPOST /api/auth/login
- User login
POST /api/jobs
- Create job postingPUT /api/jobs/:id
- Update job postingDELETE /api/jobs/:id
- Delete job postingGET /api/jobs/my-jobs
- Get company's job postingsGET /api/jobs/:id/applications
- Get applications for a job
GET /api/jobs
- Browse available jobs (with filters)POST /api/jobs/:id/apply
- Apply to a job
GET /api/jobs/:id
- Get job details
GET /api/applications/my-applications
- Get applicant's applications (Applicant only)PUT /api/applications/:id/status
- Update application status (Company only)
- Go 1.21 or higher
- PostgreSQL database
- Cloudinary account (for file uploads)
-
Clone the repository ```bash git clone cd job-api ```
-
Install dependencies ```bash go mod download ```
-
Set up environment variables ```bash cp .env.example .env ```
Edit
.env
file with your configuration: ```env DB_HOST=localhost DB_USER=postgres DB_PASSWORD=your-password DB_NAME=job_api DB_PORT=5432 JWT_SECRET=your-super-secret-jwt-key CLOUDINARY_CLOUD_NAME=your-cloud-name CLOUDINARY_API_KEY=your-api-key CLOUDINARY_API_SECRET=your-api-secret PORT=8080 ``` -
Create PostgreSQL database ```sql CREATE DATABASE job_api; ```
-
Run the application ```bash go run main.go ```
The server will start on http://localhost:8080
The application automatically creates the required tables on startup using GORM's AutoMigrate feature.
```bash
curl -X POST http://localhost:8080/api/auth/signup
-H "Content-Type: application/json"
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "SecurePass123!",
"role": "applicant"
}'
```
```bash
curl -X POST http://localhost:8080/api/auth/login
-H "Content-Type: application/json"
-d '{
"email": "john@example.com",
"password": "SecurePass123!"
}'
```
```bash
curl -X POST http://localhost:8080/api/jobs
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_JWT_TOKEN"
-d '{
"title": "Software Engineer",
"description": "We are looking for a skilled software engineer to join our team...",
"location": "Remote"
}'
```
```bash
curl -X GET "http://localhost:8080/api/jobs?page=1&page_size=10&title=engineer"
-H "Authorization: Bearer YOUR_JWT_TOKEN"
```
```bash
curl -X POST http://localhost:8080/api/jobs/JOB_ID/apply
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_JWT_TOKEN"
-d '{
"resume_link": "https://res.cloudinary.com/your-cloud/raw/upload/resume.pdf",
"cover_letter": "I am very interested in this position..."
}'
```
```json { "success": true, "message": "Operation successful", "object": { /* response data */ }, "errors": null } ```
```json { "success": true, "message": "Data retrieved successfully", "object": [ /* array of items */ ], "page_number": 1, "page_size": 10, "total_size": 50, "errors": null } ```
- Name: Required, alphabets only
- Email: Required, valid email format, unique
- Password: Required, minimum 8 characters, must contain:
- At least one uppercase letter
- At least one lowercase letter
- At least one digit
- At least one special character
- Role: Required, must be "applicant" or "company"
- Title: Required, 1-100 characters
- Description: Required, 20-2000 characters
- Location: Optional
- Resume Link: Required, valid URL
- Cover Letter: Optional, maximum 200 characters
- Password hashing using bcrypt
- JWT token-based authentication
- Role-based access control
- Input validation and sanitization
- CORS support
- SQL injection prevention through GORM
The API returns appropriate HTTP status codes and error messages:
400 Bad Request
: Invalid input data401 Unauthorized
: Missing or invalid authentication403 Forbidden
: Insufficient permissions404 Not Found
: Resource not found409 Conflict
: Duplicate resource (e.g., email already exists)500 Internal Server Error
: Server-side errors
``` job-api/ ├── config/ # Database configuration ├── handlers/ # HTTP request handlers ├── middleware/ # Authentication and authorization middleware ├── models/ # Database models and response structures ├── utils/ # Utility functions (JWT, validation, etc.) ├── main.go # Application entry point ├── go.mod # Go module dependencies └── README.md # This file ```