Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
PORT =
PORT = 3000
DBNAME = databaseName
DBUSER = databaseUser
DBPASSWORD = databasePassword
DBHOST = 127.0.0.1
DBDIALECT = postgres
73 changes: 61 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,62 @@
# Class Manager
### Introduction
<strong> More information coming soon ... </strong>

### Installation Guide
* Clone this repository [here](https://github.com/devcareer/class-manager.git).
* The main branch is the most stable branch at any given time, ensure you're working from it.
* Run <b>npm install</b> to install all dependencies
* Create an <b>.env</b> file in your project root folder and add your variables. See .env.example for assistance.
### Usage
* Run <b>npm watch:dev</b> to start the application.
### License
This project is available for use under the MIT License.

### The technologies used in creating this project are:
Node.js, ExpressJs, Sequelize ORM, and PostgreSQL

### :rocket: How to get started
- Make sure to have Git and Node.js installed on your computer
- Clone the project by running: `git clone https://https://github.com/devcareer/class-manager`
- cd into the project and run `npm install`
- create a `.env` file in the root folder and copy the content in the `.env.example`into it.
- run `npm run migrate` to migrate to the database.
- run `npm run migrate:undo` to undo migration.
- run `npm run seed` to seed the database.
- run `npm start` to start the project.

These are the HTTP response codes used in this project:
| Status Codes | Indication |
| --- | --- |
| `200` | This `OK` status code indicates that a request has succeeded |
| `400` | This `bad request error` status code indicates that the request sent to the server is incorrect |
| `404` | This `not found error` status code indicates that the resource is not found. |
| `500` | This `internal server error` status code indicates that something has gone wrong on the web server |

<hr>

The routes featured in this project:
| API routes(url) | Method | Description |
| --- | --- | --- |
| / | `GET` | Api home page |
| /messages | `GET` | Get all messages |
| /messages | `POST` | Create a message |
| /messages/id | `GET` | Get a message by id |
| /messages/id | `PUT` | Update message|
| /messages/id | `DELETE` | Delete message |
| /students | `GET` | Get all students |
| /students | `POST` | Create a student |
| /students/id | `GET` | Get a student by id |
| /students/id | `PUT` | Update student |
| /students/id | `DELETE` | Delete student |
| /teacher | `GET` | Get all teachers |
| /teacher | `POST` | Create a teacher |
| /teacher/id | `GET` | Get a teacher by id |
| /teacher/id | `PUT` | Update teacher |
| /teacher/id | `DELETE` | Delete teacher |
| /assignment | `GET` | Get all assignment |
| /assignment/id | `GET` | Get a assignment with id |
| /assignment/id | `PUT` | Update assignment |
| /assignment/id | `DELETE` | Delete assignment |

<hr>


👤 **Authors**:

| Github | Linkedin |
| ------------- | ------------- |
| [@bellogo](https://github.com/bellogo) | [Ufuoma Ogodo](https://ng.linkedin.com/in/ufuoma-ogodo) |
| [@judyseyram](https://github.com/JudySeyram) | [Judith Amegbe](https://gh.linkedin.com/in/amegbe-judith-5b881811a) |
| [@hazeem01](https://github.com/Hazeem01) | [Adenekan Abdulhazeem](https://www.linkedin.com/in/abdulhazeem-adenekan) |
| [@talktonok](https://github.com/talktonok) | [Mansur Ibrahim Nok](https://www.linkedin.com/in/mansuribrahimnok) |
| [@TijanAyo](https://github.com/TijanAyo) | [Tijani Ayomide](https://www.linkedin.com/in/tijanayo) |
| [@Ekemiben](https://github.com/ekemiben) | [Ekemini Ben](https://www.linkedin.com/in/ekemini-ben) |
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"body-parser": "^1.20.1",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-fileupload": "^1.4.0",
"pg": "^8.8.0",
"pg-hstore": "^2.3.4",
"sequelize": "^6.25.3"
Expand Down
128 changes: 128 additions & 0 deletions src/controllers/assignmentsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import AssignmentService from '../services/AssignmentService.js';
import Util from '../utils/Utils.js';

const util = new Util();

class AssignmentController {
static async home(req, res) {
res.send(`<h1>Welcome to the assignment Route</h1>`)
}

static async getAllAssignments(req, res) {
try {
const allAssignments = await AssignmentService.getAllAssignments();
if (allAssignments.length > 0) {
util.setSuccess(200, 'Assignments retrieved', allAssignments);
} else {
util.setSuccess(200, 'No Assignment found in the database');
}
return util.send(res);
} catch (error) {
util.setError(400, error);
return util.send(res);
}
}

static async addAssignment(req, res) {
if (!req.body.Assignment || !req.body.senderId || !req.body.receiverId) {
util.setError(400, 'Please provide complete details of the Assignment');
return util.send(res);
}
const newAssignment = req.body;
try {
const createdAssignment = await AssignmentService.addAssignment(newAssignment);
util.setSuccess(201, 'Assignment Added Successfully!', createdAssignment);
return util.send(res);
} catch (error) {
util.setError(400, error.Assignment);
return util.send(res);
}
}

static async updatedAssignment(req, res) {
const alteredAssignment = req.body;
const { id } = req.params;
if (!Number(id)) {
util.setError(400, 'Please input a valid numeric value');
return util.send(res);
}
try {
const updateAssignment = await AssignmentService.updateAssignment(id, alteredAssignment);
if (!updateAssignment) {
util.setError(404, `Cannot find a Assignment with the id: ${id}`);
} else {
util.setSuccess(200, 'Assignment updated', updateAssignment);
}
return util.send(res);
} catch (error) {
util.setError(404, error);
return util.send(res);
}
}

static async getAAssignment(req, res) {
const { id } = req.params;

if (!Number(id)) {
util.setError(400, 'Please input a valid numeric value');
return util.send(res);
}

try {
const theAssignment = await AssignmentService.getAAssignment(id);

if (!theAssignment) {
util.setError(404, `Cannot find a Assignment with the id ${id}`);
} else {
util.setSuccess(200, 'Found Assignment', theAssignment);
}
return util.send(res);
} catch (error) {
util.setError(404, error);
return util.send(res);
}
}

static async deleteAssignment(req, res) {
const { id } = req.params;

if (!Number(id)) {
util.setError(400, 'Please provide a numeric value');
return util.send(res);
}

try {
const AssignmentToDelete = await AssignmentService.deleteAssignment(id);

if (AssignmentToDelete) {
util.setSuccess(200, `Assignment with ${id} deleted`);
} else {
util.setError(404, `Assignment with the id ${id} cannot be found`);
}
return util.send(res);
} catch (error) {
util.setError(400, error);
return util.send(res);
}
}

static async uploadAssignment(req, res) {
const { id } = req.params;
if (!req.files) {
util.setError(400, 'Please select a file for upload');
return util.send(res);
}
const newUpload = req.files;
try {
await AssignmentService.uploadAssignment(newUpload, id);
util.setSuccess(201, 'Assignment Uploaded Successfully!');
return util.send(res);
} catch (error) {
util.setError(400, error.Assignment);
return util.send(res);
}
}

}

export default AssignmentController;
Loading