Skip to content

Commit 9ef51cc

Browse files
committed
Merge branch 'main' of github.com:UMC-AlbaLog/Node.JS
2 parents 355de8a + 02b3e05 commit 9ef51cc

9 files changed

Lines changed: 74 additions & 44 deletions

src/DTO/alba_application_dto.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export interface AlbaDetailResponseDto{
1818
}
1919

2020
export interface AlbaApplyRequestDto{
21-
albaId:string,
22-
userId:string
21+
albaId:string
2322
}
2423
export interface AlbaApplyResponseDto{
2524
albaId:string,

src/DTO/store_review_dto.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface StoreReviewRequestDto{
2-
userId:string,
32
storeId:string,
43
kindness:number,
54
communication:number,

src/controller/alba_application_controller.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Tags, Route,SuccessResponse,Response, Get, Path, Controller, Post, Body} from 'tsoa';
1+
import { Tags, Route,SuccessResponse,Response, Get, Path, Controller, Post, Body, Security,Request} from 'tsoa';
2+
import { Request as ExpressRequest } from 'express';
23
import { AlbaApplyRequestDto, AlbaApplyResponseDto, AlbaDetailResponseDto } from '../DTO/alba_application_dto';
34
import { getAlbaDetail,postAlbaApplication } from '../service/alba_application_service';
5+
import { uuidToBuffer } from '../util/uuid_util';
46

57
@Route('api/alba/application')
68
@Tags('Alba Application')
@@ -9,10 +11,11 @@ export class AlbaApplicationController extends Controller{
911
* 대타 아르바이트 정보 상세 조회 API
1012
* @params albaId
1113
*/
14+
@Get('{albaId}')
1215
@SuccessResponse('200','조회 성공')
1316
@Response('404','Not Found')
1417
@Response('500','Internal Server Error')
15-
@Get('{albaId}')
18+
1619

1720
public async fetchAlbaDetail(
1821
@Path() albaId:string
@@ -27,15 +30,26 @@ export class AlbaApplicationController extends Controller{
2730
* @param requestBody (albaId,userId)
2831
* @returns 지원 정보와 정산 상태, 승인 여부(초기에는 전부 waiting으로 설정)
2932
*/
33+
@Post('')
34+
@Security('jwt')
3035
@SuccessResponse('201','생성 성공')
36+
@Response('401','Unauthorized')
3137
@Response('404','Not Found')
3238
@Response('500','Internal Server Error')
33-
@Post('')
39+
3440
public async applyAlba(
41+
@Request() req:ExpressRequest,
3542
@Body() requestBody:AlbaApplyRequestDto
3643
):Promise<AlbaApplyResponseDto>{
44+
//UUID 문자열 Buffer로 변환
45+
const userId = (req.user as unknown as { id: string }).id;
46+
const userBuffer=Buffer.from(uuidToBuffer(userId))
47+
48+
const albaBuffer=Buffer.from(uuidToBuffer(requestBody.albaId))
49+
50+
3751
//대타 아르바이트 지원
38-
const result = await postAlbaApplication(requestBody)
52+
const result = await postAlbaApplication(userBuffer,albaBuffer)
3953
this.setStatus(201)
4054
return result
4155

src/controller/alba_status_controller.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
import {Get, Tags, Route, Query,SuccessResponse,Response, Path} from 'tsoa';
1+
import {Get, Tags, Route, Query,SuccessResponse,Response, Request, Security} from 'tsoa';
2+
import { Request as ExpressRequest } from 'express';
23
import { fetchAlbaStatus } from '../service/alba_status_service';
34
import { AlbaStatusDTO } from '../DTO/alba_status_dto';
45
import { TsoaSuccessResponse } from '../config/response_interface';
5-
@Route('api/alba_status')
6+
import { uuidToBuffer } from '../util/uuid_util';
7+
@Route('api/alba')
68
@Tags('Alba Status')
79
export class AlbaController{
810
/**
911
* 아르바이트지원 현황 조회 API
1012
* @param type 전체(all), 진행중(active), 모집완료(closed)
1113
* @returns 지원 현황 리스트 응답
1214
*/
13-
@Get('{userId}')
15+
@Get('/status')
16+
@Security('jwt')
1417
@SuccessResponse('200','리스트 조회 성공')
15-
@Response('404','User Not Found')
16-
@Response('500','Interval Server Error')
18+
@Response('401','Unauthorized')
19+
@Response('500','Internal Server Error')
1720

1821
public async getAlbaStatus(
19-
@Path() userId:string,
22+
@Request() req:ExpressRequest,
2023
@Query() type: 'all'|'active'|'closed'='all'
2124
): Promise<TsoaSuccessResponse<AlbaStatusDTO[]>>
2225
{
2326
//UUID 문자열 Buffer로 변환
24-
const userBuffer=Buffer.from(userId.replace(/-/g,''),'hex')
27+
const userId = (req.user as unknown as { id: string }).id;
28+
const userBuffer=Buffer.from(uuidToBuffer(userId))
29+
2530
const result=await fetchAlbaStatus(userBuffer,type);
2631
return new TsoaSuccessResponse(result);
2732
}

src/controller/store_review_controller.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Tags, Route,SuccessResponse,Response, Post, Body, Controller} from 'tsoa';
1+
import { Tags, Route,SuccessResponse,Response,Request, Post, Body, Controller, Security} from 'tsoa';
2+
import { Request as ExpressRequest } from 'express';
23
import {StoreReviewRequestDto,StoreReviewResponseDto} from '../DTO/store_review_dto'
34
import { addReview } from '../service/store_review_service';
5+
import { uuidToBuffer } from '../util/uuid_util';
46

57
/**
68
* 사용자가 평가하는 가게 리뷰 API
@@ -14,14 +16,19 @@ export class StoreReviewController extends Controller{
1416
* @returns 생성된 리뷰 정보 + 가게,유저명 반환
1517
*/
1618
@Post()
19+
@Security('jwt')
1720
@SuccessResponse('201','Created')
1821
@Response('400','Bad Request')
1922
@Response('500','Internal Server Error')
2023

2124
public async createStoreReview(
25+
@Request() req: ExpressRequest,
2226
@Body() requestBody:StoreReviewRequestDto
2327
): Promise<StoreReviewResponseDto>{
24-
const result = await addReview(requestBody);
28+
const userId = (req.user as unknown as { id: string }).id;
29+
const userBuffer=Buffer.from(uuidToBuffer(userId))
30+
31+
const result = await addReview(userBuffer,requestBody);
2532
this.setStatus(201);
2633
return result;
2734
}

src/repository/alba_application_repository.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,14 @@ export const findAlbaDetail = async (albaId:string)=>{
6060

6161
/**
6262
* 대타 아르바이트 지원 기능
63-
* @param data(albaId,userId)
63+
* @param data(albaBuffer,userBuffer)
6464
*/
65-
export const applyAlba= async(albaId:string,userId:string) =>{
66-
//Id Buffer로 변환
67-
const userBuffer=Buffer.from(userId.replace(/-/g,""),'hex');
68-
const albaBuffer = Buffer.from(albaId.replace(/-/g,""),'hex');
65+
export const applyAlba= async(userBuffer:Buffer,albaBuffer:Buffer) =>{
6966

7067
const result = await prisma.user_alba.create({
7168
data:{
72-
user_id:userBuffer,
73-
alba_id:albaBuffer,
69+
user_id:new Uint8Array(userBuffer),
70+
alba_id:new Uint8Array(albaBuffer),
7471
//승인이 아니므로 초기에는 waiting으로 설정
7572
process_status:'waiting',
7673
settlement_status:'waiting'

src/repository/store_review_repository.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import { StoreReviewRequestDto } from "../DTO/store_review_dto";
66
* @param data
77
* @returns 리뷰 상세 정보 및 연관 데이터
88
*/
9-
export const createStoreReview = async (data:StoreReviewRequestDto) =>{
10-
const {userId,storeId,communication,settlement,rest,kindness,review} =data;
11-
//UUID 문자열 Buffer로 변환
12-
const userBuffer=Buffer.from(userId.replace(/-/g, ""), 'hex');
13-
const storeBuffer=Buffer.from(storeId.replace(/-/g, ""), 'hex');
9+
export const createStoreReview = async (userBuffer:Buffer,storeBuffer:Buffer,data:StoreReviewRequestDto) =>{
10+
const {communication,settlement,rest,kindness,review} =data;
11+
1412
//4가지 평가지표의 평균. 표현은 소수점 첫째자리까지
1513
const totalScore = Number(((communication+kindness+settlement+rest)/4).toFixed(1));
1614

1715
const result = await prisma.store_review.create({
1816
data:{
19-
user_id:userBuffer,
20-
store_id:storeBuffer,
17+
user_id:new Uint8Array(userBuffer),
18+
store_id:new Uint8Array(storeBuffer),
2119
kindness_rating:kindness,
2220
settlement_rating:settlement,
2321
communication_rating:communication,
@@ -33,9 +31,9 @@ export const createStoreReview = async (data:StoreReviewRequestDto) =>{
3331
});
3432

3533
return {
36-
reviewId:Buffer.from(result.review_id).toString('hex'),
37-
userId,
38-
storeId,
34+
reviewId:result.review_id,
35+
userBuffer,
36+
storeBuffer,
3937
userName:result.user.user_name,
4038
storeName:result.store.store_name,
4139
totalScore,

src/service/alba_application_service.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { findAlbaDetail,applyAlba} from "../repository/alba_application_repository";
2-
import { AlbaApplyRequestDto, AlbaApplyResponseDto, AlbaDetailResponseDto } from "../DTO/alba_application_dto";
2+
import { AlbaApplyResponseDto, AlbaDetailResponseDto } from "../DTO/alba_application_dto";
3+
import { bufferToUuid } from "../util/uuid_util";
34

45
/**
56
* 대타 아르바이트 정보 상세 조회 서비스
@@ -14,17 +15,18 @@ export const getAlbaDetail = async (albaId:string):Promise<AlbaDetailResponseDto
1415

1516
/**
1617
* 대타 아르바이트 지원 서비스
17-
* @param albaId
18-
* @param userId
18+
* @param albaBuffer
19+
* @param userBuffer
1920
* @returns 알바, 유저Id와 정산여부, 진행과정
2021
*/
21-
export const postAlbaApplication = async(data:AlbaApplyRequestDto):Promise<AlbaApplyResponseDto>=>{
22-
const {albaId,userId} = data
23-
const result = await applyAlba(albaId,userId);
22+
export const postAlbaApplication = async(userBuffer:Buffer,albaBuffer:Buffer):Promise<AlbaApplyResponseDto>=>{
23+
24+
const result = await applyAlba(userBuffer,albaBuffer);
25+
2426

2527
return {
26-
albaId,
27-
userId,
28+
albaId:bufferToUuid(albaBuffer),
29+
userId:bufferToUuid(userBuffer),
2830
processStatus:result.process_status,
2931
settlementStatus:result.settlement_status
3032
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { StoreReviewRequestDto, StoreReviewResponseDto } from "../DTO/store_review_dto";
22
import { createStoreReview } from "../repository/store_review_repository";
3+
import { bufferToUuid, uuidToBuffer } from "../util/uuid_util";
34

45
/**
56
* 리뷰 생성 서비스 로직
67
* @param data(리뷰 데이터)
78
* @returns 생성된 리뷰 데이터와 생성시각, 합산된 총점
89
*/
9-
export const addReview = async(data:StoreReviewRequestDto):Promise<StoreReviewResponseDto>=>{
10-
const review = await createStoreReview(data);
11-
return review;
10+
export const addReview = async(userBuffer:Buffer,data:StoreReviewRequestDto):Promise<StoreReviewResponseDto>=>{
11+
const storeBuffer = Buffer.from(uuidToBuffer(data.storeId))
12+
13+
const review = await createStoreReview(userBuffer,storeBuffer,data);
14+
const {reviewId, userBuffer: uBuf, storeBuffer: sBuf, ...rest} = review
15+
return {
16+
...rest,
17+
reviewId:bufferToUuid(reviewId),
18+
storeId:bufferToUuid(sBuf),
19+
userId:bufferToUuid(uBuf)
20+
};
1221
}

0 commit comments

Comments
 (0)