Skip to content

Commit

Permalink
📦 DI Container added
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Oct 8, 2024
1 parent 9c3cb41 commit f13141e
Show file tree
Hide file tree
Showing 20 changed files with 318 additions and 340 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

.23234/

**/di/

# Build directories
**/.next/
**/out/
Expand Down
1 change: 0 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@aws-sdk/client-s3": "^3.654.0",
"@aws-sdk/s3-request-presigner": "^3.637.0",
"@google/generative-ai": "^0.21.0",
"awilix": "^12.0.2",
"aws-sdk": "^2.1687.0",
"bcryptjs": "^2.4.3",
"cookie-parser": "^1.4.6",
Expand Down
57 changes: 57 additions & 0 deletions server/src/di/controllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import PrescriptionController from "../presentation/controllers/prescription/PrescriptionController";
import AppointmentController from "../presentation/controllers/appointment/AppointmentControllers";
import AuthPatientController from "../presentation/controllers/patient/AuthenticationController";
import UnauthenticatedControllers from "../presentation/controllers/UnauthenticatedControllers";
import AuthDoctorController from "../presentation/controllers/doctor/AuthenticationController";
import AdminPatientController from "../presentation/controllers/admin/AdminPatientController";
import AuthAdminController from "../presentation/controllers/admin/AuthenticationController";
import AdminDoctorController from "../presentation/controllers/admin/AdminDoctorController";
import PatientController from "../presentation/controllers/patient/PatientController";
import ChatBotController from "../presentation/controllers/chatbot/ChatBotController";
import DoctorController from "../presentation/controllers/doctor/DoctorController";
import AdminController from "../presentation/controllers/admin/AdminController";
import VideoController from "../presentation/controllers/video/VideoController";
import SlotController from "../presentation/controllers/slot/SlotController";

import createUseCase from "./useCases";

const {
adminDoctorUseCase,
adminPatientUseCase,
authAdminUseCase,
authDoctorUseCase,
authPatientUseCase,
chatBotUseCase,
createAppointmentUseCase,
createPrescriptionUseCase,
createSlotUseCase,
dashboardUseCase,
deleteSlotUseCase,
getAppointmentUseCase,
getPatientUseCase,
getSlotUseCase,
getVideoSectionUseCase,
patientUseCases,
unauthenticatedUseCases,
updateAppointmentUseCase,
updateSlotUseCase
} = createUseCase;

const createControllers = () => ({
adminController: new AdminController(dashboardUseCase),
adminDoctorController: new AdminDoctorController(adminDoctorUseCase),
adminPatientController: new AdminPatientController(adminPatientUseCase),
appointmentController: new AppointmentController(createAppointmentUseCase, getAppointmentUseCase, updateAppointmentUseCase),
chatBotController: new ChatBotController(chatBotUseCase),
doctorController: new DoctorController(getPatientUseCase),
patientController: new PatientController(patientUseCases),
authDoctorController: new AuthDoctorController(authDoctorUseCase),
authPatientController: new AuthPatientController(authPatientUseCase),
prescriptionController: new PrescriptionController(createPrescriptionUseCase),
slotController: new SlotController(createSlotUseCase, updateSlotUseCase, getSlotUseCase, deleteSlotUseCase),
videoController: new VideoController(getVideoSectionUseCase),
unauthenticatedController: new UnauthenticatedControllers(unauthenticatedUseCases),
authAdminController: new AuthAdminController(authAdminUseCase),
});

export default createControllers();
11 changes: 11 additions & 0 deletions server/src/di/middlewares.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PatientAuthMiddleware from "../presentation/middlewares/PatientAuthMiddleware";
import DoctorAuthMiddleware from "../presentation/middlewares/DoctorAuthMiddleware";
import AdminAuthMiddleware from "../presentation/middlewares/AdminAuthMiddleware";
import ErrorHandler from "../presentation/middlewares/ErrorHandler";
import { jwtService } from "./services";


export const authorizePatient = new PatientAuthMiddleware(jwtService);
export const authorizeDoctor = new DoctorAuthMiddleware(jwtService);
export const authorizeAdmin = new AdminAuthMiddleware(jwtService);
export const errorHandler = new ErrorHandler();
25 changes: 25 additions & 0 deletions server/src/di/repositories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import ChatBotMessageRepository from "../infrastructure/repositories/ChatBotMessageRepository";
import NotificationRepository from "../infrastructure/repositories/NotificationRepository";
import VideoSectionRepository from "../infrastructure/repositories/VideoSectionRepository";
import PrescriptionRepository from "../infrastructure/repositories/PrescriptionRepository";
import AppointmentRepository from "../infrastructure/repositories/AppointmentRepository";
import PatientRepository from "../infrastructure/repositories/PatientRepository";
import PaymentRepository from "../infrastructure/repositories/PaymentRepository";
import MessageRepository from "../infrastructure/repositories/MessageRepository";
import DoctorRepository from "../infrastructure/repositories/DoctorRepository";
import SlotRepository from "../infrastructure/repositories/SlotRepository";
import ChatRepository from "../infrastructure/repositories/ChatRepository";
import OtpRepository from "../infrastructure/repositories/OtpRepository";

export const chatBotMessageRepository = new ChatBotMessageRepository();
export const notificationRepository = new NotificationRepository();
export const videoSectionRepository = new VideoSectionRepository();
export const prescriptionRepository = new PrescriptionRepository();
export const appointmentRepository = new AppointmentRepository();
export const patientRepository = new PatientRepository();
export const paymentRepository = new PaymentRepository();
export const messageRepository = new MessageRepository();
export const doctorRepository = new DoctorRepository();
export const slotRepository = new SlotRepository();
export const chatRepository = new ChatRepository();
export const otpRepository = new OtpRepository();
17 changes: 17 additions & 0 deletions server/src/di/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import NodeMailerService from "../infrastructure/services/NodeMailerService";
import GeminiBotService from "../infrastructure/services/GeminiBotService";
import S3StorageService from "../infrastructure/services/S3StorageService";
import BcryptService from "../infrastructure/services/BcryptService";
import StripeService from "../infrastructure/services/StripeService";
import UUIDService from "../infrastructure/services/UUIDService";
import JWTService from "../infrastructure/services/JWTService";
import JoiService from "../infrastructure/services/JoiService";

export const nodeMailerService = new NodeMailerService();
export const geminiBotService = new GeminiBotService();
export const s3StorageService = new S3StorageService();
export const bcryptService = new BcryptService();
export const stripeService = new StripeService();
export const uuidService = new UUIDService();
export const jwtService = new JWTService();
export const joiService = new JoiService();
146 changes: 146 additions & 0 deletions server/src/di/useCases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import CreatePrescriptionUseCase from "../use_case/prescription/CreatePrescriptionUseCase";
import CreateAppointmentUseCase from "../use_case/appointment/CreateAppointmentUseCase";
import UpdateAppointmentUseCase from "../use_case/appointment/UpdateAppointmentUseCase";
import PatientAuthenticationUseCase from "../use_case/patient/AuthenticationUseCase";
import DoctorAuthenticationUseCase from "../use_case/doctor/AuthenticationUseCase";
import GetAppointmentUseCase from "../use_case/appointment/GetAppointmentUseCase";
import NotificationUseCase from "../use_case/notification/NotificationUseCase";
import GetVideoSectionUseCase from "../use_case/video/GetVideoSectionUseCase";
import AuthenticationUseCase from "../use_case/admin/AuthenticationUseCase";
import UnauthenticatedUseCases from "../use_case/UnauthenticatedUseCases";
import AdminPatientUseCase from "../use_case/admin/AdminPatientUseCase";
import AdminDoctorUseCase from "../use_case/admin/AdminDoctorUseCase";
import GetPatientUseCase from "../use_case/doctor/GetPatientUseCase";
import CreateSlotUseCase from "../use_case/slot/CreateSlotUseCase";
import CreateChatUseCase from "../use_case/chat/CreateChatUseCase";
import DeleteSlotUseCase from "../use_case/slot/DeleteSlotUseCase";
import UpdateSlotUseCase from "../use_case/slot/UpdateSlotUseCase";
import DashboardUseCase from "../use_case/admin/DashboardUseCase";
import PatientUseCases from "../use_case/patient/PatientUseCases";
import ChatBotUseCase from "../use_case/chatbot/ChatBotUseCase";
import GetChatUseCase from "../use_case/chat/GetChatUseCase";
import GetSlotUseCase from "../use_case/slot/GetSlotUseCase";

import {
appointmentRepository,
chatBotMessageRepository,
chatRepository,
doctorRepository,
messageRepository,
notificationRepository,
otpRepository,
patientRepository,
paymentRepository,
prescriptionRepository,
slotRepository,
videoSectionRepository,
} from "./repositories";

import {
bcryptService,
geminiBotService,
joiService,
jwtService,
nodeMailerService,
s3StorageService,
stripeService,
uuidService,
} from "./services";


const createUseCases = () => ({
authAdminUseCase: new AuthenticationUseCase(
doctorRepository,
bcryptService,
jwtService,
nodeMailerService,
otpRepository,
joiService
),
dashboardUseCase: new DashboardUseCase(
patientRepository,
appointmentRepository,
doctorRepository,
slotRepository
),
adminPatientUseCase: new AdminPatientUseCase(patientRepository, joiService),
adminDoctorUseCase: new AdminDoctorUseCase(doctorRepository, nodeMailerService, joiService),
createAppointmentUseCase: new CreateAppointmentUseCase(
appointmentRepository,
slotRepository,
joiService,
stripeService,
paymentRepository,
videoSectionRepository,
doctorRepository,
patientRepository,
uuidService
),
updateAppointmentUseCase: new UpdateAppointmentUseCase(
appointmentRepository,
joiService,
notificationRepository,
videoSectionRepository,
stripeService,
paymentRepository
),
getAppointmentUseCase: new GetAppointmentUseCase(
appointmentRepository,
joiService,
paymentRepository,
prescriptionRepository
),
createChatUseCase: new CreateChatUseCase(
messageRepository,
chatRepository,
joiService,
patientRepository,
doctorRepository
),
getChatUseCase: new GetChatUseCase(messageRepository, chatRepository, joiService, patientRepository),
chatBotUseCase: new ChatBotUseCase(chatBotMessageRepository, geminiBotService, joiService),
authDoctorUseCase: new DoctorAuthenticationUseCase(
doctorRepository,
bcryptService,
jwtService,
nodeMailerService,
otpRepository,
s3StorageService,
joiService
),
getPatientUseCase: new GetPatientUseCase(appointmentRepository, joiService),
notificationUseCase: new NotificationUseCase(notificationRepository, joiService),
authPatientUseCase: new PatientAuthenticationUseCase(
patientRepository,
bcryptService,
nodeMailerService,
otpRepository,
jwtService,
joiService
),
patientUseCases: new PatientUseCases(
patientRepository,
s3StorageService,
joiService,
chatRepository,
videoSectionRepository
),
createPrescriptionUseCase: new CreatePrescriptionUseCase(
joiService,
prescriptionRepository,
appointmentRepository
),
createSlotUseCase: new CreateSlotUseCase(slotRepository, joiService),
deleteSlotUseCase: new DeleteSlotUseCase(
slotRepository,
appointmentRepository,
joiService,
notificationRepository
),
getSlotUseCase: new GetSlotUseCase(slotRepository, appointmentRepository, joiService),
updateSlotUseCase: new UpdateSlotUseCase(slotRepository, joiService),
getVideoSectionUseCase: new GetVideoSectionUseCase(videoSectionRepository, joiService, appointmentRepository),
unauthenticatedUseCases: new UnauthenticatedUseCases(doctorRepository),
});

export default createUseCases();
30 changes: 2 additions & 28 deletions server/src/presentation/routers/admin/AdminRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
import { Router } from "express";
import AppointmentRepository from "../../../infrastructure/repositories/AppointmentRepository";
import PatientRepository from "../../../infrastructure/repositories/PatientRepository";
import DoctorRepository from "../../../infrastructure/repositories/DoctorRepository";
import AdminPatientController from "../../controllers/admin/AdminPatientController";
import NodeMailerService from "../../../infrastructure/services/NodeMailerService";
import AdminDoctorController from "../../controllers/admin/AdminDoctorController";
import SlotRepository from "../../../infrastructure/repositories/SlotRepository";
import AdminPatientUseCase from "../../../use_case/admin/AdminPatientUseCase";
import AdminDashBoardUseCase from "../../../use_case/admin/DashboardUseCase";
import AdminDoctorUseCase from "../../../use_case/admin/AdminDoctorUseCase";
import AdminController from "../../controllers/admin/AdminController";
import JoiService from "../../../infrastructure/services/JoiService";
import createControllers from "../../../di/controllers";

const router = Router();

const appointmentRepository = new AppointmentRepository();
const patientRepository = new PatientRepository();
const doctorRepository = new DoctorRepository();
const slotRepository = new SlotRepository();

const validatorService = new JoiService();
const emailService = new NodeMailerService();
const adminPatientUseCase = new AdminPatientUseCase(patientRepository, validatorService);
const adminPatientController = new AdminPatientController(adminPatientUseCase);

const adminDoctorUseCase = new AdminDoctorUseCase(doctorRepository, emailService, validatorService);
const adminDashBoardUseCase = new AdminDashBoardUseCase(patientRepository, appointmentRepository, doctorRepository, slotRepository);

const adminDoctorController = new AdminDoctorController(adminDoctorUseCase);
const adminController = new AdminController(adminDashBoardUseCase);

const { adminController, adminPatientController, adminDoctorController } = createControllers;

router.get('/patient-gender', adminController.getGenderStatistics.bind(adminController));
router.get('/users-months', adminController.getUsersStatistics.bind(adminController));
Expand Down
36 changes: 7 additions & 29 deletions server/src/presentation/routers/admin/AuthenticationRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
import { Router } from "express";
import AuthenticationController from "../../controllers/admin/AuthenticationController";
import NodeMailerService from "../../../infrastructure/services/NodeMailerService";
import DoctorRepository from "../../../infrastructure/repositories/DoctorRepository";
import AuthenticationUseCase from "../../../use_case/admin/AuthenticationUseCase";
import OtpRepository from "../../../infrastructure/repositories/OtpRepository";
import BcryptService from "../../../infrastructure/services/BcryptService";
import JWTService from "../../../infrastructure/services/JWTService";
import JoiService from "../../../infrastructure/services/JoiService";
import createControllers from "../../../di/controllers";

const router = Router();

const adminRepository = new DoctorRepository();
const otpRepository = new OtpRepository();
const passwordService = new BcryptService();
const tokenService = new JWTService();
const emailService = new NodeMailerService();
const validatorService = new JoiService();
const { authAdminController } = createControllers

const authUseCase = new AuthenticationUseCase(
adminRepository,
passwordService,
tokenService,
emailService,
otpRepository,
validatorService
);
const authController = new AuthenticationController(authUseCase);

router.post("/", authController.login.bind(authController));
router.post("/otp-verification", authController.validateOtp.bind(authController));
router.post("/resend-otp", authController.resendOtp.bind(authController));
router.get("/refresh", authController.refreshAccessToken.bind(authController));
router.post("/logout", authController.logout.bind(authController));
router.post("/", authAdminController.login.bind(authAdminController));
router.post("/otp-verification", authAdminController.validateOtp.bind(authAdminController));
router.post("/resend-otp", authAdminController.resendOtp.bind(authAdminController));
router.get("/refresh", authAdminController.refreshAccessToken.bind(authAdminController));
router.post("/logout", authAdminController.logout.bind(authAdminController));

export default router;
Loading

1 comment on commit f13141e

@vercel
Copy link

@vercel vercel bot commented on f13141e Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.