File size: 3,865 Bytes
d122c3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
 * API Service for Flask Backend Communication
 * Base URL: http://localhost:5000 (proxied via Vite)
 */

import axios from 'axios';

const API_BASE = '/api';

const api = axios.create({
  baseURL: API_BASE,
  headers: {
    'Content-Type': 'application/json',
  },
});

// Types
export interface Hackathon {
  id?: number;
  name: string;
  description: string;
  evaluation_prompt: string;
  criteria?: any[];
  host_email?: string;
  deadline?: string;
  created_at?: string;
}

export interface Submission {
  id?: number;
  hackathon_id: number;
  team_name: string;
  project_name: string;
  code_content?: string;
  documentation_content?: string;
  github_url?: string;
  status?: string;
  created_at?: string;
}

export interface Evaluation {
  id?: number;
  submission_id: number;
  overall_score: number;
  relevance_score: number;
  technical_complexity_score: number;
  creativity_score: number;
  documentation_score: number;
  feedback: string;
  detailed_scores?: string;
  created_at?: string;
}

// Hackathon API
export const hackathonApi = {
  // Get all hackathons
  getAll: async (): Promise<Hackathon[]> => {
    const response = await api.get('/hackathons');
    return response.data;
  },

  // Get single hackathon
  getById: async (id: number): Promise<Hackathon> => {
    const response = await api.get(`/hackathon/${id}`);
    return response.data;
  },

  // Create new hackathon
  create: async (hackathon: Hackathon): Promise<Hackathon> => {
    const response = await api.post('/hackathon', hackathon);
    return response.data;
  },

  // Update hackathon
  update: async (id: number, hackathon: Partial<Hackathon>): Promise<Hackathon> => {
    const response = await api.put(`/hackathon/${id}`, hackathon);
    return response.data;
  },

  // Delete hackathon
  delete: async (id: number): Promise<void> => {
    await api.delete(`/hackathon/${id}`);
  },
};

// Submission API
export const submissionApi = {
  // Get all submissions for a hackathon
  getByHackathon: async (hackathonId: number): Promise<Submission[]> => {
    const response = await api.get(`/hackathon/${hackathonId}/submissions`);
    return response.data;
  },

  // Get single submission
  getById: async (hackathonId: number, submissionId: number): Promise<Submission> => {
    const response = await api.get(`/hackathon/${hackathonId}/submission/${submissionId}`);
    return response.data;
  },

  // Submit with files (multipart/form-data)
  submitWithFiles: async (hackathonId: number, formData: FormData): Promise<Submission> => {
    const response = await api.post(`/hackathon/${hackathonId}/submit`, formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
    return response.data;
  },

  // Submit with GitHub URL
  submitWithGithub: async (hackathonId: number, data: {
    team_name: string;
    project_name: string;
    github_url: string;
  }): Promise<Submission> => {
    const response = await api.post(`/hackathon/${hackathonId}/submit/github`, data);
    return response.data;
  },
};

// Evaluation API
export const evaluationApi = {
  // Get evaluation for a submission
  getBySubmission: async (submissionId: number): Promise<Evaluation> => {
    const response = await api.get(`/submission/${submissionId}/evaluation`);
    return response.data;
  },

  // Get all evaluations for a hackathon (for leaderboard)
  getByHackathon: async (hackathonId: number): Promise<any[]> => {
    const response = await api.get(`/hackathon/${hackathonId}/results`);
    return response.data;
  },

  // Trigger evaluation (if manual trigger is needed)
  triggerEvaluation: async (submissionId: number): Promise<Evaluation> => {
    const response = await api.post(`/submission/${submissionId}/evaluate`);
    return response.data;
  },
};

// Export axios instance for custom requests
export default api;