categories.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Generated by orval v7.0.1 🍺
  3. * Do not edit manually.
  4. * OpenAPI definition
  5. * OpenAPI spec version: v0
  6. */
  7. import type {
  8. CategoryRequest,
  9. ResultListCategory,
  10. ResultLong,
  11. ResultVoid,
  12. StatusRequest,
  13. } from "../models";
  14. import { customAxiosInstance } from "../../util/axios-instance";
  15. export const getCategories = () => {
  16. /**
  17. * @summary 修改分类
  18. */
  19. const updateCategory = (id: number, categoryRequest: CategoryRequest) => {
  20. return customAxiosInstance<ResultVoid>({
  21. url: `/admin/categories/${id}`,
  22. method: "PUT",
  23. headers: { "Content-Type": "application/json" },
  24. data: categoryRequest,
  25. });
  26. };
  27. /**
  28. * @summary 启用/禁用分类
  29. */
  30. const toggleCategoryStatus = (id: number, statusRequest: StatusRequest) => {
  31. return customAxiosInstance<ResultVoid>({
  32. url: `/admin/categories/${id}/status`,
  33. method: "PUT",
  34. headers: { "Content-Type": "application/json" },
  35. data: statusRequest,
  36. });
  37. };
  38. /**
  39. * @summary 新增分类
  40. */
  41. const createCategory = (categoryRequest: CategoryRequest) => {
  42. return customAxiosInstance<ResultLong>({
  43. url: `/admin/categories`,
  44. method: "POST",
  45. headers: { "Content-Type": "application/json" },
  46. data: categoryRequest,
  47. });
  48. };
  49. /**
  50. * @summary 获取所有分类列表
  51. */
  52. const listCategories = () => {
  53. return customAxiosInstance<ResultListCategory>({
  54. url: `/categories`,
  55. method: "GET",
  56. });
  57. };
  58. return {
  59. updateCategory,
  60. toggleCategoryStatus,
  61. createCategory,
  62. listCategories,
  63. };
  64. };
  65. export type UpdateCategoryResult = NonNullable<
  66. Awaited<ReturnType<ReturnType<typeof getCategories>["updateCategory"]>>
  67. >;
  68. export type ToggleCategoryStatusResult = NonNullable<
  69. Awaited<ReturnType<ReturnType<typeof getCategories>["toggleCategoryStatus"]>>
  70. >;
  71. export type CreateCategoryResult = NonNullable<
  72. Awaited<ReturnType<ReturnType<typeof getCategories>["createCategory"]>>
  73. >;
  74. export type ListCategoriesResult = NonNullable<
  75. Awaited<ReturnType<ReturnType<typeof getCategories>["listCategories"]>>
  76. >;