Skip to content

Commit

Permalink
feat: 루트에서 최근 포커 결과 보기
Browse files Browse the repository at this point in the history
  • Loading branch information
w8385 committed Jan 25, 2024
1 parent e14a4f8 commit 14f375d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getRecentPokerResult() {
return this.appService.getRecentPokerResult();
}
}
7 changes: 6 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { PokerModule } from './poker/poker.module';
import { DatabaseModule } from './database/database.module';

@Module({
imports: [UserModule, PokerModule],
imports: [UserModule, PokerModule, DatabaseModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
21 changes: 21 additions & 0 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Inject, Injectable } from '@nestjs/common';
import { RedisClientType } from 'redis';
import { PokerService } from './poker/poker.service';

@Injectable()
export class AppService {
constructor(
private readonly pokerService: PokerService,
@Inject('REDIS') private readonly redisClient: RedisClientType,
) {}

async getRecentPokerResult() {
const recentPokerId = await this.redisClient.get('recent');
if (!recentPokerId) {
return {
result: '존재하지 않는 포커입니다.',
};
}
return await this.pokerService.calc(recentPokerId);
}
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function bootstrap() {
.addTag('User', '사용자 점수 조회')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('', app, document);
SwaggerModule.setup('api', app, document);
await app.listen(3000);
}

Expand Down
7 changes: 7 additions & 0 deletions src/poker/poker.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ export class PokerController {
async calc(@Param('pokerId') pokerId: string) {
return this.pokerService.calc(pokerId);
}

@Post(':pokerId/recent')
@ApiOperation({ summary: '최근 포커 설정' })
@ApiParam({ name: 'pokerId', description: '포커 id' })
async setRecent(@Param('pokerId') pokerId: string) {
return this.pokerService.setRecent(pokerId);
}
}
1 change: 1 addition & 0 deletions src/poker/poker.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import { HttpModule } from '@nestjs/axios';
imports: [DatabaseModule, HttpModule],
controllers: [PokerController],
providers: [PokerService, UserService],
exports: [PokerService],
})
export class PokerModule {}
5 changes: 5 additions & 0 deletions src/poker/poker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ export class PokerService {

return result;
}

async setRecent(pokerId: string) {
await this.redisClient.set('recent', pokerId);
return { recent: pokerId };
}
}
1 change: 0 additions & 1 deletion src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export class UserService {
}
url = url.concat('id:' + problems[i] + '|');
}
console.log(url);

const response = await this.httpService.axiosRef
.get(url)
Expand Down

0 comments on commit 14f375d

Please sign in to comment.