mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-27 11:36:22 +00:00
⚡️ feat: update global styles and color variables for improved theming
refactor: change import paths for DeviceContext and GravatarAvatar components fix: adjust login form API call and update UI text for clarity feat: add post API for listing posts with pagination and filtering options feat: implement BlogCard component for displaying blog posts with enhanced UI feat: create Badge component for consistent styling of labels and indicators refactor: reintroduce DeviceContext with improved functionality for theme and language management feat: define Label and Post models for better type safety and structure
This commit is contained in:
@ -3,12 +3,12 @@ import { camelToSnakeObj, snakeToCamelObj } from "field-conv";
|
||||
|
||||
const API_SUFFIX = "/api/v1";
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
const axiosClient = axios.create({
|
||||
baseURL: API_SUFFIX,
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
axiosInstance.interceptors.request.use((config) => {
|
||||
axiosClient.interceptors.request.use((config) => {
|
||||
if (config.data && typeof config.data === "object") {
|
||||
config.data = camelToSnakeObj(config.data);
|
||||
}
|
||||
@ -18,7 +18,7 @@ axiosInstance.interceptors.request.use((config) => {
|
||||
return config;
|
||||
});
|
||||
|
||||
axiosInstance.interceptors.response.use(
|
||||
axiosClient.interceptors.response.use(
|
||||
(response) => {
|
||||
if (response.data && typeof response.data === "object") {
|
||||
response.data = snakeToCamelObj(response.data);
|
||||
@ -28,4 +28,4 @@ axiosInstance.interceptors.response.use(
|
||||
(error) => Promise.reject(error),
|
||||
);
|
||||
|
||||
export default axiosInstance;
|
||||
export default axiosClient;
|
||||
|
30
web/src/api/post.ts
Normal file
30
web/src/api/post.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import type { BaseResponse } from "@/models/resp";
|
||||
import type { Post } from "@/models/post";
|
||||
import axiosClient from "./client";
|
||||
|
||||
interface ListPostsParams {
|
||||
page?: number;
|
||||
size?: number;
|
||||
orderedBy?: string;
|
||||
reverse?: boolean;
|
||||
keywords?: string;
|
||||
}
|
||||
|
||||
export async function listPosts({
|
||||
page = 1,
|
||||
size = 10,
|
||||
orderedBy = 'updated_at',
|
||||
reverse = false,
|
||||
keywords = ''
|
||||
}: ListPostsParams = {}): Promise<BaseResponse<Post[]>> {
|
||||
const res = await axiosClient.get<BaseResponse<Post[]>>("/post/list", {
|
||||
params: {
|
||||
page,
|
||||
size,
|
||||
orderedBy,
|
||||
reverse,
|
||||
keywords
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}
|
@ -1,56 +1,46 @@
|
||||
import axiosInstance from "./client";
|
||||
|
||||
import axiosClient from "./client";
|
||||
import type { OidcConfig } from "@/models/oidc-config";
|
||||
import type { User } from "@/models/user";
|
||||
import type { BaseResponse } from "@/models/resp";
|
||||
|
||||
export function userLogin(
|
||||
username: string,
|
||||
password: string
|
||||
): Promise<BaseResponse<{ token: string; user: User }>> {
|
||||
return axiosInstance
|
||||
.post<BaseResponse<{ token: string; user: User }>>(
|
||||
"/user/login",
|
||||
{
|
||||
username,
|
||||
password,
|
||||
}
|
||||
)
|
||||
.then(res => res.data);
|
||||
export interface LoginRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
rememberMe?: boolean; // 可以轻松添加新字段
|
||||
captcha?: string;
|
||||
}
|
||||
|
||||
export function userRegister(
|
||||
username: string,
|
||||
password: string,
|
||||
nickname: string,
|
||||
email: string,
|
||||
verificationCode?: string
|
||||
): Promise<BaseResponse<{ token: string; user: User }>> {
|
||||
return axiosInstance
|
||||
.post<BaseResponse<{ token: string; user: User }>>(
|
||||
"/user/register",
|
||||
{
|
||||
username,
|
||||
password,
|
||||
nickname,
|
||||
email,
|
||||
verificationCode,
|
||||
}
|
||||
)
|
||||
.then(res => res.data);
|
||||
export interface RegisterRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
nickname: string;
|
||||
email: string;
|
||||
verificationCode?: string;
|
||||
}
|
||||
|
||||
export function ListOidcConfigs(): Promise<BaseResponse<{ oidcConfigs: OidcConfig[] }>> {
|
||||
return axiosInstance
|
||||
.get<BaseResponse<{ oidcConfigs: OidcConfig[] }>>("/user/oidc/list")
|
||||
.then(res => {
|
||||
const data = res.data;
|
||||
if ('configs' in data) {
|
||||
return {
|
||||
...data,
|
||||
oidcConfigs: data.configs,
|
||||
};
|
||||
}
|
||||
return data;
|
||||
});
|
||||
export async function userLogin(
|
||||
data: LoginRequest
|
||||
): Promise<BaseResponse<{ token: string; user: User }>> {
|
||||
const res = await axiosClient.post<BaseResponse<{ token: string; user: User }>>(
|
||||
"/user/login",
|
||||
data
|
||||
);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
export async function userRegister(
|
||||
data: RegisterRequest
|
||||
): Promise<BaseResponse<{ token: string; user: User }>> {
|
||||
const res = await axiosClient.post<BaseResponse<{ token: string; user: User }>>(
|
||||
"/user/register",
|
||||
data
|
||||
);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
export async function ListOidcConfigs(): Promise<BaseResponse<OidcConfig[]>> {
|
||||
const res = await axiosClient.get<BaseResponse<OidcConfig[]>>(
|
||||
"/user/oidc/list"
|
||||
);
|
||||
return res.data;
|
||||
}
|
Reference in New Issue
Block a user