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

https://github.com/tobysolutions/school-complaints-api

This is the backend for the school complaints API codebase
https://github.com/tobysolutions/school-complaints-api

Last synced: 4 months ago
JSON representation

This is the backend for the school complaints API codebase

Awesome Lists containing this project

README

          

# 📌 School Complaints API

## 📖 Overview
The **School Complaints API** is a backend system built with **Laravel** that allows students to submit complaints against lecturers, track their status, and receive responses. Lecturers can respond to complaints, change their status, and mark them as resolved.

## 🚀 Features
- **User Authentication** (Students & Lecturers)
- **Complaint Submission & Tracking**
- **Lecturer Response Management**
- **Seeding Default Users & Departments**
- **RESTful API Endpoints**

---

## 📂 Project Setup

### 1️⃣ **Clone the Repository**
```sh
git clone
cd school-complaints-api
```

### 2️⃣ **Install Dependencies**
```sh
composer install
```

### 3️⃣ **Set Up Database Locally**

#### **Install MySQL (if not installed)**
```sh
brew install mysql
```

#### **Start MySQL Service**
```sh
brew services start mysql
```

#### **Login to MySQL & Create Database**
```sh
mysql -u root -p
```
Then, inside MySQL:
```sql
CREATE DATABASE school_complaints;
EXIT;
```

#### **Verify MySQL is Running**
```sh
mysqladmin -u root -p status
```

### 4️⃣ **Set Up Environment Variables**
Copy the `.env.example` file and rename it to `.env`:
```sh
cp .env.example .env
```
Edit `.env` and update the database credentials:
```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=school_complaints
DB_USERNAME=root
DB_PASSWORD=newpassword
```

### 5️⃣ **Generate Application Key**
```sh
php artisan key:generate
```

### 6️⃣ **Run Database Migrations & Seeding**
```sh
php artisan migrate:fresh --seed
```
✅ **This will drop all tables, recreate them, and seed default users.**

### 7️⃣ **Start Laravel Development Server**
```sh
php artisan serve
```
Server will be running at:
```sh
http://127.0.0.1:8000
```

---

## 🔑 Default Users (Seeded Data)

| Name | Email | Password | Role |
|------------------|---------------------|-------------|---------|
| Alice Johnson | alice@example.com | password123 | Student |
| Bob Anderson | bob@example.com | password123 | Student |
| Charlie Brown | charlie@example.com | password123 | Student |
| David Green | david@example.com | password123 | Student |
| Dr. Smith | smith@example.com | password123 | Lecturer |
| Prof. Johnson | johnson@example.com | password123 | Lecturer |
| Dr. Williams | williams@example.com | password123 | Lecturer |
| Dr. Evans | evans@example.com | password123 | Lecturer |

---

## 📌 API Endpoints

### 🔑 **Authentication**
| Method | Endpoint | Description |
|--------|--------------|-------------|
| POST | `/api/register` | Register a new user |
| POST | `/api/login` | Login and receive user details |

### 🏫 **Students & Lecturers**
| Method | Endpoint | Description |
|--------|-------------------|-------------|
| GET | `/api/students/{id}` | Get student details (with department & courses) |
| GET | `/api/lecturers/{id}` | Get lecturer details (with department) |

### 🏛 **Departments & Courses**
| Method | Endpoint | Description |
|--------|-------------------|-------------|
| GET | `/api/departments/{id}` | Get department details (with courses) |

### 📝 **Complaints**
| Method | Endpoint | Description |
|--------|------------------------------|-------------|
| POST | `/api/complaints` | Submit a complaint |
| GET | `/api/complaints/{id}` | Get complaint details |
| PUT | `/api/complaints/{id}/status` | Update complaint status |
| POST | `/api/complaints/{id}/comments` | Lecturer responds to complaint |

---

## 🛠 **Troubleshooting**

### ❌ `SQLSTATE[42S22]: Column not found: 1054 Unknown column 'role'`
✅ Ensure your `users` table has the `role` column. If missing, rerun migrations:
```sh
php artisan migrate:fresh --seed
```

### ❌ `401 Unauthorized` when logging in
✅ Clear the cache and restart the Laravel server:
```sh
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan serve
```