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: 23 additions & 0 deletions src/api/activity/delete-acitivites.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;

export async function deleteActivity(activityId: number): Promise<boolean> {
try {
const res = await fetch(`${API_BASE_URL}/admin/activities/${activityId}`, {
method: 'DELETE',
credentials: 'include',
headers: {
accept: '*/*',
},
});

if (!res.ok) {
console.log("활동 삭제 실패:", res.status);
return false;
}

return true;
} catch (err) {
console.error("활동 삭제 실패:", err);
return false;
}
}
30 changes: 30 additions & 0 deletions src/api/activity/get-activities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;

export interface Activity {
activityId: number;
name: string;
pointAmount: number;
}

export async function GetActivities(): Promise<Activity[]> {
try {
const res = await fetch(`${API_BASE_URL}/admin/activities`, {
method: 'GET',
credentials: 'include',
headers: {
accept: 'application/json',
},
});

if (!res.ok) {
console.log("응답이 실패했습니다:", res.status);
return [];
}

const data: Activity[] = await res.json();
return data;
} catch (err) {
console.error("활동 목록 조회 실패:", err);
return [];
}
}
30 changes: 30 additions & 0 deletions src/api/activity/get-qrcode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;

export interface MemberInfo {
memberId: number;
name: string;
studentId: string;
}

export async function GetQRCode(uuid: string): Promise<{ success: boolean; data: MemberInfo | null; error?: string }> {
try {
const res = await fetch(`${API_BASE_URL}/admin/qrcode/${uuid}`, {
method: 'GET',
credentials: 'include',
headers: {
accept: 'application/json',
},
});

if (!res.ok) {
console.log("응답이 실패했습니다:", res.status);
return { success: false, data: null, error: `QR 코드 인식에 실패했습니다. (오류 코드: ${res.status})` };
}

const data: MemberInfo = await res.json();
return { success: true, data };
} catch (err) {
console.error("QR 코드 멤버 정보 조회 실패:", err);
return { success: false, data: null, error: "네트워크 오류가 발생했습니다." };
}
}
35 changes: 35 additions & 0 deletions src/api/activity/post-activities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;

export interface MemberActivityRequest {
name: string;
pointAmount: number;
}

export async function PostMemberActivities(name: string, pointAmount: number): Promise<boolean> {
try {
const requestBody: MemberActivityRequest = {
name,
pointAmount,
};

const res = await fetch(`${API_BASE_URL}/admin/activities`, {
method: 'POST',
credentials: 'include',
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody)
});


if (!res.ok) {
console.log("응답이 실패했습니다:", res.status);
return false;
}
return true;
} catch (err) {
console.error("활동 등록 실패:", err);
return false;
}
}
36 changes: 36 additions & 0 deletions src/api/activity/post-memebr-activities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;

export interface MemberActivityRequest {
activityId: number;
memberId: number;
}

export async function PostMemberActivities(activityId: number, memberId: number): Promise<boolean> {
try {
const requestBody: MemberActivityRequest = {
activityId,
memberId
};

const res = await fetch(`${API_BASE_URL}/admin/activity-participation`, {
method: 'POST',
credentials: 'include',
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody)
});


if (!res.ok) {
console.log("응답이 실패했습니다:", res.status);
return false;
}

return true;
} catch (err) {
console.error("멤버 활동 참여 등록 실패:", err);
return false;
}
}
64 changes: 64 additions & 0 deletions src/api/activity/put-activities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;

export interface ActivityInfo {
activityId: number;
name: string;
pointAmount: number;
}

// 조회
export async function getActivityById(activityId: number): Promise<ActivityInfo | null> {
try {
const res = await fetch(`${API_BASE_URL}/admin/activities/${activityId}`, {
method: 'GET',
credentials: 'include',
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
},
});

if (!res.ok) {
console.log("응답이 실패했습니다:", res.status);
return null;
}

const data: ActivityInfo = await res.json();
console.log("받아온 활동 정보:", data);

return data;
} catch (err) {
console.error("활동 정보 조회 실패:", err);
return null;
}
}

// 수정
export async function updateActivity(activityId: number, name: string, pointAmount: number): Promise<boolean> {
try {
const requestBody = {
name,
pointAmount,
};

const res = await fetch(`${API_BASE_URL}/admin/activities/${activityId}`, {
method: 'PUT',
credentials: 'include',
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody)
});

if (!res.ok) {
console.log("활동 수정 실패:", res.status);
return false;
}

return true;
} catch (err) {
console.error("활동 수정 실패:", err);
return false;
}
}
31 changes: 31 additions & 0 deletions src/api/auth/members.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;

export async function Members(): Promise<boolean> {
try {
const res = await fetch(`${API_BASE_URL}/members`, {
method: 'GET',
credentials: 'include',
headers: {
accept: 'application/json',
},
});

if (!res.ok) {
console.log("응답이 실패했습니다:", res.status);
return false;
}

const data = await res.json();

if (data.role === "ADMIN") {
alert(`안녕하세요 ${data.name} 관리자님!`);
return true;
} else {
alert("로그인 실패! 관리자만 접근 가능합니다.");
return false;
}
} catch (err) {
console.error("인증 확인 실패:", err);
return false;
}
}
Loading