feat(country-province-city): add, edit functionality
This commit is contained in:
50
src/services/cityAPI.js
Normal file
50
src/services/cityAPI.js
Normal 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;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user