보일러 플레이팅 레벨
This commit is contained in:
105
viewer/src/services/feedback.ts
Normal file
105
viewer/src/services/feedback.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
// src/services/feedback.ts
|
||||
|
||||
// API 응답과 요청 본문에 대한 타입을 정의합니다.
|
||||
// 실제 API 명세에 따라 더 구체적으로 작성할 수 있습니다.
|
||||
export interface Feedback {
|
||||
id: string;
|
||||
content: string;
|
||||
// ... 다른 필드들
|
||||
}
|
||||
|
||||
export interface Issue {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface CreateFeedbackRequest {
|
||||
message: string;
|
||||
issueNames: string[];
|
||||
}
|
||||
|
||||
const getApiBaseUrl = (projectId: string, channelId:string) =>
|
||||
`/api/projects/${projectId}/channels/${channelId}/feedbacks`;
|
||||
|
||||
/**
|
||||
* 특정 채널의 피드백 목록을 조회합니다.
|
||||
* @param projectId 프로젝트 ID
|
||||
* @param channelId 채널 ID
|
||||
* @returns 피드백 목록 Promise
|
||||
*/
|
||||
export const getFeedbacks = async (
|
||||
projectId: string,
|
||||
channelId: string,
|
||||
): Promise<Feedback[]> => {
|
||||
const url = getApiBaseUrl(projectId, channelId);
|
||||
const response = await fetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("피드백 목록을 불러오는 데 실패했습니다.");
|
||||
}
|
||||
|
||||
return response.json();
|
||||
};
|
||||
|
||||
/**
|
||||
* 특정 채널에 새로운 피드백을 생성합니다.
|
||||
* @param projectId 프로젝트 ID
|
||||
* @param channelId 채널 ID
|
||||
* @param feedbackData 생성할 피드백 데이터
|
||||
* @returns 생성된 피드백 Promise
|
||||
*/
|
||||
export const createFeedback = async (
|
||||
projectId: string,
|
||||
channelId: string,
|
||||
feedbackData: CreateFeedbackRequest,
|
||||
): Promise<Feedback> => {
|
||||
const url = getApiBaseUrl(projectId, channelId);
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(feedbackData),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("피드백 생성에 실패했습니다.");
|
||||
}
|
||||
|
||||
return response.json();
|
||||
};
|
||||
|
||||
/**
|
||||
* 프로젝트의 이슈를 검색합니다.
|
||||
* @param projectId 프로젝트 ID
|
||||
* @param query 검색어
|
||||
* @returns 이슈 목록 Promise
|
||||
*/
|
||||
export const searchIssues = async (
|
||||
projectId: string,
|
||||
query: string,
|
||||
): Promise<Issue[]> => {
|
||||
const url = `/api/projects/${projectId}/issues/search`;
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: { name: query },
|
||||
limit: 10,
|
||||
page: 1,
|
||||
sort: { createdAt: "ASC" },
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("이슈 검색에 실패했습니다.");
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
// API 응답이 { items: Issue[] } 형태일 경우를 가정
|
||||
return result.items || [];
|
||||
};
|
||||
|
||||
// 여기에 다른 API 함수들을 추가할 수 있습니다. (예: updateFeedback, deleteFeedback)
|
||||
Reference in New Issue
Block a user