deleted: src/app.controller.spec.ts

modified:   src/app.module.ts
	modified:   src/app.service.ts
	new file:   src/bus/bus.controller.ts
	deleted:    src/strip.controller.ts
	new file:   src/strip/strip.controller.ts
This commit is contained in:
Maksym 2024-10-14 19:19:52 +02:00
parent 25af899ca7
commit ac8c5d52ec
6 changed files with 138 additions and 64 deletions

View File

@ -1,22 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});

View File

@ -1,11 +1,12 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { AppController } from './app.controller'; import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { StripController } from './strip.controller'; import { StripController } from './strip/strip.controller';
import { Bus } from './bus/bus.controller';
@Module({ @Module({
imports: [], imports: [],
controllers: [AppController, StripController], controllers: [AppController, StripController],
providers: [AppService], providers: [AppService, Bus],
}) })
export class AppModule {} export class AppModule {}

View File

@ -47,4 +47,12 @@ export class AppService implements OnModuleInit {
setGain(IOType: IOType, id: number, gain: number) { setGain(IOType: IOType, id: number, gain: number) {
return (this.strips[id].Gain = gain); return (this.strips[id].Gain = gain);
} }
getMuteState(IOType: IOType, id: number) {
return this.strips[id].Mute;
}
setMuteState(IOType: IOType, id: number, state: boolean) {
return (this.strips[id].Mute = state);
}
} }

58
src/bus/bus.controller.ts Normal file
View File

@ -0,0 +1,58 @@
import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Patch,
} from '@nestjs/common';
import { AppService, IOType } from 'src/app.service';
@Controller('/bus/:busId')
export class Bus {
constructor(private readonly appService: AppService) {}
@Get('/gain')
getGain(@Param('busId') busId: string) {
return { gain: this.appService.getGain(IOType.BUS, +busId) };
}
@Patch('/gain')
setGain(@Param('busId') busId: string, @Body() { gain }: { gain: number }) {
if (gain === undefined)
throw new HttpException(
'"gain" parameter not specified',
HttpStatus.BAD_REQUEST,
);
if (typeof gain !== 'number' || isNaN(gain))
throw new HttpException(
'Invalid "gain" parameter type. Must be number',
HttpStatus.BAD_REQUEST,
);
return { gain: this.appService.setGain(IOType.BUS, +busId, gain) };
}
@Get('/mute')
getMuteState(@Param('busId') busId: string) {
return { muteState: this.appService.getMuteState(IOType.BUS, +busId) };
}
@Patch('/mute')
setMuteState(
@Param('busId') busId: string,
@Body() { muteState }: { muteState: boolean },
) {
if (muteState === undefined)
throw new HttpException(
'"muteState" parameter not specified',
HttpStatus.BAD_REQUEST,
);
if (typeof muteState !== 'boolean')
throw new HttpException(
'Invalid "muteState" parameter type. Must be boolean',
HttpStatus.BAD_REQUEST,
);
return {
muteState: this.appService.setMuteState(IOType.BUS, +busId, muteState),
};
}
}

View File

@ -1,40 +0,0 @@
import {
Body,
Controller,
Get,
Header,
HostParam,
HttpException,
HttpStatus,
Param,
Patch,
Post,
Query,
} from '@nestjs/common';
import { AppService, IOType } from './app.service';
@Controller('/strip/:stripId')
export class StripController {
constructor(private readonly appService: AppService) {}
@Get('/gain')
getGain(@Param('stripId') stripId: string) {
return { gain: this.appService.getGain(IOType.STRIP, +stripId) };
}
@Patch('/gain')
setGain(
@Param('stripId') stripId: string,
@Body() { gain }: { gain: number },
) {
if (gain === undefined)
throw new HttpException(
'Gain parameter not specified',
HttpStatus.BAD_REQUEST,
);
if (typeof gain !== 'number' || isNaN(gain))
throw new HttpException(
'Invalid gain parameter type. Must be a number',
HttpStatus.BAD_REQUEST,
);
return { gain: this.appService.setGain(IOType.STRIP, +stripId, gain) };
}
}

View File

@ -0,0 +1,69 @@
import {
Body,
Controller,
Get,
Header,
HostParam,
HttpException,
HttpStatus,
Param,
Patch,
Post,
Query,
} from '@nestjs/common';
import { AppService, IOType } from '../app.service';
@Controller('/strip/:stripId')
export class StripController {
constructor(private readonly appService: AppService) {}
@Get('/gain')
getGain(@Param('stripId') stripId: string) {
return { gain: this.appService.getGain(IOType.STRIP, +stripId) };
}
@Patch('/gain')
setGain(
@Param('stripId') stripId: string,
@Body() { gain }: { gain: number },
) {
if (gain === undefined)
throw new HttpException(
'"gain" parameter not specified',
HttpStatus.BAD_REQUEST,
);
if (typeof gain !== 'number' || isNaN(gain))
throw new HttpException(
'Invalid "gain" parameter type. Must be number',
HttpStatus.BAD_REQUEST,
);
return { gain: this.appService.setGain(IOType.STRIP, +stripId, gain) };
}
@Get('/mute')
getMuteState(@Param('stripId') stripId: string) {
return { muteState: this.appService.getMuteState(IOType.STRIP, +stripId) };
}
@Patch('/mute')
setMuteState(
@Param('stripId') stripId: string,
@Body() { muteState }: { muteState: boolean },
) {
if (muteState === undefined)
throw new HttpException(
'"muteState" parameter not specified',
HttpStatus.BAD_REQUEST,
);
if (typeof muteState !== 'boolean')
throw new HttpException(
'Invalid "muteState" parameter type. Must be boolean',
HttpStatus.BAD_REQUEST,
);
return {
muteState: this.appService.setMuteState(
IOType.STRIP,
+stripId,
muteState,
),
};
}
}