Skip to content

Commit

Permalink
✨ feat: 신규 라우트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kms0219kms committed Dec 15, 2024
1 parent 707efd4 commit 211b527
Show file tree
Hide file tree
Showing 38 changed files with 1,644 additions and 1,344 deletions.
62 changes: 23 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,42 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"dependencies": {
"@fastify/static": "^7.0.0",
"@nestjs/axios": "^3.0.3",
"@nestjs/cache-manager": "^2.2.2",
"@nestjs/common": "^10.4.4",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.4.4",
"@fastify/static": "^7.0.4",
"@keyv/redis": "^4.1.0",
"@nestjs/axios": "^3.1.3",
"@nestjs/cache-manager": "3.0.0-next.0",
"@nestjs/common": "^10.4.15",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.4.15",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-fastify": "^10.4.4",
"@nestjs/swagger": "^7.4.2",
"axios": "^1.7.7",
"cache-manager": "^5.7.6",
"cache-manager-redis-yet": "^5.1.5",
"fastify": "^5.0.0",
"mongoose": "^8.6.4",
"@nestjs/platform-fastify": "^10.4.15",
"@nestjs/swagger": "^8.1.0",
"axios": "^1.7.9",
"cache-manager": "^6.3.1",
"fastify": "^4.28.1",
"keyv": "^5.2.2",
"mongoose": "^8.9.0",
"nestjs-redox": "^1.2.2",
"redoc": "^2.1.5",
"redoc": "^2.2.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.4.5",
"@nestjs/schematics": "^10.1.4",
"@types/node": "^22.7.3",
"@typescript-eslint/eslint-plugin": "^8.7.0",
"@typescript-eslint/parser": "^8.7.0",
"eslint": "^8.57.1",
"@nestjs/cli": "^10.4.9",
"@nestjs/schematics": "^10.2.3",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.2"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"typescript": "^5.7.2"
},
"packageManager": "[email protected]+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b"
}
2,402 changes: 1,205 additions & 1,197 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger';

class rootAccessDto {
class RootAccessDto {
/**
* Default return
* @example hacking
Expand All @@ -18,7 +18,7 @@ export class AppController {
summary: 'Health Check',
description: 'Check the server is running',
})
rootAccess(): rootAccessDto {
rootAccess(): RootAccessDto {
return { happy: 'hacking' };
}
}
15 changes: 9 additions & 6 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { CacheModule } from '@nestjs/cache-manager';

import { redisStore } from 'cache-manager-redis-yet';
import { createKeyv } from '@keyv/redis';

import { AppController } from './app.controller';
import { RepositoryModule } from './common/repository/repository.module';
Expand All @@ -14,6 +14,7 @@ import { ChartsModule } from './charts/charts.module';
import { LyricsModule } from './lyrics/lyrics.module';
import { MypageModule } from './mypage/mypage.module';
import { SongsModule } from './songs/songs.module';
import { BannersModule } from './banners/banners.module';

@Module({
imports: [
Expand All @@ -22,11 +23,12 @@ import { SongsModule } from './songs/songs.module';
envFilePath: ['.env.development', '.env'],
}),
process.env.ENABLE_REDIS === '1'
? CacheModule.register({
? CacheModule.registerAsync({
useFactory: async (configService: ConfigService) => ({
stores: [createKeyv(configService.getOrThrow('REDIS_URI'))],
}),
inject: [ConfigService],
isGlobal: true,

store: redisStore,
url: process.env.REDIS_URI,
})
: CacheModule.register({
isGlobal: true,
Expand All @@ -40,6 +42,7 @@ import { SongsModule } from './songs/songs.module';
SongsModule,
RepositoryModule,
AppModule,
BannersModule,
],
controllers: [AppController],
})
Expand Down
8 changes: 4 additions & 4 deletions src/artist/artist.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';

import { ArtistService } from './artist.service';

import { artistDto } from './dto/artist.dto';
import { artistSearchDto } from './dto/artistSearch.dto';
import { ArtistDto } from './dto/artist.dto';
import { ArtistSearchDto } from './dto/artistSearch.dto';

@ApiTags('Music - Artist Information')
@Controller('artist')
Expand All @@ -18,7 +18,7 @@ export class ArtistController {
summary: '아티스트 리스트 확인',
description: '왁타플레이에 등록된 아티스트 리스트를 확인합니다.',
})
async getArtistList(): Promise<artistDto[]> {
async getArtistList(): Promise<ArtistDto[]> {
return await this.artistService.getArtistList();
}

Expand All @@ -41,7 +41,7 @@ export class ArtistController {
@Param('id') id: string,
@Query('page') page: string = '1',
@Query('size') size: string = '20',
): Promise<artistSearchDto> {
): Promise<ArtistSearchDto> {
return await this.artistService.getOneArtist(
id,
parseInt(page, 10),
Expand Down
8 changes: 4 additions & 4 deletions src/artist/artist.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { IMusic } from 'src/common/repository/schemas/music.schema';

import { APIException } from 'src/common/dto/APIException.dto';

import { artistDto } from './dto/artist.dto';
import { artistSearchDto } from './dto/artistSearch.dto';
import { ArtistDto } from './dto/artist.dto';
import { ArtistSearchDto } from './dto/artistSearch.dto';

@Injectable()
export class ArtistService {
Expand All @@ -20,7 +20,7 @@ export class ArtistService {
private readonly musicModel: Model<IMusic>,
) {}

async getArtistList(): Promise<artistDto[]> {
async getArtistList(): Promise<ArtistDto[]> {
try {
return this.artistModel.find().select('-_id -__v');
} catch (e) {
Expand All @@ -33,7 +33,7 @@ export class ArtistService {
id: string,
page: number = 1,
size: number = 20,
): Promise<artistSearchDto> {
): Promise<ArtistSearchDto> {
try {
const searchQuery = {};
searchQuery[`artist.${id}`] = true;
Expand Down
31 changes: 22 additions & 9 deletions src/artist/dto/artist.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IArtist } from 'src/common/repository/schemas/artist.schema';

export class artistDto implements IArtist {
export class ArtistDto implements IArtist {
/**
* 아티스트 고유 ID (보통 영문명 소문자)
* @example 'viichan'
Expand All @@ -13,6 +13,17 @@ export class artistDto implements IArtist {
*/
name: string;

/**
* 아티스트 설명
*/
description: string;

/**
* 아티스트 소속 그룹 고유 ID
* @example 'isedol'
*/
group: string;

/**
* 아티스트 영문명
* @example 'VIichan'
Expand All @@ -25,12 +36,6 @@ export class artistDto implements IArtist {
*/
shortName: string;

/**
* 아티스트 소속 그룹 고유 ID
* @example 'isedol'
*/
group: string;

/**
* 아티스트 대표 색상
* @example '85AC20'
Expand All @@ -44,10 +49,10 @@ export class artistDto implements IArtist {
twitch?: string;

/**
* 아티스트 아프리카 ID (NEW)
* 아티스트 숲 BJ ID
* @example 'viichan6'
*/
afreecatv?: string;
soop?: string;

/**
* 아티스트 유튜브 ID
Expand All @@ -60,4 +65,12 @@ export class artistDto implements IArtist {
* @example 'viichan6'
*/
instagram?: string;

/**
* 아티스트 트위터 ID
* @example 'viichan6'
*/
twitter?: string;
}

export default ArtistDto;
12 changes: 6 additions & 6 deletions src/artist/dto/artistSearch.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { artistDto } from './artist.dto';
import { musicDto } from 'src/songs/dto/music.dto';
import { ArtistDto } from './artist.dto';
import { MusicDto } from 'src/songs/dto/music.dto';

export class artistSearchDto {
artist: artistDto;
export class ArtistSearchDto {
artist: ArtistDto;
music: {
page: number;
count: number;
hasNext: boolean;
data: musicDto[];
data: MusicDto[];
};
}

export default artistSearchDto;
export default ArtistSearchDto;
12 changes: 6 additions & 6 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { ApiOperation, ApiTags } from '@nestjs/swagger';

import { AuthService } from './auth.service';

import { authCallbackDto } from './dto/authCallback.dto';
import { authCallbackRequestDto } from './dto/authCallbackRequest.dto';
import { authRefreshRequestDto } from './dto/authRefreshRequest.dto';
import { AuthCallbackDto } from './dto/authCallback.dto';
import { AuthCallbackRequestDto } from './dto/authCallbackRequest.dto';
import { AuthRefreshRequestDto } from './dto/authRefreshRequest.dto';

@ApiTags('Common - Authentication API')
@Controller('auth')
Expand All @@ -27,8 +27,8 @@ export class AuthController {
description: 'SpaceWak OAuth2를 통한 Access Token 발급 요청',
})
async callback(
@Body() body: authCallbackRequestDto,
): Promise<authCallbackDto> {
@Body() body: AuthCallbackRequestDto,
): Promise<AuthCallbackDto> {
try {
return await this.authService.callback(body.code);
} catch (e) {
Expand All @@ -44,7 +44,7 @@ export class AuthController {
summary: 'Access Token 갱신',
description: 'SpaceWak OAuth2를 통한 Access Token 갱신 요청',
})
async refresh(@Body() body: authRefreshRequestDto): Promise<authCallbackDto> {
async refresh(@Body() body: AuthRefreshRequestDto): Promise<AuthCallbackDto> {
try {
return await this.authService.refreshToken(body.refresh_token);
} catch (e) {
Expand Down
10 changes: 5 additions & 5 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HttpStatus, Injectable, Logger } from '@nestjs/common';
import { catchError, firstValueFrom } from 'rxjs';
import { AxiosError } from 'axios';

import { authCallbackDto } from './dto/authCallback.dto';
import { AuthCallbackDto } from './dto/authCallback.dto';
import { APIException } from 'src/common/dto/APIException.dto';

@Injectable()
Expand All @@ -13,7 +13,7 @@ export class AuthService {

constructor(private readonly httpService: HttpService) {}

async callback(code: string): Promise<authCallbackDto> {
async callback(code: string): Promise<AuthCallbackDto> {
const params = new URLSearchParams({
code: code,
grant_type: 'authorization_code',
Expand All @@ -23,7 +23,7 @@ export class AuthService {
return await this.getToken(params);
}

async refreshToken(refreshToken: string): Promise<authCallbackDto> {
async refreshToken(refreshToken: string): Promise<AuthCallbackDto> {
const params = new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: refreshToken,
Expand All @@ -32,10 +32,10 @@ export class AuthService {
return await this.getToken(params);
}

async getToken(params: URLSearchParams): Promise<authCallbackDto> {
async getToken(params: URLSearchParams): Promise<AuthCallbackDto> {
const { data } = await firstValueFrom(
this.httpService
.post<authCallbackDto>(
.post<AuthCallbackDto>(
'https://auth.spacewak.net/oauth2/token',
params,
{
Expand Down
4 changes: 2 additions & 2 deletions src/auth/dto/authCallback.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class authCallbackDto {
export class AuthCallbackDto {
/**
* Access Token
* @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMDQ1NjcwNTg1OTcyMDAzMDQwNzYiLCJlbWFpbCI6ImttczAyMTlrbXNAZ21haWwuY29tIiwicHJvdmlkZXIiOiJnb29nbGUiLCJlbmNEYXRhIjoiOWQzNzA4NmNlNDJlMjJkOTgwYjE1OGZlNWI5NzFiMmMxYzFiMjA1YmRhY2IxODEyNzZhZmEwZDY1YmMxMDU5NyIsImlhdCI6MTcwNjg5MTU3OX0.kufYCcO-kZELot9QM4kyD8imjOeGdXnJfC9mAHRqNws
Expand All @@ -24,4 +24,4 @@ export class authCallbackDto {
token_type: string;
}

export default authCallbackDto;
export default AuthCallbackDto;
4 changes: 2 additions & 2 deletions src/auth/dto/authCallbackRequest.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export class authCallbackRequestDto {
export class AuthCallbackRequestDto {
/**
* SpaceWak OAuth2에서 발급한 authorization code
* @example 8FZGv8vxfOFvaRV9SO6el
*/
code: string;
}

export default authCallbackRequestDto;
export default AuthCallbackRequestDto;
4 changes: 2 additions & 2 deletions src/auth/dto/authRefreshRequest.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export class authRefreshRequestDto {
export class AuthRefreshRequestDto {
/**
* SpaceWak OAuth2에서 발급된 refresh token
* @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMDQ1NjcwNTg1OTcyMDAzMDQwNzYiLCJpYXQiOjE3MDY4OTE1NzksImV4cCI6MTcwOTQ4MzU3OX0.j0fhOuROu2sNzUhiXeoimC6HR3Rf0d7pjZueGeVFXwI
*/
refresh_token: string;
}

export default authRefreshRequestDto;
export default AuthRefreshRequestDto;
Loading

0 comments on commit 211b527

Please sign in to comment.