Skip to content

Commit

Permalink
[Documentation/Feature] Make Swagger clear & Fix GET /vr-video featur…
Browse files Browse the repository at this point in the history
…e's bug (#14)

* chore: fix typo and improve swagger.

* chore: add entity in AppModule.

* feat: make swagger clear and make GET /vr-video/{id}

* feat: add `VrResourcePositon` in `/GET vr-video`'s response
  • Loading branch information
woog2roid committed Apr 27, 2024
1 parent 733e357 commit cb3d9a6
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller, Get, ServiceUnavailableException } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { ConfigService } from '@nestjs/config';

@ApiTags('Root')
@ApiTags('Root (Health Check)')
@Controller('/')
export class AppController {
private AI_SERVER_URL: string;
Expand All @@ -18,7 +18,7 @@ export class AppController {
}

@ApiOperation({ summary: 'AI 헬스체크' })
@Get('/')
@Get('/ai')
async healthCheckAI(): Promise<{ message: string }> {
const response = await fetch(`${this.AI_SERVER_URL}/`);
if (response.status === 200) {
Expand Down
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { VrVideo } from './domain/vr-video/entity/vr-video.entity';
import { VrVideoModule } from './domain/vr-video/vr-video.module';
import { AppController } from './app.controller';
import { SampleModule } from './domain/sample/sample.module';
import { SampleVrResource } from './domain/sample/entity/sample-vr-resource.entity';

@Module({
imports: [
Expand All @@ -34,7 +35,7 @@ import { SampleModule } from './domain/sample/sample.module';
username: configService.get<string>('DB_USERNAME'),
password: configService.get<string>('DB_PASSWORD'),
database: configService.get<string>('DB_DATABASE'),
entities: [User, Group, Badge, VrResource, VrVideo],
entities: [User, Group, Badge, VrResource, VrVideo, SampleVrResource],
migrations: [__dirname + '/src/migrations/*.ts'],
autoLoadEntities: true,
charset: 'utf8mb4',
Expand Down
24 changes: 24 additions & 0 deletions src/domain/group/repository/group.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@ export class GroupRepository extends Repository<Group> {
super(repository.target, repository.manager);
}

async isUserInGroup(userId: string, groupId: string): Promise<boolean> {
// 1. is the user careRecipient?
const isCareRecipient =
(
await this.findOne({
where: { recipient: { id: userId } },
})
)?.id === groupId
? true
: false;

// 2. is the user careGiver?
const isCareGiver =
(
await this.findOne({
where: { givers: { id: userId } },
})
)?.id === groupId
? true
: false;

return isCareRecipient || isCareGiver ? true : false;
}

async findByCareGiverIdWithUsers(giverId: string): Promise<Group> {
return await this.findOne({
where: { givers: { id: giverId } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class VrResourceDto extends PickType(VrResource, [
'createdAt',
] as const) {
@ApiProperty({
description: '인증된 storage URL (10분 간 유효)',
description:
'인증된 storage URL (10분 간 유효), file이 여러 chunk로 나눠져있음.',
example: [
'https://storage.googleapis.com/...',
'https://storage.googleapis.com/...',
Expand Down
24 changes: 20 additions & 4 deletions src/domain/vr-video/dto/request/generate-vr-video.request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { ApiProperty, PickType } from '@nestjs/swagger';
import { VrVideo } from '../../entity/vr-video.entity';
import { ObjectDataType } from '../../type/object-data.type';
import { IsNotEmpty, IsString } from 'class-validator';
import {
ArrayMaxSize,
ArrayMinSize,
IsArray,
IsNotEmpty,
IsString,
ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';

class VrResourceInfo {
@ApiProperty({ description: '리소스 ID', example: '123' })
export class VrResourceInfo {
@ApiProperty({
description: '리소스(아바타, 배경) ID',
example: '123456789012',
})
@IsNotEmpty()
@IsString()
resourceId: string;

@ApiProperty({ description: '리소스 위치 (VR 비디오 내에서의)' })
@ApiProperty({ description: '리소스 위치 (VR 비디오 내에서의 x,y,z위치 등)' })
@IsNotEmpty()
objectData: ObjectDataType;
}
Expand All @@ -26,5 +37,10 @@ export class GenerateVrVideoRequestDto extends PickType(VrVideo, [
type: [VrResourceInfo],
})
@IsNotEmpty()
@IsArray()
@ValidateNested({ each: true })
@ArrayMinSize(1)
@ArrayMaxSize(10)
@Type(() => VrResourceInfo)
avatarsInfo: VrResourceInfo[];
}
52 changes: 45 additions & 7 deletions src/domain/vr-video/dto/response/get-vr-videos.response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
import { ApiProperty, PickType } from '@nestjs/swagger';
import { VrVideo } from '../../entity/vr-video.entity';
import { VrResourceDto } from 'src/domain/vr-resource/dto/response/get-vr-resources.response.dto';
import { VrResource } from 'src/domain/vr-resource/entity/vr-resource.entity';

export class VrResourceDtoForVideo extends PickType(VrResource, [
'id',
'title',
'type',
'createdAt',
] as const) {
// ! storageUrls: vr-resource(아바타) 파일
@ApiProperty({
description: 'vr-resource(아바타) 파일: storage URL (10분 간 유효)',
example: [
'https://storage.googleapis.com/...',
'https://storage.googleapis.com/...',
],
})
storageUrls: string[];

@ApiProperty({
description: 'video내에서 리소스의 포지셔닝을 설명하는 파일의 storage URL',
example: 'https://storage.googleapis.com/...',
})
inVideoPositionFile: string;

static of(
vrResource: VrResource,
storageUrls: string[],
inVideoPositionFile: string,
): VrResourceDtoForVideo {
return {
id: vrResource.id,
title: vrResource.title,
type: vrResource.type,
storageUrls: storageUrls,
inVideoPositionFile: inVideoPositionFile,
createdAt: vrResource.createdAt,
};
}
}

export class GetVrVideosResponseDto extends PickType(VrVideo, [
'title',
] as const) {
@ApiProperty({ type: VrResourceDto })
scene: VrResourceDto;
@ApiProperty({ type: VrResourceDtoForVideo })
scene: VrResourceDtoForVideo;

@ApiProperty({ type: [VrResourceDto] })
avatars: VrResourceDto[];
@ApiProperty({ type: [VrResourceDtoForVideo] })
avatars: VrResourceDtoForVideo[];

constructor(
vrVideo: VrVideo,
scene: VrResourceDto,
avatars: VrResourceDto[],
scene: VrResourceDtoForVideo,
avatars: VrResourceDtoForVideo[],
) {
super(vrVideo, ['title', 'scene', 'avatars']);
this.scene = scene;
Expand Down
9 changes: 9 additions & 0 deletions src/domain/vr-video/repository/vr-video.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Injectable } from '@nestjs/common';
import { VrVideo } from '../entity/vr-video.entity';
import { VrResource } from 'src/domain/vr-resource/entity/vr-resource.entity';
import { Group } from 'src/domain/group/entity/group.entity';

@Injectable()
export class VrVideoRepository extends Repository<VrVideo> {
Expand All @@ -18,4 +20,11 @@ export class VrVideoRepository extends Repository<VrVideo> {
relations: ['scene', 'avatars'],
});
}

async findById(videoId: string): Promise<VrVideo> {
return this.repository.findOne({
where: { id: videoId },
relations: ['scene', 'avatars'],
});
}
}
Loading

0 comments on commit cb3d9a6

Please sign in to comment.