feat: implement QuestionBank CRUD with pagination and template query
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { API_BASE_URL } from '../utils/constants';
|
||||
import { apiClient } from './apiClient';
|
||||
|
||||
interface AuthResponse {
|
||||
access_token: string;
|
||||
}
|
||||
|
||||
export const authService = {
|
||||
async login(username: string, password: string): Promise<AuthResponse> {
|
||||
const language = localStorage.getItem('userLanguage') || 'ja';
|
||||
const response = await fetch(`${API_BASE_URL}/auth/login`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-user-language': language,
|
||||
},
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.message || 'Login failed');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
},
|
||||
|
||||
|
||||
|
||||
async getProfile(token: string): Promise<any> {
|
||||
const response = await apiClient.request('/auth/profile', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.message || 'Failed to fetch profile');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user