Skip to content

Commit

Permalink
merge #251: 타임라인 상세 내용 Papago API로 번역
Browse files Browse the repository at this point in the history
[feat] 타임라인 상세 내용 Papago API로 번역
  • Loading branch information
yaongmeow authored Dec 5, 2023
2 parents 185e944 + 9565ab7 commit 7218923
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
docker pull traveline/traveline-docker
docker stop traveline-container || true
docker rm traveline-container || true
docker run -e DB_HOST=${{ secrets.DB_HOST }} -e DB_PORT=${{ secrets.DB_PORT }} -e DB_USER=${{ secrets.DB_USER }} -e DB_PASSWORD=${{ secrets.DB_PASSWORD }} -e DB_DATABASE=${{ secrets.DB_DATABASE }} -e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} -e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} -e AWS_REGION=${{ secrets.AWS_REGION }} -e JWT_SECRET_ACCESS=${{ secrets.JWT_SECRET_ACCESS }} -e JWT_SECRET_REFRESH=${{ secrets.JWT_SECRET_REFRESH }} -e CLIENT_ID=${{ secrets.CLIENT_ID }} -e TEAM_ID=${{ secrets.TEAM_ID }} -e KEY_ID=${{ secrets.KEY_ID }} -e AUTH_KEY_LINE1=${{ secrets.AUTH_KEY_LINE1 }} -e AUTH_KEY_LINE2=${{ secrets.AUTH_KEY_LINE2 }} -e AUTH_KEY_LINE3=${{ secrets.AUTH_KEY_LINE3 }} -e AUTH_KEY_LINE4=${{ secrets.AUTH_KEY_LINE4 }} -e KAKAO_REST_API_KEY=${{ secrets.KAKAO_REST_API_KEY }} -d -p ${{secrets.EXTERNAL_PORT}}:${{secrets.INTERNAL_PORT}} --name traveline-container traveline/traveline-docker
docker run -e DB_HOST=${{ secrets.DB_HOST }} -e DB_PORT=${{ secrets.DB_PORT }} -e DB_USER=${{ secrets.DB_USER }} -e DB_PASSWORD=${{ secrets.DB_PASSWORD }} -e DB_DATABASE=${{ secrets.DB_DATABASE }} -e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} -e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} -e AWS_REGION=${{ secrets.AWS_REGION }} -e JWT_SECRET_ACCESS=${{ secrets.JWT_SECRET_ACCESS }} -e JWT_SECRET_REFRESH=${{ secrets.JWT_SECRET_REFRESH }} -e CLIENT_ID=${{ secrets.CLIENT_ID }} -e TEAM_ID=${{ secrets.TEAM_ID }} -e KEY_ID=${{ secrets.KEY_ID }} -e AUTH_KEY_LINE1=${{ secrets.AUTH_KEY_LINE1 }} -e AUTH_KEY_LINE2=${{ secrets.AUTH_KEY_LINE2 }} -e AUTH_KEY_LINE3=${{ secrets.AUTH_KEY_LINE3 }} -e AUTH_KEY_LINE4=${{ secrets.AUTH_KEY_LINE4 }} -e KAKAO_REST_API_KEY=${{ secrets.KAKAO_REST_API_KEY }} -e X_NCP_APIGW_API_KEY_ID=${{ secrets.X_NCP_APIGW_API_KEY_ID }} -e X_NCP_APIGW_API_KEY=${{ secrets.X_NCP_APIGW_API_KEY }} -d -p ${{secrets.EXTERNAL_PORT}}:${{secrets.INTERNAL_PORT}} --name traveline-container traveline/traveline-docker
12 changes: 12 additions & 0 deletions BE/src/timelines/timelines.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
findCoordinates_OK,
findOne_OK,
remove_OK,
translate_OK,
update_OK,
} from './timelines.swagger';

Expand Down Expand Up @@ -176,4 +177,15 @@ export class TimelinesController {
async remove(@Param('id', ParseUUIDPipe) id: string): Promise<Timeline> {
return this.timelinesService.remove(id);
}

@Get(':id/translate')
@ApiOperation({
summary: 'Papago API 번역',
description:
'Papago API를 사용하여 타임라인 세부 내용을 영어로 번역하고, 그 결과를 반환합니다.',
})
@ApiOkResponse({ schema: { example: translate_OK } })
async translate(@Param('id', ParseUUIDPipe) id: string) {
return this.timelinesService.translate(id);
}
}
25 changes: 25 additions & 0 deletions BE/src/timelines/timelines.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,31 @@ export class TimelinesService {
return documents;
}

async translate(id: string) {
const { description } = await this.findOne(id);
const url = 'https://naveropenapi.apigw.ntruss.com/nmt/v1/translation';
const body = {
source: 'ko',
target: 'en',
text: description,
};
const {
data: {
message: { result },
},
} = await firstValueFrom(
this.httpService.post(url, body, {
headers: {
'Content-Type': 'application/json',
'X-NCP-APIGW-API-KEY-ID': process.env.X_NCP_APIGW_API_KEY_ID,
'X-NCP-APIGW-API-KEY': process.env.X_NCP_APIGW_API_KEY,
},
})
);

return { description: result.translatedText };
}

private async findOneAndUpdateThumbnail(postingId: string) {
const result =
await this.timelinesRepository.findOneWithNonEmptyImage(postingId);
Expand Down
5 changes: 5 additions & 0 deletions BE/src/timelines/timelines.swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,8 @@ export const findCoordinates_OK = [
y: '37.553341424711675',
},
];

export const translate_OK = {
description:
"Seongsimdang is a bakery located in Daejeon Metropolitan City. It is famous for fried Soboro or chives bread, and is famous for making Pope Francis' meal bread during Pope Francis' visit to Korea in 2014. Along with Gunsan Yi Seongdang, Seoul Napoleon, Jeonju PNB Pungnyeon Confectionery, and Busan B&C, it is also considered one of the top five bakeries in Korea.[1] There are five stores, including Euneungjeongi, Daejeon Station, Daejeon Convention Center, Lotte Department Store, and Daejeon Branch, but they do not open stores other than Daejeon. Sungsimdang, which operated the KTX express service and was available in other regions, ended its operation of the KTX express baggage center on December 25, 2022.",
};

0 comments on commit 7218923

Please sign in to comment.