Skip to content

Commit

Permalink
Added Signup Endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: ryanjung1998 <ryanjung1998@gmail.com>
  • Loading branch information
ryanjung1998 committed Dec 4, 2023
1 parent 95167d9 commit 4520de1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
17 changes: 16 additions & 1 deletion backend/src/controllers/authentication.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,6 +22,20 @@ class AuthenticationController implements AuthenticationControllerInterface {
next: NextFunction
): Promise<void | Response<any, Record<string, any>>> => {
// 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 (
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/user.model.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 5 additions & 3 deletions backend/src/services/authentication.service.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
// TODO: Implement login and initialize session (Anfaal)
}

async signup(): Promise<void> {
async signup(email: string, password:string, firstName:string, lastName:string): Promise<void> {
// TODO: Implement signup and initialize session (Ryan)
const newUser = new User(email,password,firstName,lastName)
this.userRepository.createUser(newUser)
}

async logout(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion backend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface AuthenticationControllerInterface {

export interface AuthenticationServiceInterface {
login(): Promise<void>;
signup(): Promise<void>;
signup(email: string, password:string, firstName:string, lastName:string): Promise<void>;
logout(): Promise<void>;
}

Expand Down

0 comments on commit 4520de1

Please sign in to comment.