Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -22,4 +22,4 @@ declare global {
}): this;
}
}
}
}
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@google-cloud/vision": "^4.3.2",
"@prisma/client": "^6.1.0",
"@quixo3/prisma-session-store": "^3.1.13",
"@types/navermaps": "^3.7.8",
"coordinate-parser": "^1.0.7",
"cors": "^2.8.5",
"dotenv": "^16.4.7",
Expand All @@ -50,24 +51,24 @@
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/express-session": "^1.18.1",
"@types/multer": "^1.4.12",
"@types/multer-s3": "^3.0.3",
"@types/node": "^22.10.3",
"@types/passport": "^1.0.17",
"@types/passport-google-oauth20": "^2.0.16",
"@types/swagger-ui-express": "^4.1.7",
"@typescript-eslint/eslint-plugin": "^8.19.1",
"@typescript-eslint/parser": "^8.19.1",
"@types/multer": "^1.4.12",
"@types/multer-s3": "^3.0.3",
"@types/passport-kakao": "^1.0.3",
"@types/passport-naver": "^1.0.4",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.7",
"@typescript-eslint/eslint-plugin": "^8.19.1",
"@typescript-eslint/parser": "^8.19.1",
"esbuild": "^0.24.2",
"esbuild-plugin-copy": "^2.1.1",
"eslint": "^9.17.0",
"gts": "^6.0.2",
"nodemon": "^3.1.9",
"tsoa": "^6.6.0",
"tsx": "^4.19.2",
"typescript": "^5.6.3",
"tsoa": "^6.6.0"
"typescript": "^5.6.3"
}
}
81 changes: 78 additions & 3 deletions src/controllers/challenge.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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';

export const handleUpdateChallenge = async (
req: Request,
Expand Down Expand Up @@ -104,4 +104,79 @@ export const handleRemoveChallenge = async (
serviceDeleteChallenge(getIdNumber(req.body));
res.status(StatusCodes.OK).success(req.body);
console.log(req.body);
};

export const handleAcceptChallenge = async (
req: Request<{id: string}>,
res: Response,
next: NextFunction
): Promise<void> => {
const result: Challenge = await serviceAcceptChallenge(BigInt(req.params.id));
res.status(StatusCodes.OK).success(result);
};

export const handleCompleteChallenge = async (
req: Request<{id: string}>,
res: Response,
next: NextFunction
): Promise<void> => {
const result: Challenge = await serviceCompleteChallenge(BigInt(req.params.id));
res.status(StatusCodes.OK).success(result);
};

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.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"}
}
}
}
}
}
}
}
};
*/
const result: ResponseFromGetByUserIdReform[] = await serviceGetByUserId(BigInt(req.params.userId));
res.status(StatusCodes.OK).success(result);
};
4 changes: 2 additions & 2 deletions src/controllers/memo-createFolderOCR.Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const createFolderOCR = async (
#swagger.tags = ['memo-ai']
#swagger.summary = '폴더 생성 및 OCR 수행'
#swagger.description = '새로운 폴더를 생성하고, 이미지에서 OCR 텍스트를 추출하여 이미지와 텍스트를 저장하는 API입니다.'
#swagger.requestBody = {W
#swagger.requestBody = {
required: true,
content: {
"application/json": {
Expand Down Expand Up @@ -54,7 +54,7 @@ export const createFolderOCR = async (
properties: {
folder_id: { type: "string", example: "1" },
image_text: { type: "string", example: "이번 수업 시간은 사회 과학 시간이다." },
}
}
}
}
Expand Down
36 changes: 31 additions & 5 deletions src/dtos/challenge.dtos.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Challenge, LocationChallenge, DateChallenge } from '@prisma/client';
import { BodyToLocationCreation, BodyToWeeklyCreation, PhotoInfo } from '../models/challenge.entities.js';
import { BodyToLocationCreation, BodyToWeeklyCreation, PhotoInfo, ResponseFromChallenge, ResponseFromGetByUserId, ResponseFromGetByUserIdReform, ResponseFromLocationChallenge, ResponseFromWeeklyChallenge } from '../models/challenge.entities.js';

export const responseFromLocationChallenge = ({
location,
challenge
}: {
location: LocationChallenge;
challenge: Challenge;
}) => {
}): ResponseFromLocationChallenge => {
const {id, title, context, requiredCount, remainingCount,
userId, createdAt, updatedAt, acceptedAt, completedAt, status
} = challenge;
Expand Down Expand Up @@ -35,7 +35,7 @@ export const responseFromWeeklyChallenge = ({
}: {
weekly: DateChallenge;
challenge: Challenge
}) => {
}): ResponseFromWeeklyChallenge => {
const {id, title, context, requiredCount, remainingCount,
userId, createdAt, updatedAt, acceptedAt, completedAt, status
} = challenge;
Expand All @@ -58,7 +58,7 @@ export const responseFromWeeklyChallenge = ({
};
};

export const responseFromChallenge = (challenge: Challenge) => {
export const responseFromChallenge = (challenge: Challenge): ResponseFromChallenge => {
const {id, title, context, requiredCount, remainingCount, userId,
createdAt, updatedAt, acceptedAt, completedAt, status
} = challenge;
Expand All @@ -78,7 +78,33 @@ export const responseFromChallenge = (challenge: Challenge) => {
};
};

export const bodyToLocationLogic = (photo: PhotoInfo[]) => {
export const responseFromGetByUserId = (
challenges: ResponseFromGetByUserId[]
): ResponseFromGetByUserIdReform[] => {
return challenges.map((value: ResponseFromGetByUserId) => {
const {id, title, context, requiredCount, remainingCount, userId,
createdAt, updatedAt, acceptedAt, completedAt, status, locationChallenge, dateChallenge
} = value;

return {
id: id.toString(),
title,
context,
challengeLocation: locationChallenge?.challengeLocation,
challengeDate: dateChallenge?.challengeDate,
requiredCount,
remainingCount,
userId: userId.toString(),
createdAt,
updatedAt,
acceptedAt,
completedAt,
status
};
});
};

export const bodyToLocationLogic = (photo: PhotoInfo[]): PhotoInfo[] => {
return photo;
};

Expand Down
48 changes: 44 additions & 4 deletions src/errors.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 파일에서 낭니가 만들어놓은 에러 클래스들 명이나 양식 바꾸시고 적용하신거같은데, 곧 낭니가 재업데이트하면 아마 컨플릭날 수도 있습니다.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class DataValidationError extends BaseError {

// 생성 관련 에러 (CHL)
export class LocationChallengeCreationError extends BaseError {
constructor(details: {latitude: number; longitude: number}) {
constructor(details: {reason: string}) {
super(
400,
'CHL-400',
Expand All @@ -96,14 +96,14 @@ export class LocationChallengeCreationError extends BaseError {
}

// 업데이트 관련 에러 (CHL-Challenge)
export class LocationChallengeUpdateError extends BaseError {
export class ChallengeUpdateError extends BaseError {
constructor(details: {challengeId: bigint; userId?: bigint}) {
super(400, 'CHL-400', '위치 기반 챌린지 업데이트 실패.', details);
super(400, 'CHL-400', '챌린지 업데이트 실패.', details);
}
}

// 삭제 관련 에러 (CHL)
export class LocationChallengeDeletionError extends BaseError {
export class ChallengeDeletionError extends BaseError {
constructor(details: {challengeId: bigint}) {
super(400, 'CHL-400', '위치 기반 챌린지 삭제 실패.', details);
}
Expand All @@ -116,6 +116,46 @@ export class LocationChallengeNotFoundError extends BaseError {
}
}

// 챌린지 수락 관련 에러 (CHL)
export class ChallengeAcceptError extends BaseError {
constructor(details: {challengeId: bigint; reason: string}) {
super(400, 'CHL-400', '해당 챌린지를 수락할 수 없습니다.', details);
}
}

// 챌린지 완료 관련 에러 (CHL)
export class ChallengeCompleteError extends BaseError {
constructor(details: {challengeId: bigint; reason: string}){
super(400, 'CHL-400', '챌린지 완료 실패', details);
}
}

// 챌린지 조회 관련 에러 (CHL)
export class ChallengeNotFoundError extends BaseError {
constructor(details: {userId: bigint}){
super(404, 'CHL-404', '해당 유저의 챌린지를 찾을 수 없습니다.', details);
}
}

// 날짜 챌린지 생성 관련 에러 (CHL)
export class DateChallengeCreationError extends BaseError {
constructor(details: {reason: string}) {
super(
400,
'CHL-400',
'날짜 기반 챌린지 생성 중 오류가 발생했습니다.',
details,
);
}
}

// 조회 관련 에러 (CHL)
export class DateChallengeNotFoundError extends BaseError {
constructor(details: {challengeId: bigint}) {
super(404, 'CHL-404', '해당 날짜 기반 챌린지를 찾을 수 없습니다.', details);
}
}

// 사진 데이터 관련 에러 (PHO-photo)
export class PhotoDataNotFoundError extends BaseError {
constructor(details?: ErrorDetails) {
Expand Down
39 changes: 38 additions & 1 deletion src/models/challenge.entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface ResponseFromWeeklyChallenge {
userId: string;
title: string;
context: string;
challengeDate: string;
challengeDate: Date;
requiredCount: number;
remainingCount: number;
createdAt: Date;
Expand All @@ -89,6 +89,43 @@ export interface ResponseFromUpdateChallenge {
status: number;
}

export interface ResponseFromGetByUserId {
locationChallenge: {
challengeLocation: string;
} | null;
dateChallenge: {
challengeDate: Date;
} | null;

id: bigint;
userId: bigint;
title: string;
context: string;
requiredCount: number;
remainingCount: number;
createdAt: Date;
updatedAt: Date | null;
acceptedAt: Date | null;
completedAt: Date | null;
status: number;
}

export interface ResponseFromGetByUserIdReform {
id: string;
userId: string;
title: string;
context: string;
challengeLocation: string | undefined;
challengeDate: Date | undefined;
requiredCount: number;
remainingCount: number;
createdAt: Date;
updatedAt: Date | null;
acceptedAt: Date | null;
completedAt: Date | null;
status: number;
}

export interface PhotoInfo {
id: string;
displayName: string;
Expand Down
Loading
Loading