Files
schedule-parser-next/src/schedule/schedule.controller.ts
2024-09-26 03:52:26 +04:00

116 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Post,
UseGuards,
} from "@nestjs/common";
import { AuthGuard } from "../auth/auth.guard";
import { ScheduleService } from "./schedule.service";
import {
CacheStatusDto,
GroupScheduleDto,
GroupScheduleRequestDto,
ScheduleDto,
ScheduleGroupsDto,
SiteMainPageDto,
} from "../dto/schedule.dto";
import { ResultDto } from "../utility/validation/class-validator.interceptor";
import {
ApiExtraModels,
ApiNotAcceptableResponse,
ApiNotFoundResponse,
ApiOkResponse,
ApiOperation,
refs,
} from "@nestjs/swagger";
@Controller("api/v1/schedule")
@UseGuards(AuthGuard)
export class ScheduleController {
constructor(private readonly scheduleService: ScheduleService) {}
@ApiExtraModels(ScheduleDto)
@ApiOperation({ summary: "Получение расписания", tags: ["schedule"] })
@ApiOkResponse({
description: "Расписание получено успешно",
schema: refs(ScheduleDto)[0],
})
@ResultDto(ScheduleDto)
@HttpCode(HttpStatus.OK)
@Get("get")
async getSchedule(): Promise<ScheduleDto> {
return await this.scheduleService.getSchedule();
}
@ApiExtraModels(GroupScheduleDto)
@ApiOperation({
summary: "Получение расписания группы",
tags: ["schedule"],
})
@ApiOkResponse({
description: "Расписание получено успешно",
schema: refs(GroupScheduleDto)[0],
})
@ApiNotFoundResponse({ description: "Требуемая группа не найдена" })
@ResultDto(GroupScheduleDto)
@HttpCode(HttpStatus.OK)
@Post("get-group")
async getGroupSchedule(
@Body() groupDto: GroupScheduleRequestDto,
): Promise<GroupScheduleDto> {
return await this.scheduleService.getGroup(groupDto.name);
}
@ApiExtraModels(ScheduleGroupsDto)
@ApiOperation({
summary: "Получение списка названий всех групп в расписании",
tags: ["schedule"],
})
@ApiOkResponse({
description: "Список получен успешно",
schema: refs(ScheduleGroupsDto)[0],
})
@ApiNotFoundResponse({ description: "Требуемая группа не найдена" })
@ResultDto(ScheduleGroupsDto)
@HttpCode(HttpStatus.OK)
@Get("get-group-names")
async getGroupNames(): Promise<ScheduleGroupsDto> {
return await this.scheduleService.getGroupNames();
}
@ApiExtraModels(SiteMainPageDto)
@ApiExtraModels(CacheStatusDto)
@ApiOperation({
summary: "Обновление данных основной страницы политехникума",
tags: ["schedule"],
})
@ApiOkResponse({ description: "Данные обновлены успешно" })
@ApiNotAcceptableResponse({
description: "Передан некорректный код страницы",
})
@ResultDto(CacheStatusDto)
@HttpCode(HttpStatus.OK)
@Post("update-site-main-page")
async updateSiteMainPage(
@Body() siteMainPageDto: SiteMainPageDto,
): Promise<CacheStatusDto> {
return await this.scheduleService.updateSiteMainPage(siteMainPageDto);
}
@ApiExtraModels(CacheStatusDto)
@ApiOperation({
summary: "Получение информации о кеше",
tags: ["schedule", "cache"],
})
@ApiOkResponse({ description: "Получение данных прошло успешно" })
@ResultDto(CacheStatusDto)
@HttpCode(HttpStatus.OK)
@Get("cache-status")
getCacheStatus(): CacheStatusDto {
return this.scheduleService.getCacheStatus();
}
}