Files
bowlingManager/frontend/src/stores/adminStore.js
T
2025-04-17 23:32:39 +09:00

66 lines
1.7 KiB
JavaScript

import { defineStore } from 'pinia';
import axios from 'axios';
export const useAdminStore = defineStore('admin', {
state: () => ({
users: [],
clubs: [],
subscriptions: [],
loading: false,
error: null
}),
actions: {
async fetchUsers() {
try {
this.loading = true;
const response = await axios.get('/api/admin/users', {
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`
}
});
this.users = response.data;
} catch (error) {
this.error = error.response?.data?.message || '사용자 목록을 불러오는데 실패했습니다.';
throw error;
} finally {
this.loading = false;
}
},
async fetchClubs() {
try {
this.loading = true;
const response = await axios.get('/api/admin/clubs', {
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`
}
});
this.clubs = response.data;
} catch (error) {
this.error = error.response?.data?.message || '클럽 목록을 불러오는데 실패했습니다.';
throw error;
} finally {
this.loading = false;
}
},
async fetchSubscriptions() {
try {
this.loading = true;
const response = await axios.get('/api/admin/subscriptions', {
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`
}
});
this.subscriptions = response.data;
} catch (error) {
this.error = error.response?.data?.message || '구독 정보를 불러오는데 실패했습니다.';
throw error;
} finally {
this.loading = false;
}
}
}
});