diff --git a/service/src/app.module.ts b/service/src/app.module.ts index 0d05ae0..8ee1998 100644 --- a/service/src/app.module.ts +++ b/service/src/app.module.ts @@ -1,12 +1,14 @@ import { Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; +import { AppController } from './app/app.controller'; +import { AppService } from './app/app.service'; import { createDbClient } from './db'; +import { CalendarController } from './calendar/calendar.controller'; +import { CalendarService } from './calendar/calendar.service'; @Module({ imports: [ConfigModule.forRoot({ ignoreEnvFile: true })], - controllers: [AppController], + controllers: [AppController, CalendarController], providers: [ { provide: 'dbClient', @@ -18,6 +20,7 @@ import { createDbClient } from './db'; inject: [ConfigService], }, AppService, + CalendarService, ], }) // eslint-disable-next-line @typescript-eslint/no-extraneous-class diff --git a/service/src/app.controller.spec.ts b/service/src/app/app.controller.spec.ts similarity index 96% rename from service/src/app.controller.spec.ts rename to service/src/app/app.controller.spec.ts index 54a1537..84f9bba 100644 --- a/service/src/app.controller.spec.ts +++ b/service/src/app/app.controller.spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { AppController } from './app.controller'; import { AppService } from './app.service'; -import { DbClient } from './db'; +import { DbClient } from '../db'; describe('AppController', () => { let appController: AppController; diff --git a/service/src/app.controller.ts b/service/src/app/app.controller.ts similarity index 100% rename from service/src/app.controller.ts rename to service/src/app/app.controller.ts diff --git a/service/src/app.service.ts b/service/src/app/app.service.ts similarity index 90% rename from service/src/app.service.ts rename to service/src/app/app.service.ts index e5397d0..ca5a23c 100644 --- a/service/src/app.service.ts +++ b/service/src/app/app.service.ts @@ -1,5 +1,5 @@ import { Inject, Injectable } from '@nestjs/common'; -import { DbClient } from './db'; +import { DbClient } from '../db'; @Injectable() export class AppService { diff --git a/service/src/calendar/calendar.controller.spec.ts b/service/src/calendar/calendar.controller.spec.ts new file mode 100644 index 0000000..e7eb2cd --- /dev/null +++ b/service/src/calendar/calendar.controller.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { CalendarController } from './calendar.controller'; +import { CalendarService } from './calendar.service'; + +describe('CalendarController', () => { + let controller: CalendarController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [CalendarController], + providers: [CalendarService], + }).compile(); + + controller = module.get(CalendarController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/service/src/calendar/calendar.controller.ts b/service/src/calendar/calendar.controller.ts new file mode 100644 index 0000000..b0e04c4 --- /dev/null +++ b/service/src/calendar/calendar.controller.ts @@ -0,0 +1,24 @@ +import { + Body, + ClassSerializerInterceptor, + Controller, + HttpCode, + Post, + UseInterceptors, +} from '@nestjs/common'; +import { CalendarService } from './calendar.service'; +import { QueryParamsDto, QueryResponseDto } from './calendar.dto'; + +@Controller('calendar') +export class CalendarController { + constructor(private readonly calendarService: CalendarService) {} + + @Post('query') + @HttpCode(200) + @UseInterceptors(ClassSerializerInterceptor) + async getAvailableSlots( + @Body() queryParamsDto: QueryParamsDto, + ): Promise { + return await this.calendarService.getAvailableSlots(queryParamsDto); + } +} diff --git a/service/src/calendar/calendar.dto.ts b/service/src/calendar/calendar.dto.ts new file mode 100644 index 0000000..6989975 --- /dev/null +++ b/service/src/calendar/calendar.dto.ts @@ -0,0 +1,48 @@ +import { Expose, Transform } from 'class-transformer'; +import { IsArray, IsDateString, IsEnum, MaxLength } from 'class-validator'; + +export enum ProductType { + SolarPanels = 'SolarPanels', + Heatpumps = 'Heatpumps', +} + +export enum Language { + German = 'German', + English = 'English', +} + +export enum CustomerRating { + Gold = 'Gold', + Silver = 'Silver', + Bronze = 'Bronze', +} + +export class QueryParamsDto { + @MaxLength(10) + @IsDateString({ strict: true }) + public date!: string; + + @IsArray() + @IsEnum(ProductType, { each: true }) + public products!: ProductType[]; + + @IsEnum(Language) + public language!: Language; + + @IsEnum(CustomerRating) + public rating!: CustomerRating; +} + +export class QueryResponseDto { + @Expose({ name: 'available_count' }) + availableCount: number; + + @Expose({ name: 'start_date' }) + @Transform(({ value }) => (value as Date).toISOString()) + startDate: Date; + + constructor(availableCount: number, startDate: Date) { + this.availableCount = availableCount; + this.startDate = startDate; + } +} diff --git a/service/src/calendar/calendar.service.spec.ts b/service/src/calendar/calendar.service.spec.ts new file mode 100644 index 0000000..1927e6a --- /dev/null +++ b/service/src/calendar/calendar.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { CalendarService } from './calendar.service'; + +describe('CalendarService', () => { + let service: CalendarService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [CalendarService], + }).compile(); + + service = module.get(CalendarService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/service/src/calendar/calendar.service.ts b/service/src/calendar/calendar.service.ts new file mode 100644 index 0000000..9d29df8 --- /dev/null +++ b/service/src/calendar/calendar.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from '@nestjs/common'; +import { QueryParamsDto, QueryResponseDto } from './calendar.dto'; + +@Injectable() +export class CalendarService { + async getAvailableSlots(queryParamsDto: QueryParamsDto) { + console.log(queryParamsDto); + return Promise.resolve([new QueryResponseDto(1, new Date())]); + } +}