Skip to content

Commit fd4df62

Browse files
authored
feat: coffeeChat added function api
2 parents 63e39ae + 32fd26a commit fd4df62

File tree

3 files changed

+173
-3
lines changed

3 files changed

+173
-3
lines changed

src/coffeeChat/coffeeChat.Controller.ts

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Get, Post, Route, SuccessResponse, Tags, Response, Request, Middlewares, Query } from 'tsoa';
1+
import { Body, Controller, Get, Post, Route, SuccessResponse, Tags, Response, Request, Middlewares, Query, Patch } from 'tsoa';
22
import { ITsoaErrorResponse, ITsoaSuccessResponse, TsoaSuccessResponse } from '../config/tsoaResponse';
33
import { Request as ExpressRequest } from 'express';
44
import { exceedLimitError, nonData, nonPostComment, postTodayError } from './coffeeChat.Message';
@@ -338,4 +338,116 @@ export class HomeController extends Controller {
338338
return new TsoaSuccessResponse<CoffeeChatRecordDetail>(result);
339339
};
340340

341+
/**
342+
* Coffect coffeeChat Home API.
343+
*
344+
* @summary 커피챗 일정등록 API
345+
* @param body 유저 Token
346+
* @returns 요청 성공 여부
347+
*/
348+
@Patch('fixCoffeeChatSchedule')
349+
@Middlewares(verify)
350+
@SuccessResponse('200', '정상적으로 커피챗 일정을 수정하였습니다다.')
351+
@Response<ITsoaErrorResponse> (
352+
400,
353+
'Bad Request',
354+
{
355+
resultType: 'FAIL',
356+
error: {
357+
errorCode: 'HE402',
358+
reason: '내용이 누락되었습니다.',
359+
data: null
360+
},
361+
success: null
362+
})
363+
@Response<ITsoaErrorResponse>(
364+
500,
365+
'Internal Server Error',
366+
{
367+
resultType: 'FAIL',
368+
error: {
369+
errorCode: 'HE500',
370+
reason: '서버 오류가 발생했습니다.',
371+
data: null
372+
},
373+
success: null
374+
})
375+
public async fixCoffeeChatSchedule (
376+
@Request() req: ExpressRequest,
377+
@Body() body: {
378+
coffectId : number;
379+
coffeeDate: Date;
380+
location: string;
381+
time: Date;
382+
},
383+
):Promise<ITsoaSuccessResponse<string>> {
384+
const userId = req.decoded.index;
385+
const { coffectId, coffeeDate, location, time } = body;
386+
387+
if(coffectId === null) {
388+
throw new nonPostComment('커피챗 일정 번호가 누락되었습니다.');
389+
} else if(coffeeDate === null) {
390+
throw new nonPostComment('일정이 누락되었습니다.');
391+
} else if(location === null ) {
392+
throw new nonPostComment('위치가 누락되었습니다.');
393+
} else if(time === null) {
394+
throw new nonPostComment('시간이 누락되었습니다.');
395+
}
396+
397+
const result = await this.homeService.fixCoffeeChatScheduleService(userId, coffectId,coffeeDate, location, time);
398+
399+
return new TsoaSuccessResponse<string>('정상적으로 커피챗 일정을 등록했습니다.');
400+
};
401+
402+
/**
403+
* Coffect coffeeChat Home API.
404+
*
405+
* @summary 커피챗 승낙 API
406+
* @param body 유저 Token
407+
* @returns 요청 성공 여부
408+
*/
409+
@Patch('acceptCoffeeChat')
410+
@Middlewares(verify)
411+
@SuccessResponse('200', '성공적으로 커피챗을 승낙했습니다.')
412+
@Response<ITsoaErrorResponse> (
413+
400,
414+
'Bad Request',
415+
{
416+
resultType: 'FAIL',
417+
error: {
418+
errorCode: 'HE404',
419+
reason: '존재하지 않는 커피챗 일정입니다.',
420+
data: null
421+
},
422+
success: null
423+
})
424+
@Response<ITsoaErrorResponse>(
425+
500,
426+
'Internal Server Error',
427+
{
428+
resultType: 'FAIL',
429+
error: {
430+
errorCode: 'HE500',
431+
reason: '서버 오류가 발생했습니다.',
432+
data: null
433+
},
434+
success: null
435+
})
436+
public async acceptCoffeeChat(
437+
@Request() req: ExpressRequest,
438+
@Body() body: {
439+
coffectId : number;
440+
},
441+
):Promise<ITsoaSuccessResponse<string>> {
442+
const userId = req.decoded.index;
443+
const { coffectId } = body;
444+
445+
if(coffectId === null) {
446+
throw new nonData('존재하지 않는 커피챗입니다.');
447+
}
448+
449+
await this.homeService.acceptCoffeeChatService(userId, coffectId);
450+
451+
return new TsoaSuccessResponse<string>('정상적으로 커피챗을 승낙했습니다.');
452+
};
341453
}

src/coffeeChat/coffeeChat.Model.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ export class HomeModel {
287287
const currentGrade = userGrade.studentId;
288288

289289
if(currentGrade === null || currentGrade === undefined) {
290-
throw new Error (`Cannot extract grade: ${userGrade.studentId}`);
290+
// studentId가 없으면 filteredArray 그대로 사용
291+
return;
291292
}
292293

293294
// filteredArray를 순회하면서 조건에 맞는 사용자를 탐색
@@ -469,6 +470,7 @@ export class HomeModel {
469470
{ secondUserId: userId }
470471
],
471472
valid: true,
473+
// 커피챗 일정이 오늘 이후인 경우만 조회
472474
coffectDate: {
473475
gte: currentDate
474476
}
@@ -670,4 +672,42 @@ export class HomeModel {
670672
secondUserImage
671673
);
672674
};
675+
676+
public async fixCoffeeChatScheduleModel(
677+
userId : number,
678+
coffectId : number,
679+
coffeeChat : Date,
680+
location : string,
681+
time : Date
682+
):Promise<void> {
683+
const combineDate = new Date(coffeeChat.getTime() + time.getTime());
684+
685+
await prisma.coffeeChat.update({
686+
where : {
687+
coffectId : coffectId,
688+
OR : [{firstUserId : userId}, {secondUserId : userId}]
689+
},
690+
data : {
691+
coffectDate : combineDate,
692+
location : location
693+
}
694+
});
695+
};
696+
697+
public async acceptCoffeeChatModel(
698+
userId : number,
699+
coffectId : number
700+
):Promise<void> {
701+
await prisma.coffeeChat.update({
702+
where : {
703+
OR : [{firstUserId : userId}, {secondUserId : userId}],
704+
coffectId : coffectId
705+
},
706+
data : {
707+
valid : true
708+
}
709+
});
710+
};
711+
712+
673713
}

src/coffeeChat/coffeeChat.Service.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,23 @@ export class HomeService {
118118
const result = await this.homeModel.getSpecifyCoffeeChatModel(userId);
119119

120120
return result;
121-
}
121+
};
122+
123+
public async fixCoffeeChatScheduleService(
124+
userId : number,
125+
coffectId : number,
126+
coffeeChat : Date,
127+
location : string,
128+
time : Date
129+
):Promise<void> {
130+
await this.homeModel.fixCoffeeChatScheduleModel(userId, coffectId, coffeeChat, location, time);
131+
};
132+
133+
public async acceptCoffeeChatService(
134+
userId : number,
135+
coffectId : number
136+
):Promise<void> {
137+
await this.homeModel.acceptCoffeeChatModel(userId, coffectId);
138+
};
139+
122140
}

0 commit comments

Comments
 (0)