Rename some API object and add update user to UserPoint. However, it seems to be broken somehow

This commit is contained in:
araemer 2025-11-13 21:32:27 +01:00
parent 81f1c3668b
commit a9bd803112
12 changed files with 143 additions and 41 deletions

View file

@ -7,7 +7,7 @@ import {
UnauthorizedError,
InternalServerError,
} from "../errors/httpErrors.js";
import { LoginRequestDto } from "../dtos/LoginRequestDto.js";
import { LoginRequest } from "../dtos/LoginRequest.js";
export const authBasicRoute = "/auth"
@ -18,13 +18,13 @@ const authController = new AuthHandler(userRepository, mapper);
/**
* Login using username and password
* Consumes LoginRequestDto
* Responds with LoginResponseDto
* Consumes LoginRequest
* Responds with LoginResponse
*/
router.post("/login", async (req, res) => {
console.log("login point called")
try {
const requestDto: LoginRequestDto = req.body;
const requestDto: LoginRequest = req.body;
const responseDto = await authController.login(requestDto);
res.json(responseDto);
} catch (err: any) {

View file

@ -19,7 +19,7 @@ const recipeIngredientMapper = new RecipeIngredientDtoEntityMapper();
const recipeIngredientGroupMapper = new RecipeIngredientGroupDtoEntityMapper(recipeIngredientMapper);
const recipeInstructionStepMapper = new RecipeInstructionStepDtoEntityMapper();
const recipeMapper = new RecipeDtoEntityMapper(recipeInstructionStepMapper, recipeIngredientGroupMapper);
const recipeController = new RecipeHandler(recipeRepository, recipeMapper);
const recipeHandler = new RecipeHandler(recipeRepository, recipeMapper);
/**
@ -34,7 +34,7 @@ router.post(
"/create-or-update",
asyncHandler(async(req, res) => {
const requestDto: RecipeDto = req.body;
const responseDto = await recipeController.createOrUpdateRecipe(requestDto);
const responseDto = await recipeHandler.createOrUpdateRecipe(requestDto);
res.status(201).json(responseDto);
})
)
@ -47,7 +47,7 @@ router.get(
"/:id",
asyncHandler(async(req, res) => {
const id = req.params.id;
const responseDto = await recipeController.getRecipeById(id);
const responseDto = await recipeHandler.getRecipeById(id);
res.status(201).json(responseDto);
})
);

View file

@ -1,9 +1,11 @@
import { Router } from "express";
import { UserHandler } from "../handlers/UserHandler.js";
import { CreateUserRequestDto } from "../dtos/CreateUserRequestDto.js";
import { CreateUserRequest } from "../dtos/CreateUserRequest.js";
import { UserRepository } from "../repositories/UserRepository.js";
import { UserDtoEntityMapper } from "../mappers/UserDtoEntityMapper.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import {CreateUserResponse} from "../dtos/CreateUserResponse.js";
import {UserDto} from "../dtos/UserDto.js";
/**
* Handles all user related routes
@ -11,24 +13,51 @@ import { asyncHandler } from "../utils/asyncHandler.js";
const router = Router();
// Inject repo + mapper here
const userRepository = new UserRepository();
const userMapper = new UserDtoEntityMapper();
const userController = new UserHandler(userRepository, userMapper);
const handler
= new UserHandler(new UserRepository(), new UserDtoEntityMapper());
/**
* Create a new user
* Consumes CreateUserRequestDto
* Consumes CreateUserRequest
* Responds with UserDto
*/
router.post(
"/",
"/create",
asyncHandler(async (req, res) => {
const requestDto: CreateUserRequestDto = req.body;
const responseDto = await userController.createUser(requestDto);
res.status(201).json(responseDto);
const request: CreateUserRequest = req.body;
const user : UserDto = await handler.createUser(request);
const response : CreateUserResponse = { userData: user };
res.status(201).json(response);
})
);
/**
* Update existing user
* Consumes UserDto
* Responds with UserDto
* Does not allow for password change. Use change-password instead
*/
router.post(
"/update",
asyncHandler(async (req, res) => {
const dto : UserDto = req.body;
const response = await handler.updateUserData(dto);
res.status(201).json(response);
})
)
/**
* Update password of existing user
* Consumes ChangeUserPasswordRequest
* Responds with code 201 indicating success
*/
router.post(
"/change-password",
asyncHandler(async (req, res) => {
throw Error("not implemented!");
})
)
/**
* Get user data for current user
* Responds with UserDto
@ -39,7 +68,7 @@ router.get("/me",
const id = req.currentUser?.id;
if(id){
// it breaks here because id is no longer a uuid
const responseDto = await userController.getUserById(id);
const responseDto = await handler.getUserById(id);
res.status(201).json(responseDto);
}
})