Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @types/express.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ declare global {
}): this;
}
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@google-cloud/vision": "^4.3.2",
"@prisma/client": "^6.1.0",
"@quixo3/prisma-session-store": "^3.1.13",
"@types/navermaps": "^3.7.8",
"@types/cookie-parser": "^1.4.8",
"cookie-parser": "^1.4.7",
"@tsoa/runtime": "^6.6.0",
Expand Down
228 changes: 217 additions & 11 deletions src/controllers/challenge.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Request, Response, NextFunction } from 'express';
import { serviceDeleteChallenge, serviceUpdateChallenge } from '../services/challenge.services.js';
import { serviceAcceptChallenge, serviceCompleteChallenge, serviceDeleteChallenge, serviceGetByUserId, serviceUpdateChallenge } from '../services/challenge.services.js';
import { StatusCodes } from 'http-status-codes';
import { getIdNumber } from '../utils/challenge.utils.js';


import { Challenge } from '@prisma/client';
import { ResponseFromGetByUserIdReform } from '../models/challenge.entities.js';
import { DataValidationError } from '../errors.js';

export const handleUpdateChallenge = async (
req: Request,
Expand Down Expand Up @@ -52,9 +53,17 @@ export const handleUpdateChallenge = async (
}
};
*/
serviceUpdateChallenge(req.body);
res.status(StatusCodes.OK).success(req.body);
console.log(req.body);
try{
if(!req.body){
throw new DataValidationError({reason: '업데이트 내용이 없습니다.'});
}

serviceUpdateChallenge(req.body);
res.status(StatusCodes.OK).success(req.body);
console.log(req.body);
} catch(error){
next(error);
}
};

export const handleRemoveChallenge = async (
Expand All @@ -63,9 +72,9 @@ export const handleRemoveChallenge = async (
next: NextFunction
): Promise<void> => {
/*
#swagger.tags = ['challenge-controller']
#swagger.tags = ['challenge-controller'];
#swagger.summary = '챌린지 삭제 API';
#swagger.description = '챌린지를 삭제하는 API입니다.'
#swagger.description = '챌린지를 삭제하는 API입니다.';
#swagger.requestBody = {
required: true,
content: {
Expand Down Expand Up @@ -101,7 +110,204 @@ export const handleRemoveChallenge = async (
}
};
*/
serviceDeleteChallenge(getIdNumber(req.body));
res.status(StatusCodes.OK).success(req.body);
console.log(req.body);
try{
if(!req.body){
throw new DataValidationError({reason: '삭제할 챌린지의 정보가 없습니다.'});
}
serviceDeleteChallenge(getIdNumber(req.body));
res.status(StatusCodes.OK).success(req.body);
console.log(req.body);
} catch(error){
next(error);
}
};

export const handleAcceptChallenge = async (
req: Request<{id: string}>,
res: Response,
next: NextFunction
): Promise<void> => {
/*
#swagger.tags = ['challenge-controller'];
#swagger.summary = '챌린지 수락 API';
#swagger.description = '챌린지를 수락하는 API입니다.';
#swagger.parameters['id'] = {
in: 'path',
required: true,
description: "챌린지 ID 입력",
'@schema': {
type: "string",
}
};
#swagger.requestBody = {
required: false
};
#swagger.responses[200] = {
description: "챌린지 수락 성공 응답",
content: {
"application/json": {
schema: {
type: "object",
properties: {
resultType: { type: "string", example: "SUCCESS" },
error: { type: "object", nullable: true, example: null },
success: {
type: "object",
properties: {
id: { type: "string", example: "1" },
title: { type: "string", example: "challenge-title" },
context: { type: "string", example: "challenge-context" },
requiredCount: { type: "number", example: 10 },
remainingCount: { type: "number", example: 10 },
userId: { type: "string", example: "1" },
createdAt: { type: "string", format: "date-time", example: "2025-01-20T18:19:47.415Z" },
updatedAt: { type: "string", format: "date-time", example: "2025-01-20T18:19:47.415Z" },
acceptedAt: { type: "string", format: "date-time", example: "2025-01-20T18:19:47.415Z" },
completedAt: { type: "string", format: "date-time", example: "2025-01-20T18:19:47.415Z" },
status: { type: "number", example: 1 }
}
}
}
}
}
}
};
*/
try{
if(!req.params.id){
throw new DataValidationError({reason: '올바른 parameter값이 필요합니다.'});
}

const result: Challenge = await serviceAcceptChallenge(BigInt(req.params.id));
res.status(StatusCodes.OK).success(result);
} catch(error){
next(error);
}
};

export const handleCompleteChallenge = async (
req: Request<{id: string}>,
res: Response,
next: NextFunction
): Promise<void> => {
/*
#swagger.tags = ['challenge-controller'];
#swagger.summary = '챌린지 완료 API';
#swagger.description = '챌린지를 완료하는 API입니다.';
#swagger.parameters['id'] = {
in: 'path',
required: true,
description: "챌린지 ID 입력",
'@schema': {
type: "string",
}
};
#swagger.requestBody = {
required: false
};
#swagger.responses[200] = {
description: "챌린지 완료 성공 응답",
content: {
"application/json": {
schema: {
type: "object",
properties: {
resultType: { type: "string", example: "SUCCESS" },
error: { type: "object", nullable: true, example: null },
success: {
type: "object",
properties: {
id: { type: "string", example: "1" },
title: { type: "string", example: "challenge-title" },
context: { type: "string", example: "challenge-context" },
requiredCount: { type: "number", example: 10 },
remainingCount: { type: "number", example: 10 },
userId: { type: "string", example: "1" },
createdAt: { type: "string", format: "date-time", example: "2025-01-20T18:19:47.415Z" },
updatedAt: { type: "string", format: "date-time", example: "2025-01-20T18:19:47.415Z" },
acceptedAt: { type: "string", format: "date-time", example: "2025-01-20T18:19:47.415Z" },
completedAt: { type: "string", format: "date-time", example: "2025-01-20T18:19:47.415Z" },
status: { type: "number", example: 1}
}
}
}
}
}
}
};
*/
try{
if(!req.params.id){
throw new DataValidationError({reason: '올바른 parameter값이 필요합니다.'});
}

const result: Challenge = await serviceCompleteChallenge(BigInt(req.params.id));
res.status(StatusCodes.OK).success(result);
} catch(error){
next(error);
}
};

export const handleGetByUserId = async (
req: Request<{userId: string}>,
res: Response,
next: NextFunction
): Promise<void> => {
/*
#swagger.tags = ['challenge-controller'];
#swagger.summary = '특정 유저의 챌린지 조회 API';
#swagger.description = '특정 유저의 모든 챌린지를 조회하는 API입니다.';
#swagger.parameters['userId'] = {
in: 'path',
required: true,
description: "유저 ID 입력",
'@schema': {
type: "string"
}
};
#swagger.requestBody = {
required: false
};
#swagger.responses[200] = {
description: "유저 챌린지 조회 성공 응답",
content: {
"application/json": {
schema: {
type: "object",
properties: {
resultType: { type: "string", example: "SUCCESS" },
error: { type: "object", nullable: true, example: null },
success: {
type: "array",
items: {
type: "object",
properties: {
id: {type: "string", example: "1"},
title: {type: "string"},
context: {type: "string"},
challengeLocation: {type: "string"},
challengeDate: {type: "string", format: "date-time"},
requiredCount: {type: "number"},
remainingCount: {type: "number"},
userId: {type: "string"},
createdAt: {type: "string", format: "date-time"},
updatedAt: {type: "string", format: "date-time"},
acceptedAt: {type: "string", format: "date-time"},
completedAt: {type: "string", format: "date-time"},
status: {type: "number"}
}
}
}
}
}
}
}
};
*/
try{
const result: ResponseFromGetByUserIdReform[] = await serviceGetByUserId(BigInt(req.params.userId));
res.status(StatusCodes.OK).success(result);
} catch(error){
next(error);
}
};
39 changes: 30 additions & 9 deletions src/controllers/challenge.location.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { serviceCreateNewLocationChallenge, serviceGetLocationChallenge, service
import { StatusCodes } from 'http-status-codes';
import { LocationChallengeCreation, ResponseFromChallenge } from '../models/challenge.entities.js';
import { bodyToLocationCreation } from '../dtos/challenge.dtos.js';
import { DataValidationError } from '../errors.js';

export const handleNewLocationChallenge = async (
req: Request,
Expand Down Expand Up @@ -62,10 +63,18 @@ export const handleNewLocationChallenge = async (
}
};
*/
const data: LocationChallengeCreation = bodyToLocationCreation(req.body);
const result: ResponseFromChallenge = await serviceCreateNewLocationChallenge(data);
res.status(StatusCodes.OK).success(result);
console.log(req.body);
try{
if(!req.body){
throw new DataValidationError({reason: '위치 챌린지를 생성할 데이터가 없습니다.'});
}

const data: LocationChallengeCreation = bodyToLocationCreation(req.body);
const result: ResponseFromChallenge = await serviceCreateNewLocationChallenge(data);
res.status(StatusCodes.OK).success(result);
console.log(req.body);
} catch(error){
next(error);
}
};

export const handleGetLocationChallenge = async (
Expand Down Expand Up @@ -120,9 +129,17 @@ export const handleGetLocationChallenge = async (
}
};
*/
const result = await serviceGetLocationChallenge(BigInt(req.params.id));
res.status(StatusCodes.OK).success(result);
console.log(req.params.id);
try{
if(!req.params.id){
throw new DataValidationError({reason: '올바른 parameter 값이 필요합니다.'});
}

const result = await serviceGetLocationChallenge(BigInt(req.params.id));
res.status(StatusCodes.OK).success(result);
console.log(req.params.id);
} catch(error){
next(error);
}
};

export const handleLocationLogic = async (
Expand Down Expand Up @@ -183,6 +200,10 @@ export const handleLocationLogic = async (
}
};
*/
const result = await serviceLocationLogic(req.body);
res.status(StatusCodes.OK).success(result);
try{
const result = await serviceLocationLogic(req.body);
res.status(StatusCodes.OK).success(result);
} catch(error){
next(error);
}
};
29 changes: 23 additions & 6 deletions src/controllers/challenge.weekly.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ResponseFromChallenge, WeeklyChallengeCreation } from '../models/challe
import { bodyToWeeklyCreation } from '../dtos/challenge.dtos.js';
import { StatusCodes } from 'http-status-codes';
import { serviceCreateNewWeeklyChallenge, serviceGetWeeklyChallenge } from '../services/challenge.weekly.services.js';
import { DataValidationError } from '../errors.js';

export const handleNewWeeklyChallenge = async(
req: Request,
Expand Down Expand Up @@ -61,10 +62,18 @@ export const handleNewWeeklyChallenge = async(
}
};
*/
const data: WeeklyChallengeCreation = bodyToWeeklyCreation(req.body);
const result: ResponseFromChallenge = await serviceCreateNewWeeklyChallenge(data);
res.status(StatusCodes.OK).success(result);
console.log(req.headers);
try{
if(!req.body){
throw new DataValidationError({reason: '날짜 챌린지를 생성할 데이터가 없습니다.'});
}

const data: WeeklyChallengeCreation = bodyToWeeklyCreation(req.body);
const result: ResponseFromChallenge = await serviceCreateNewWeeklyChallenge(data);
res.status(StatusCodes.OK).success(result);
console.log(req.headers);
} catch(error){
next(error);
}
};

export const handleGetWeeklyChallenge = async(
Expand Down Expand Up @@ -119,6 +128,14 @@ export const handleGetWeeklyChallenge = async(
}
};
*/
const result = await serviceGetWeeklyChallenge(BigInt(req.params.id));
res.status(StatusCodes.OK).success(result);
try{
if(!req.params.id){
throw new DataValidationError({reason: '올바른 parameter값이 필요합니다.'});
}

const result = await serviceGetWeeklyChallenge(BigInt(req.params.id));
res.status(StatusCodes.OK).success(result);
} catch(error){
next(error);
}
};
Loading
Loading