diff --git a/src/api/public/me/me.controller.spec.ts b/src/api/public/me/me.controller.spec.ts new file mode 100644 index 000000000..0f6ffdc95 --- /dev/null +++ b/src/api/public/me/me.controller.spec.ts @@ -0,0 +1,26 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { HistoryModule } from '../../../history/history.module'; +import { User } from '../../../users/user.entity'; +import { UsersModule } from '../../../users/users.module'; +import { MeController } from './me.controller'; + +describe('Me Controller', () => { + let controller: MeController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [MeController], + imports: [UsersModule, HistoryModule], + }) + .overrideProvider(getRepositoryToken(User)) + .useValue({}) + .compile(); + + controller = module.get(MeController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/api/public/me/me.controller.ts b/src/api/public/me/me.controller.ts new file mode 100644 index 000000000..f561ceb7f --- /dev/null +++ b/src/api/public/me/me.controller.ts @@ -0,0 +1,54 @@ +import { + Body, + Controller, + Delete, + Get, + HttpCode, + Logger, + NotFoundException, + Param, + Put, +} from '@nestjs/common'; +import { HistoryEntryUpdateDto } from '../../../history/history-entry-update.dto'; +import { HistoryEntryDto } from '../../../history/history-entry.dto'; +import { HistoryService } from '../../../history/history.service'; +import { UserInfoDto } from '../../../users/user-info.dto'; +import { UsersService } from '../../../users/users.service'; + +@Controller('me') +export class MeController { + private readonly logger = new Logger(MeController.name); + + constructor( + private usersService: UsersService, + private historyService: HistoryService, + ) {} + + @Get() + getMe(): UserInfoDto { + return this.usersService.getUserInfo(); + } + + @Get('history') + getUserHistory(): HistoryEntryDto[] { + return this.historyService.getUserHistory('someone'); + } + + @Put('history/:note') + updateHistoryEntry( + @Param('note') note: string, + @Body() entryUpdateDto: HistoryEntryUpdateDto, + ): HistoryEntryDto { + return this.historyService.updateHistoryEntry(note, entryUpdateDto); + } + + @Delete('history/:note') + @HttpCode(204) + deleteHistoryEntry(@Param('note') note: string) { + try { + return this.historyService.deleteHistoryEntry(note); + } catch (e) { + throw new NotFoundException(e.message); + } + } +} diff --git a/src/api/public/media/media.controller.spec.ts b/src/api/public/media/media.controller.spec.ts new file mode 100644 index 000000000..1f04a4483 --- /dev/null +++ b/src/api/public/media/media.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { MediaController } from './media.controller'; + +describe('Media Controller', () => { + let controller: MediaController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [MediaController], + }).compile(); + + controller = module.get(MediaController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/api/public/media/media.controller.ts b/src/api/public/media/media.controller.ts new file mode 100644 index 000000000..d5bba9347 --- /dev/null +++ b/src/api/public/media/media.controller.ts @@ -0,0 +1,4 @@ +import { Controller } from '@nestjs/common'; + +@Controller('media') +export class MediaController {} diff --git a/src/api/public/monitoring/monitoring.controller.spec.ts b/src/api/public/monitoring/monitoring.controller.spec.ts new file mode 100644 index 000000000..b56e07aa5 --- /dev/null +++ b/src/api/public/monitoring/monitoring.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { MonitoringController } from './monitoring.controller'; + +describe('Monitoring Controller', () => { + let controller: MonitoringController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [MonitoringController], + }).compile(); + + controller = module.get(MonitoringController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/api/public/monitoring/monitoring.controller.ts b/src/api/public/monitoring/monitoring.controller.ts new file mode 100644 index 000000000..1f510cfa9 --- /dev/null +++ b/src/api/public/monitoring/monitoring.controller.ts @@ -0,0 +1,4 @@ +import { Controller } from '@nestjs/common'; + +@Controller('monitoring') +export class MonitoringController {} diff --git a/src/api/public/notes/notes.controller.spec.ts b/src/api/public/notes/notes.controller.spec.ts new file mode 100644 index 000000000..98739ce69 --- /dev/null +++ b/src/api/public/notes/notes.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { NotesController } from './notes.controller'; + +describe('Notes Controller', () => { + let controller: NotesController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [NotesController], + }).compile(); + + controller = module.get(NotesController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts new file mode 100644 index 000000000..aaedacefb --- /dev/null +++ b/src/api/public/notes/notes.controller.ts @@ -0,0 +1,4 @@ +import { Controller } from '@nestjs/common'; + +@Controller('notes') +export class NotesController {} diff --git a/src/api/public/public-api.module.ts b/src/api/public/public-api.module.ts new file mode 100644 index 000000000..bbb55828a --- /dev/null +++ b/src/api/public/public-api.module.ts @@ -0,0 +1,18 @@ +import { Module } from '@nestjs/common'; +import { HistoryModule } from '../../history/history.module'; +import { UsersModule } from '../../users/users.module'; +import { MeController } from './me/me.controller'; +import { NotesController } from './notes/notes.controller'; +import { MediaController } from './media/media.controller'; +import { MonitoringController } from './monitoring/monitoring.controller'; + +@Module({ + imports: [UsersModule, HistoryModule], + controllers: [ + MeController, + NotesController, + MediaController, + MonitoringController, + ], +}) +export class PublicApiModule {}