ilk
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
// src/services/api.js
|
||||
import axios from 'axios'
|
||||
import qs from 'qs'
|
||||
import { useAuthStore } from 'stores/authStore'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:8080/api',
|
||||
timeout: 180000,
|
||||
paramsSerializer: params =>
|
||||
qs.stringify(params, { arrayFormat: 'repeat' })
|
||||
})
|
||||
|
||||
// REQUEST
|
||||
api.interceptors.request.use((config) => {
|
||||
const auth = useAuthStore()
|
||||
const url = config.url || ''
|
||||
|
||||
const isPublic =
|
||||
url.startsWith('/auth/login') ||
|
||||
url.startsWith('/auth/refresh') ||
|
||||
url.startsWith('/password/forgot') ||
|
||||
url.startsWith('/password/reset')
|
||||
|
||||
|
||||
if (!isPublic && auth?.token) {
|
||||
config.headers ||= {}
|
||||
config.headers.Authorization = `Bearer ${auth.token}`
|
||||
}
|
||||
|
||||
return config
|
||||
})
|
||||
|
||||
// RESPONSE
|
||||
let isLoggingOut = false
|
||||
api.interceptors.response.use(
|
||||
r => r,
|
||||
async (error) => {
|
||||
if (error?.response?.status === 401 && !isLoggingOut) {
|
||||
isLoggingOut = true
|
||||
try {
|
||||
useAuthStore().clearSession()
|
||||
} finally {
|
||||
isLoggingOut = false
|
||||
}
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// HELPERS
|
||||
export const get = (u, p = {}, c = {}) =>
|
||||
api.get(u, { params: p, ...c }).then(r => r.data)
|
||||
|
||||
export const post = (u, b = {}, c = {}) =>
|
||||
api.post(u, b, c).then(r => r.data)
|
||||
|
||||
export const put = (u, b = {}, c = {}) =>
|
||||
api.put(u, b, c).then(r => r.data)
|
||||
|
||||
export const del = (u, p = {}, c = {}) =>
|
||||
api.delete(u, { params: p, ...c }).then(r => r.data)
|
||||
|
||||
export const download = (u, p = {}, c = {}) =>
|
||||
api.get(u, { params: p, responseType: 'blob', ...c })
|
||||
.then(r => r.data)
|
||||
|
||||
export default api
|
||||
@@ -0,0 +1,62 @@
|
||||
// src/services/orderService.js
|
||||
import { get, post, put } from './api'
|
||||
|
||||
/**
|
||||
* 🔹 Tek bir siparişi ID’ye göre getirir.
|
||||
* @param {string} id - OrderHeaderID (GUID)
|
||||
*/
|
||||
export async function getOrderById(id) {
|
||||
try {
|
||||
const data = await get(`/order/get/${id}`)
|
||||
return data
|
||||
} catch (err) {
|
||||
console.error('❌ getOrderById hatası:', err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 🔹 Yeni sipariş oluşturur (insert).
|
||||
* Backend: POST /api/order/create
|
||||
* @param {Object} header - Sipariş başlığı (OrderHeader tablosu)
|
||||
* @param {Array} lines - Satırlar (OrderLine tablosu)
|
||||
*/
|
||||
export async function createOrder(header, lines) {
|
||||
const payload = {
|
||||
header,
|
||||
lines,
|
||||
username: header?.CreatedUserName || 'system',
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await post('/order/create', payload)
|
||||
console.log('✅ Sipariş oluşturuldu:', data)
|
||||
return data
|
||||
} catch (err) {
|
||||
console.error('❌ createOrder hatası:', err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 🔹 Mevcut siparişi günceller (update).
|
||||
* Backend: PUT /api/order/update
|
||||
* @param {Object} header - Sipariş başlığı (OrderHeader tablosu)
|
||||
* @param {Array} lines - Satırlar (OrderLine tablosu)
|
||||
*/
|
||||
export async function updateOrder(header, lines) {
|
||||
const payload = {
|
||||
header,
|
||||
lines,
|
||||
username: header?.LastUpdatedUserName || 'system',
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await put('/order/update', payload)
|
||||
console.log('✅ Sipariş güncellendi:', data)
|
||||
return data
|
||||
} catch (err) {
|
||||
console.error('❌ updateOrder hatası:', err.message)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user