feat(country-province-city): add, edit functionality

This commit is contained in:
ghazall-ag
2025-11-17 00:40:53 +03:30
parent 77cc7534a0
commit 7cc442b600
20 changed files with 2008 additions and 280 deletions

50
src/services/cityAPI.js Normal file
View File

@@ -0,0 +1,50 @@
import api from './apiClient';
// -----------------------------
// City API
// -----------------------------
export const cityAPI = {
// GET /api/v1/City (with pagination)
async list(params = {}) {
const { currentPage = 1, pageSize = 10, ...otherParams } = params;
const res = await api.get('/api/v1/City', {
params: { currentPage, pageSize, ...otherParams },
skipAuthRedirect: true
});
return res?.data?.data?.data || [];
},
// POST /api/v1/City
async create(city) {
const payload = {
ProvinceId: city?.provinceId || '',
CityName: String(city?.cityName || ''),
};
const res = await api.post('/api/v1/City', payload, { skipAuthRedirect: true });
return res?.data;
},
// PUT /api/v1/City/{cityId}
async update(cityId, city) {
if (!cityId) {
throw new Error('City ID is required');
}
const payload = {
ProvinceId: city?.provinceId || '',
CityName: String(city?.cityName || '').trim(),
};
console.log('City API Update:', { cityId, payload });
try {
const res = await api.put(`/api/v1/City/${encodeURIComponent(cityId)}`, payload, { skipAuthRedirect: true });
return res?.data;
} catch (error) {
console.error('City API Update Error:', {
cityId,
payload,
error: error?.response?.data || error?.message || error
});
throw error;
}
},
};