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
23 changes: 16 additions & 7 deletions src/reports/dtos/report.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const toCreateReportResponse = ({



// 신고된 프롬프트 목록 조회 응답 인터페이스
// 개별 신고 항목 DTO
export interface ReportedPromptDTO {
report_id: number;
prompt_id: number;
Expand All @@ -40,33 +40,42 @@ export interface ReportedPromptDTO {
created_at: string;
is_read: boolean;
}
// 전체 신고 목록 응답 타입


// 전체 응답 DTO
export interface ReportedPromptListResponse {
reports: ReportedPromptDTO[];// 신고 목록 배열
has_more: boolean; // 다음 페이지 여부
total_count: number; // 전체 신고 수
}
// 변환 함수(신고목록->api응답)


// 변환 함수
export const toReportedPromptListResponse = (
reports: (PromptReport & {
prompt: { prompt_id: number; title: string };// 프롬프트 정보 (프롬프트 ID & 제목)
reporter: { user_id: number; nickname: string };// 신고자 정보 (ID & 닉네임)
})[],
hasMore: boolean
hasMore: boolean,
totalCount: number
): ReportedPromptListResponse => {
// DB 원본 데이터를 ReportedPromptDTO 배열로 변환

// 개별 신고 항목 변환
const transformed: ReportedPromptDTO[] = reports.map((report) => ({
report_id: report.report_id,
prompt_id: report.prompt.prompt_id,
prompt_title: report.prompt.title,
reporter_id: report.reporter.user_id,
reporter_nickname: report.reporter.nickname,
created_at: report.created_at.toISOString(),
is_read: report.is_read
is_read: report.is_read,
}));

// 최종 응답 객체 반환 (has_more은 페이징 기준으로 판단)
return {
reports: transformed,
has_more: hasMore
has_more: hasMore,
total_count: totalCount
};
};

Expand Down
5 changes: 5 additions & 0 deletions src/reports/repositories/report.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export const findAllReports = async (
});
};

// 시스템 전체 신고 개수 조회
export const countTotalReports = async () => {
return await prisma.promptReport.count();
}

// 읽음 처리
export const markReportAsRead = async (reportId: number) => {
return await prisma.promptReport.update({
Expand Down
13 changes: 9 additions & 4 deletions src/reports/routes/report.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ router.post('/', authenticateJwt, postReport); // 특정 프롬프트에 대한
* description: |
* 커서 기반 페이지네이션(cursor-based-pagination) 사용.
* - `cursor`는 이전 요청에서 받은 마지막 목록의 ID를 의미하며, 이를 기준으로 이후 데이터를 조회.
* - 첫 요청 시에는 `cursor`를 생략하여 최신 리뷰부터 조회.
* - 첫 요청 시에는 `cursor`를 생략하여 최신 신고부터 조회.
* - `has_more` 속성으로 더 불러올 데이터가 있는지 미리 확인 가능.
* tags: [Report]
* security:
Expand All @@ -100,16 +100,16 @@ router.post('/', authenticateJwt, postReport); // 특정 프롬프트에 대한
* schema:
* type: integer
* description: >
* 마지막으로 조회된 ID.
* 처음 요청 시 생략 가능.
* 마지막으로 조회된 ID.
* 처음 요청 시 생략 가능.
* 예: 첫 요청에서 id=80~70까지 받았다면 다음 요청 시 `cursor=70`
* - in: query
* name: limit
* required: false
* schema:
* type: integer
* default: 10
* description: 가져올 리뷰 수 (기본값 10)
* description: 가져올 신고 수 (기본값 10)
* responses:
* 200:
* description: 신고된 프롬프트 목록을 성공적으로 불러왔습니다.
Expand Down Expand Up @@ -154,6 +154,10 @@ router.post('/', authenticateJwt, postReport); // 특정 프롬프트에 대한
* has_more:
* type: boolean
* example: false
* total_count:
* type: integer
* example: 57
* description: 시스템에 존재하는 전체 신고 수
* statusCode:
* type: integer
* example: 200
Expand All @@ -163,6 +167,7 @@ router.post('/', authenticateJwt, postReport); // 특정 프롬프트에 대한
* description: 서버 오류
*/


router.get('/', authenticateJwt, getReportedPrompts); // 신고 당한 프롬프트 목록 조회(관리자용)
/**
* @swagger
Expand Down
6 changes: 4 additions & 2 deletions src/reports/services/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
findAllReports,
markReportAsRead,
findReportById,
countTotalReports,
} from '../repositories/report.repository';
import eventBus from '../../config/eventBus';

Expand Down Expand Up @@ -36,6 +37,7 @@ export const createReportService = async (
return toCreateReportResponse(newReport);
};

// 신고된 프롬프트 목록 조회
export const getReportedPromptsService = async (
userId: number,
rawCursor?: string,
Expand Down Expand Up @@ -66,8 +68,8 @@ export const getReportedPromptsService = async (
const rawreportedPrompts = await findAllReports(cursor, limit);
const hasMore = rawreportedPrompts.length > limit;
const slicedNotifications = hasMore ? rawreportedPrompts.slice(0, limit) : rawreportedPrompts;

return toReportedPromptListResponse(slicedNotifications, hasMore);
const totalCount = await countTotalReports();
return toReportedPromptListResponse(slicedNotifications, hasMore, totalCount);
};


Expand Down