Skip to content

Commit 28c8b1f

Browse files
authored
Merge pull request #122 from ChooseTale/fix/create-game
Fix/create game
2 parents d55b101 + c69e4a3 commit 28c8b1f

File tree

14 files changed

+77
-70
lines changed

14 files changed

+77
-70
lines changed

local.docker-compose.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,3 @@ services:
3434
environment:
3535
ZOOKEEPER_CLIENT_PORT: 2181
3636
ZOOKEEPER_TICK_TIME: 2000
37-
38-
server:
39-
build:
40-
context: .
41-
dockerfile: dev.dockerfile
42-
ports:
43-
- '5001:5001'
44-
- '5002:5002'
45-
depends_on:
46-
- db
47-
- kafka
48-
- zookeeper
49-
command: ['sh', '-c', 'yarn prisma migrate dev && yarn dev:docker']

src/common/chat-gpt/chatgpt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class ChatGPT implements IChatGPTPagePort {
9696
},
9797
],
9898
});
99-
99+
console.log(promptGPT.choices[0].message.content);
100100
if (promptGPT.choices[0].message.content === 'error') {
101101
return '';
102102
}
@@ -107,7 +107,7 @@ export class ChatGPT implements IChatGPTPagePort {
107107
n: 1,
108108
size: '1024x1024',
109109
});
110-
110+
console.log(imageResponse.data[0].url);
111111
const response = await axios.get(imageResponse.data[0].url ?? '', {
112112
responseType: 'stream',
113113
});

src/game-builder/choice/infrastructure/repositories/choice.repository.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,6 @@ export class ChoiceRepository implements IChoiceRepository {
7373
): Promise<ChoiceDomainEntity> {
7474
try {
7575
// 페이지 버전 업데이트
76-
const updatedPage = await (transaction ?? this.prisma).page.update({
77-
data: {
78-
version: {
79-
increment: 1,
80-
},
81-
},
82-
where: {
83-
id: createChoiceReqDto.parentPageId,
84-
version: fromPageVersion,
85-
},
86-
});
87-
88-
if (!updatedPage) {
89-
throw new ConflictException('페이지가 업데이트 되지 않음.');
90-
}
9176

9277
// 선택지 생성
9378
await (transaction ?? this.prisma).choicePage.create({
@@ -118,6 +103,7 @@ export class ChoiceRepository implements IChoiceRepository {
118103

119104
return toDomain(createdFromPage);
120105
} catch (err) {
106+
console.log(err);
121107
throw new BadRequestException(`선택지 생성 실패`);
122108
}
123109
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export class GetRecommentImageDto {
2-
imageId: number;
32
url: string;
43
}

src/game-builder/game/application/controllers/game.controller.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { GetDataGameResDto } from './dto/get-data-game.dto';
3232
import { AuthSerializeGuard } from '@@src/common/guard/auth.serielize.guard';
3333
import { IsMyGameGuard } from '@@src/game-builder/guard/is-my-game.guard';
3434
import { PublishGameUsecase } from '../usecases/publish.usecase';
35+
import { Genres } from '@prisma/client';
3536

3637
@Controller('game')
3738
@UseGuards(AuthSerializeGuard)
@@ -198,11 +199,14 @@ export class GameController {
198199
* @summary 🟡(240726) 게임 추천 썸네일 이미지 생성
199200
*/
200201
@Post(':gameId/recommend-image')
201-
@UseGuards(IsMyGameGuard)
202202
async recommendImage(
203203
@Param('gameId', ParseIntPipe) gameId: number,
204+
@Body() body: { title: string; description: string; genre: Genres },
204205
): Promise<GetRecommentImageDto> {
205-
return await this.getRecommandImageUseCase.execute(gameId);
206+
return {
207+
url: 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-XyZTnjNifxUU5reDbdFFMkGG/user-7T71nvcI6lYXV6RIPeFEKyLz/img-UTKIe4S0m7qjfMBg6MnUo4n2.png?st=2025-02-24T11%3A17%3A25Z&se=2025-02-24T13%3A17%3A25Z&sp=r&sv=2024-08-04&sr=b&rscd=inline&rsct=image/png&skoid=d505667d-d6c1-4a0a-bac7-5c84a87759f8&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2025-02-24T05%3A52%3A53Z&ske=2025-02-25T05%3A52%3A53Z&sks=b&skv=2024-08-04&sig=T5ODHUJygh1ZlMYVfSDo4WPUBDglVY2qUHpMfa5Y9T8%3D',
208+
};
209+
// return await this.getRecommandImageUseCase.execute(body);
206210
}
207211

208212
/**

src/game-builder/game/application/usecases/get-recommand-image.usecase.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IChatGPTPagePort } from '@@src/game-builder/page/domain/ports/output/ch
33
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
44
import { IGameService } from '../../domain/ports/input/game.service.interface';
55
import { IImageService } from '@@src/game-builder/images/domain/port/input/image.service.interface';
6+
import { Genres } from '@prisma/client';
67

78
@Injectable()
89
export class GetRecommandImageUseCase {
@@ -17,37 +18,19 @@ export class GetRecommandImageUseCase {
1718
private readonly imageService: IImageService,
1819
) {}
1920

20-
async execute(gameId: number) {
21-
const game = await this.gameService.getById(gameId);
22-
const startingPage = await this.pagePort.getStartingPage(gameId);
23-
if (!game) {
24-
throw new Error('Game not found');
25-
}
26-
if (!startingPage) {
27-
throw new Error('Starting page not found');
28-
}
21+
async execute(body: { title: string; description: string; genre: Genres }) {
2922
const image = await this.chatGPT.getThumbnailImage(
30-
game.title,
31-
game.description,
32-
game.genre,
23+
body.title,
24+
body.description,
25+
body.genre,
3326
);
3427

3528
if (image === '') {
3629
throw new BadRequestException('이미지 생성에 실패했습니다.');
3730
}
3831

39-
const newImage = await this.imageService.uploadImageForGameThumbnail(
40-
gameId,
41-
[{ url: image }],
42-
);
43-
44-
if (newImage.length > 1) {
45-
throw new Error('Too many images');
46-
}
47-
4832
return {
49-
imageId: newImage[0].id,
50-
url: newImage[0].url,
33+
url: image,
5134
};
5235
}
5336
}

src/game-builder/game/application/usecases/mapper/to-get-all-res.mapper.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ export const toGetAllResMapper = (
6262

6363
// 선택지가 연결되지 않은 페이지
6464
// parentId와 childId가 모두 존재하지 않는 페이지
65-
const unconnectedPages = pages.filter((page) =>
66-
choices.every(
67-
(choice) =>
68-
choice.parentPageId !== page.id && choice.childPageId !== page.id,
69-
),
65+
const unconnectedPages = pages.filter(
66+
(page) => !result.some((r) => r.id === page.id),
7067
);
7168

7269
for (const page of unconnectedPages) {
@@ -82,7 +79,7 @@ export const toGetAllResMapper = (
8279
isStarting: page.isStarting,
8380
isEnding: page.isEnding,
8481
depth: -1,
85-
choices: [],
82+
choices: resChoices.filter((choice) => choice.fromPageId === page.id),
8683
fromPageIds: [],
8784
});
8885
}

src/game-builder/game/application/usecases/publish.usecase.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ export class PublishGameUsecase {
3636

3737
const trees = toGetAllResMapper(game, pages, choices);
3838

39+
let endingCount = 0;
40+
3941
for (const page of trees.pages) {
42+
if (page.isEnding && page.depth !== -1) {
43+
endingCount++;
44+
}
45+
4046
const notExistLinkChoice = page.choices.filter(
4147
(choice) => !choice.toPageId,
4248
);
@@ -57,8 +63,8 @@ export class PublishGameUsecase {
5763
);
5864

5965
await Promise.all(
60-
unConnectedPages.map((page) => {
61-
this.pageService.delete(page.id, transaction);
66+
unConnectedPages.map(async (page) => {
67+
await this.pageService.delete(page.id, transaction);
6268
}),
6369
);
6470

@@ -70,6 +76,10 @@ export class PublishGameUsecase {
7076
throw new ConflictException('썸네일 이미지가 없습니다.');
7177
}
7278

79+
if (endingCount === 0) {
80+
throw new ConflictException('연결된 엔딩 페이지가 존재하지 않습니다.');
81+
}
82+
7383
await this.gameService.update(
7484
gameId,
7585
game.userId,

src/my-page/game-builder/domain/entities/get-my-builded-games.entity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class GetMyBuildedGamesEntity {
3131
if (!startingPage) {
3232
throw new ConflictException('Starting page not found');
3333
}
34+
3435
return {
3536
id: game.id,
3637
title: game.title,

src/my-page/game-builder/domain/services/query/get-my-builded-game.query.service.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
import { Genres, Prisma } from '@prisma/client';
22

33
export type GetMyBuildedGameInclude = {
4-
Page: true;
4+
Page: {
5+
where: {
6+
deletedAt: null;
7+
};
8+
};
59
thumbnail: true;
6-
ChoicePage: true;
7-
PlayGame: true;
10+
ChoicePage: {
11+
where: {
12+
deletedAt: null;
13+
};
14+
};
15+
PlayGame: {
16+
where: {
17+
deletedAt: null;
18+
};
19+
};
820
};
921

1022
export class GetMyBuildedGameQueryService {
1123
private query: Prisma.GameFindManyArgs = { where: {}, include: {} };
1224
constructor(userId: number) {
1325
const include: GetMyBuildedGameInclude = {
14-
Page: true,
26+
Page: {
27+
where: {
28+
deletedAt: null,
29+
},
30+
},
1531
thumbnail: true,
16-
ChoicePage: true,
17-
PlayGame: true,
32+
ChoicePage: {
33+
where: {
34+
deletedAt: null,
35+
},
36+
},
37+
PlayGame: {
38+
where: { deletedAt: null },
39+
},
1840
};
1941
this.query.where = {
2042
userId,

0 commit comments

Comments
 (0)