add auth and user handling

This commit is contained in:
Anika Raemer 2025-09-21 19:49:54 +02:00
parent db057ce342
commit 1fce467571
19 changed files with 356 additions and 32 deletions

View file

@ -0,0 +1,38 @@
import { Router } from "express";
import { UserController } from "../controllers/UserController";
import { CreateUserRequestDto } from "../dtos/CreateUserRequestDto";
import { UserRepository } from "../repositories/UserRepository";
import { UserDtoEntityMapper } from "../mappers/UserDtoEntityMapper";
import {
ValidationError,
ConflictError,
NotFoundError,
InternalServerError,
} from "../errors/httpErrors";
const router = Router();
// Inject repo + mapper here
const userRepository = new UserRepository();
const userMapper = new UserDtoEntityMapper();
const userController = new UserController(userRepository, userMapper);
router.post("/", async (req, res) => {
try {
const requestDto: CreateUserRequestDto = req.body;
const responseDto = await userController.createUser(requestDto);
res.status(201).json(responseDto);
} catch (err: any) {
if (err instanceof ValidationError ||
err instanceof ConflictError ||
err instanceof NotFoundError) {
res.status(err.statusCode).json({ error: err.message });
} else {
console.error("Unexpected error:", err);
const internalError = new InternalServerError("Some unexpected error occurred!");
res.status(internalError.statusCode).json({ error: internalError.message });
}
}
});
export default router;