feat: something with something

This commit is contained in:
moolcoov
2025-03-02 13:52:42 +03:00
parent 62e44aba4c
commit b220004ea5
25 changed files with 369 additions and 126 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
import { authFetch } from ".";
import { apiFetch } from ".";
interface AuthResponse {
token: string;
@@ -9,14 +9,14 @@ export const signup = async (body: {
username: string;
password: string;
}) => {
return await authFetch<AuthResponse>("/sign-up", {
return await apiFetch<AuthResponse>("/sign-up", {
method: "POST",
body,
});
};
export const login = async (body: { email: string; password: string }) => {
return await authFetch<AuthResponse>("/sign-in", {
return await apiFetch<AuthResponse>("/sign-in", {
method: "POST",
body,
});
@@ -0,0 +1,14 @@
import { userFetch } from ".";
import { Competition } from "../types/competition";
export const getCompetitions = async (participating?: boolean) => {
return await userFetch<Competition[]>("/competitions", {
params: {
is_participating: participating,
},
});
};
export const getCompetition = async (id: string) => {
return await userFetch<Competition>(`/competition/${id}`);
};
+2 -3
View File
@@ -14,17 +14,16 @@ export class ApiError extends Error {
}
}
export const authFetch = ofetch.create({
export const apiFetch = ofetch.create({
baseURL: BASE_URL,
async onResponseError({ response }) {
throw new ApiError(response);
},
});
export const apiFetch = ofetch.create({
export const userFetch = ofetch.create({
baseURL: BASE_URL,
async onRequest({ options }) {
console.log(import.meta.env.VITE_API_ENDPOINT);
options.headers.set("Authorization", "Bearer " + getToken());
},
async onResponseError({ response }) {
@@ -0,0 +1,10 @@
import { apiFetch } from ".";
import { Reviewer } from "../types/review";
export const getReviewer = async (token: string) => {
return await apiFetch<Reviewer>(`/review/${token}`);
};
export const getReviewerSubmissions = async (token: string) => {
return await apiFetch(`/review/${token}/submissions`);
};
+2 -2
View File
@@ -1,6 +1,6 @@
import { apiFetch } from ".";
import { userFetch } from ".";
import { User } from "../types/user";
export const getCurrentUser = async () => {
return await apiFetch<User>("/me");
return await userFetch<User>("/me");
};
@@ -0,0 +1,26 @@
export interface Competition {
id: string;
title: string;
description: string;
state: CompetitionState;
image_url?: string;
start_date?: Date;
end_date?: Date;
type: CompetitionType;
participation_type: CompetitionParticipationType;
}
export enum CompetitionState {
NOT_STARTED = "not_started",
STARTED = "started",
FINISHED = "finished",
}
export enum CompetitionType {
EDU = "edu",
COMPETITIVE = "competitive",
}
export enum CompetitionParticipationType {
SOLO = "solo",
}
@@ -0,0 +1,5 @@
export interface Reviewer {
id: string;
name: string;
surname: string;
}