feat: implement category management API with CRUD operations for categories.
This commit is contained in:
parent
1caeac6226
commit
4b335b6b49
5 changed files with 220 additions and 2 deletions
45
Backend/src/controllers/CategoriesController.ts
Normal file
45
Backend/src/controllers/CategoriesController.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Delete, Controller, Security, Request, Put, Path } from 'tsoa';
|
||||
import { ValidationError } from '../middleware/errorHandler';
|
||||
import { CategoryService } from '../services/categories.service';
|
||||
import { createCategory, createCategoryResponse, deleteCategoryResponse, updateCategory, updateCategoryResponse, listCategoriesResponse } from '../types/categories.type';
|
||||
|
||||
@Route('api/admin/categories')
|
||||
@Tags('Admin/Categories')
|
||||
export class CategoriesController extends Controller {
|
||||
private categoryService = new CategoryService();
|
||||
|
||||
@Get()
|
||||
@Security('jwt', ['admin'])
|
||||
@SuccessResponse('200', 'Categories fetched successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async listCategories(): Promise<listCategoriesResponse> {
|
||||
return await this.categoryService.listCategories();
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Security('jwt', ['admin'])
|
||||
@SuccessResponse('200', 'Category created successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async createCategory(@Request() request: any, @Body() body: createCategory): Promise<createCategoryResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
||||
return await this.categoryService.createCategory(token, body);
|
||||
}
|
||||
|
||||
@Put('{id}')
|
||||
@Security('jwt', ['admin'])
|
||||
@SuccessResponse('200', 'Category updated successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async updateCategory(@Request() request: any, @Body() body: updateCategory): Promise<updateCategoryResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
||||
return await this.categoryService.updateCategory(token, body.id, body);
|
||||
}
|
||||
|
||||
@Delete('{id}')
|
||||
@Security('jwt', ['admin'])
|
||||
@SuccessResponse('200', 'Category deleted successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async deleteCategory(@Request() request: any, @Path() id: number): Promise<deleteCategoryResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
||||
return await this.categoryService.deleteCategory(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security, Request, Put } from 'tsoa';
|
||||
import { ValidationError } from '../middleware/errorHandler';
|
||||
import { UserService } from '../services/user.service';
|
||||
import {
|
||||
UserResponse,
|
||||
|
|
@ -10,7 +11,6 @@ import {
|
|||
} from '../types/user.types';
|
||||
import { ChangePassword } from '../types/auth.types';
|
||||
import { profileUpdateSchema, changePasswordSchema } from "../validators/user.validator";
|
||||
import { ValidationError } from '../middleware/errorHandler';
|
||||
|
||||
@Route('api/user')
|
||||
@Tags('User')
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { ListUsersResponse, GetUserResponse, ActivateAccountResponse, Deactivate
|
|||
import { getUserByIdValidator, updateUserRoleValidator } from '../validators/usermanagement.validator';
|
||||
|
||||
@Route('api/admin/usermanagement')
|
||||
@Tags('UserManagement')
|
||||
@Tags('Admin/UserManagement')
|
||||
export class UserManagementController {
|
||||
|
||||
private userManagementService = new UserManagementService();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue