Skip to content

Commit

Permalink
following rest api conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Khaled308 committed Oct 7, 2023
2 parents 0dfa048 + 97d0028 commit 96d8b19
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 27 deletions.
2 changes: 1 addition & 1 deletion clinic/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
"arrow-spacing": ["error", { "before": true, "after": true }],
"no-duplicate-imports": "error",
"prefer-const": "error"
}
}
}
7 changes: 7 additions & 0 deletions clinic/src/api/AdminAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import AdminService from '../service/admin-service.js';
//import { EMPTY_SIZE, ERROR_STATUS_CODE, NOT_FOUND_STATUS_CODE, OK_STATUS_CODE } from '../utils/Constants.js';

// export const admin = (app) => {
//const service = new AdminService();

// }
7 changes: 7 additions & 0 deletions clinic/src/api/AppointmentAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import AppointmentService from '../service/appointment-service.js';
//import { EMPTY_SIZE, ERROR_STATUS_CODE, NOT_FOUND_STATUS_CODE, OK_STATUS_CODE } from '../utils/Constants.js';

// export const appointment = (app) => {
//const service = new AppointmentService();

// }
7 changes: 7 additions & 0 deletions clinic/src/api/DoctorAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import DoctorService from '../service/doctor-service.js';
//import { EMPTY_SIZE, ERROR_STATUS_CODE, NOT_FOUND_STATUS_CODE, OK_STATUS_CODE } from '../utils/Constants.js';

// export const doctor = (app) => {
//const service = new DoctorService();

// }
35 changes: 18 additions & 17 deletions clinic/src/api/clinic.js → clinic/src/api/HealthPackageAPI.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import ClinicService from '../service/clinic-service.js';

import HealthPackageService from '../service/health-package-service.js';
import { EMPTY_SIZE, ERROR_STATUS_CODE, NOT_FOUND_STATUS_CODE, OK_STATUS_CODE } from '../utils/Constants.js';

export const clinic = (app) => {
const service = new ClinicService();
export const healthPackage = (app) => {
const service = new HealthPackageService();

app.get('/all-packages', async (req,res) => {
app.get('/packages', async (req, res) => {
const allPackages = await service.getAllPackages();
if(allPackages.length > EMPTY_SIZE){
if (allPackages.length > EMPTY_SIZE) {
res.status(OK_STATUS_CODE).json({ allPackages });
}else{
res.status(NOT_FOUND_STATUS_CODE).json({ message:'patients not found' });
} else {
res.status(NOT_FOUND_STATUS_CODE).json({ message: 'patients not found' });
}
});

app.post('/new-package', async (req, res) => {
app.post('/packages', async (req, res) => {

const { name, price, discountOfDoctor, discountOfMedicin, discountOfFamily } = req.body;
console.log({ name });

const data = await service.createNewPackage(name, price, discountOfDoctor, discountOfMedicin, discountOfFamily);
if(data){
if (data) {
res.status(OK_STATUS_CODE).json({ data });
}else{
} else {
res.status(ERROR_STATUS_CODE);
}
});
Expand All @@ -30,15 +31,15 @@ export const clinic = (app) => {

// });

app.delete('/remove-package/:id', async (req,res) => {
app.delete('/packages/:id', async (req, res) => {
const id = req.params.id;
try{
try {
console.log(id);
const deletedPackage = await service.deletePackage(id);
res.status(OK_STATUS_CODE).json({ deletedPackage });
}catch(err){
res.status(ERROR_STATUS_CODE).json({ err : err.message });
}
} catch (err) {
res.status(ERROR_STATUS_CODE).json({ err: err.message });
}
});

};
11 changes: 8 additions & 3 deletions clinic/src/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import express from 'express';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import { clinic } from './api/clinic.js';
import { healthPackage } from './api/HealthPackageAPI.js';
import { PORT } from './utils/Constants.js';

//import {doctor } from './api/doctor.js';
//import {appointment } from './api/appointment.js';
//import {admin } from './api/admin.js';


dotenv.config();
Expand All @@ -24,7 +26,10 @@ await connect();

app.use(express.json());

clinic(app);
healthPackage(app);
//admin(app);
//doctor(app);
//appointment(app);

const port = process.env.PORT || PORT;

Expand Down
2 changes: 2 additions & 0 deletions clinic/src/database/models/HealthPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mongoose from 'mongoose';


const HealthPackage = mongoose.Schema({

price: {
type: Number,
required: true
Expand All @@ -22,6 +23,7 @@ const HealthPackage = mongoose.Schema({
type : Number,
required: true
}

});

const HealthPackageModel = mongoose.model('HealthPackage', HealthPackage);
Expand Down
7 changes: 7 additions & 0 deletions clinic/src/database/repository/admin-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import AdminModel from '../models/Admin.js';

class AdminRepository{

}

export default AdminRepository;
7 changes: 7 additions & 0 deletions clinic/src/database/repository/appointment-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import AppointmentModel from '../models/Admin.js'

class AppointmentRepository{

}

export default AppointmentRepository;
7 changes: 7 additions & 0 deletions clinic/src/database/repository/doctor-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import DoctorModel from '../models/Doctor.js';

class DoctorRepository{

}

export default DoctorRepository;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import HealthPackageModel from '../models/HealthPackage.js';

class ClinicRepository{
class HealthPackageRepository{
async findAllPackages(){
const allPackages = await HealthPackageModel.find();
return allPackages;
Expand All @@ -26,4 +27,5 @@ class ClinicRepository{

}

export default ClinicRepository;
export default HealthPackageRepository;

7 changes: 7 additions & 0 deletions clinic/src/service/admin-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import AdminRepository from '../database/repository/admin-repository.js';

class AdminService{

}

export default AdminService;
7 changes: 7 additions & 0 deletions clinic/src/service/appointment-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import AppointmentRepository from '../database/repository/appointment-repository.js';

class AppointmentService{

}

export default AppointmentService;
7 changes: 7 additions & 0 deletions clinic/src/service/doctor-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import DoctorRepository from '../database/repository/doctor-repository.js';

class DoctorService{

}

export default DoctorService;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ClinicRepository from '../database/repository/clinic-repository.js';

class ClinicService {
import HealthPackageRepository from '../database/repository/health-package-repository.js';

class HealthPackageService {
constructor() {
this.repository = new ClinicRepository();
this.repository = new HealthPackageRepository();

}

Expand Down Expand Up @@ -31,4 +32,5 @@ class ClinicService {
}
}

export default ClinicService;
export default HealthPackageService;

0 comments on commit 96d8b19

Please sign in to comment.