diff --git a/backend/src/controllers/authentication.controller.ts b/backend/src/controllers/authentication.controller.ts index e8aaf8c..bcb03f6 100644 --- a/backend/src/controllers/authentication.controller.ts +++ b/backend/src/controllers/authentication.controller.ts @@ -3,9 +3,10 @@ import { AuthenticationControllerInterface, AuthenticationServiceInterface, } from "../../types.js"; +import { BadRequestError } from "../errors/errors.js"; class AuthenticationController implements AuthenticationControllerInterface { - constructor(private authentication: AuthenticationServiceInterface) {} + constructor(private authenticationService: AuthenticationServiceInterface) {} postLogin = async ( req: Request, @@ -21,6 +22,20 @@ class AuthenticationController implements AuthenticationControllerInterface { next: NextFunction ): Promise>> => { // TODO: Implement postSignup controller (Ryan) + try{ + const email = req.body.email + const password = req.body.password + const firstName = req.body.firstName + const lastName = req.body.lastName + if(email == null || password == null || firstName == null || lastName == null){ + throw new BadRequestError("All fields must be submitted") + } + this.authenticationService.signup(email, password, firstName, lastName) + } + catch (err){ + next(err) + } + }; postLogout = async ( diff --git a/backend/src/models/user.model.ts b/backend/src/models/user.model.ts index 0a3372e..8af59fd 100644 --- a/backend/src/models/user.model.ts +++ b/backend/src/models/user.model.ts @@ -1,6 +1,6 @@ import { UserInterface } from "../../types.js"; -class User implements UserInterface { +export class User implements UserInterface { constructor( private email: string, private password: string, diff --git a/backend/src/services/authentication.service.ts b/backend/src/services/authentication.service.ts index 0fba607..40dd145 100644 --- a/backend/src/services/authentication.service.ts +++ b/backend/src/services/authentication.service.ts @@ -1,15 +1,17 @@ import { UserRepositoryInterface } from "../../types"; -import UserRepository from "../repositories/user.repository"; +import {User} from "../models/user.model" class AuthenticationService implements AuthenticationService { - constructor(private UserRepository: UserRepositoryInterface) {} + constructor(private userRepository: UserRepositoryInterface) {} async login(): Promise { // TODO: Implement login and initialize session (Anfaal) } - async signup(): Promise { + async signup(email: string, password:string, firstName:string, lastName:string): Promise { // TODO: Implement signup and initialize session (Ryan) + const newUser = new User(email,password,firstName,lastName) + this.userRepository.createUser(newUser) } async logout(): Promise { diff --git a/backend/types.ts b/backend/types.ts index 9483305..1d91da5 100644 --- a/backend/types.ts +++ b/backend/types.ts @@ -47,7 +47,7 @@ export interface AuthenticationControllerInterface { export interface AuthenticationServiceInterface { login(): Promise; - signup(): Promise; + signup(email: string, password:string, firstName:string, lastName:string): Promise; logout(): Promise; }