ready to deployment

This commit is contained in:
2025-08-10 21:50:14 +02:00
commit 1efb04b057
37 changed files with 7379 additions and 0 deletions

38
frontend/src/api/api.js Normal file
View File

@@ -0,0 +1,38 @@
// src/api/api.js
import axios from 'axios'
import router from '@/router'
import { useAuthStore } from '@/stores/authStore'
const api = axios.create({
baseURL: 'http://localhost:8000', // Twój backend
})
// Request interceptor dodawanie tokena
api.interceptors.request.use((config) => {
// const token = localStorage.getItem('token')
// if (token) {
const authStore = useAuthStore()
if (authStore.token) {
config.headers.Authorization = `Bearer ${authStore.token}`
}
return config
})
// Response interceptor obsługa błędów
api.interceptors.response.use(
(response) => response,
(error) => {
const authStore = useAuthStore()
if (error.response && error.response.status === 401) {
authStore.logout()
router.push('/')
// Używamy redirectu bez routera (bo nie zawsze mamy go w tym miejscu)
// window.location.href = '/'
}
return Promise.reject(error)
},
)
export default api

View File

@@ -0,0 +1,11 @@
// src/api/authApi.js
import api from './api'
export const login = async (email, password) => {
const params = new URLSearchParams()
params.append('username', email)
params.append('password', password)
const res = await api.post('/token', params)
return res.data // { access_token: "...", token_type: "bearer" }
}

View File

@@ -0,0 +1,7 @@
// src/api/dataApi.js
import api from './api'
export const getData = async (year, month) => {
const res = await api.get(`/data/${year}/${month}`)
return res.data
}

View File

@@ -0,0 +1,19 @@
import may from '@/assets/may.json'
import june from '@/assets/june.json'
import july from '@/assets/july.json'
export default {
getResponse(month) {
if (!month || typeof month !== 'string' || month.trim() === '' || month === 'lipiec') {
return july
}
if (month === 'czerwiec') {
return june
}
if (month === 'maj') {
return may
}
},
}