post-controller.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Generated by orval v7.0.1 🍺
  3. * Do not edit manually.
  4. * Serve API
  5. * Serve应用接口文档
  6. * OpenAPI spec version: 0.0.1-SNAPSHOT
  7. */
  8. import type {
  9. ListPostsParams,
  10. ListPreviousPostsParams,
  11. PostDto,
  12. ResponseCreatePostVo,
  13. ResponsePageVoListPostVo,
  14. ResponsePostVo,
  15. ResponseVoid,
  16. UpdateHitStatusDto,
  17. UpdateViewCountDto,
  18. } from "./models";
  19. import { customAxiosInstance } from "../util/axios-instance";
  20. export const getPostController = () => {
  21. /**
  22. * @summary 获取帖子详情
  23. */
  24. const getPostDetail = (id: number) => {
  25. return customAxiosInstance<ResponsePostVo>({
  26. url: `/posts/${id}`,
  27. method: "GET",
  28. });
  29. };
  30. /**
  31. * @summary 更新帖子(管理员/本人)
  32. */
  33. const updatePost = (id: number, postDto: PostDto) => {
  34. return customAxiosInstance<ResponseVoid>({
  35. url: `/posts/${id}`,
  36. method: "PUT",
  37. headers: { "Content-Type": "application/json" },
  38. data: postDto,
  39. });
  40. };
  41. /**
  42. * @summary 删除帖子(管理员,逻辑删除)
  43. */
  44. const deletePost = (id: number) => {
  45. return customAxiosInstance<ResponseVoid>({
  46. url: `/posts/${id}`,
  47. method: "DELETE",
  48. });
  49. };
  50. /**
  51. * @summary 修改查看人数(管理员)
  52. */
  53. const updateViewCount = (
  54. id: number,
  55. updateViewCountDto: UpdateViewCountDto,
  56. ) => {
  57. return customAxiosInstance<ResponseVoid>({
  58. url: `/posts/${id}/view-count`,
  59. method: "PUT",
  60. headers: { "Content-Type": "application/json" },
  61. data: updateViewCountDto,
  62. });
  63. };
  64. /**
  65. * @summary 设置命中状态(管理员)
  66. */
  67. const updateHitStatus = (
  68. id: number,
  69. updateHitStatusDto: UpdateHitStatusDto,
  70. ) => {
  71. return customAxiosInstance<ResponseVoid>({
  72. url: `/posts/${id}/hit-status`,
  73. method: "PUT",
  74. headers: { "Content-Type": "application/json" },
  75. data: updateHitStatusDto,
  76. });
  77. };
  78. /**
  79. * @summary 获取帖子列表
  80. */
  81. const listPosts = (params?: ListPostsParams) => {
  82. return customAxiosInstance<ResponsePageVoListPostVo>({
  83. url: `/posts`,
  84. method: "GET",
  85. params,
  86. });
  87. };
  88. /**
  89. * @summary 创建帖子(仅专家/管理员)
  90. */
  91. const createPost = (postDto: PostDto) => {
  92. return customAxiosInstance<ResponseCreatePostVo>({
  93. url: `/posts`,
  94. method: "POST",
  95. headers: { "Content-Type": "application/json" },
  96. data: postDto,
  97. });
  98. };
  99. /**
  100. * @summary 获取专家往期帖子
  101. */
  102. const listPreviousPosts = (
  103. expertId: number,
  104. params?: ListPreviousPostsParams,
  105. ) => {
  106. return customAxiosInstance<ResponsePageVoListPostVo>({
  107. url: `/posts/expert/${expertId}/previous`,
  108. method: "GET",
  109. params,
  110. });
  111. };
  112. return {
  113. getPostDetail,
  114. updatePost,
  115. deletePost,
  116. updateViewCount,
  117. updateHitStatus,
  118. listPosts,
  119. createPost,
  120. listPreviousPosts,
  121. };
  122. };
  123. export type GetPostDetailResult = NonNullable<
  124. Awaited<ReturnType<ReturnType<typeof getPostController>["getPostDetail"]>>
  125. >;
  126. export type UpdatePostResult = NonNullable<
  127. Awaited<ReturnType<ReturnType<typeof getPostController>["updatePost"]>>
  128. >;
  129. export type DeletePostResult = NonNullable<
  130. Awaited<ReturnType<ReturnType<typeof getPostController>["deletePost"]>>
  131. >;
  132. export type UpdateViewCountResult = NonNullable<
  133. Awaited<ReturnType<ReturnType<typeof getPostController>["updateViewCount"]>>
  134. >;
  135. export type UpdateHitStatusResult = NonNullable<
  136. Awaited<ReturnType<ReturnType<typeof getPostController>["updateHitStatus"]>>
  137. >;
  138. export type ListPostsResult = NonNullable<
  139. Awaited<ReturnType<ReturnType<typeof getPostController>["listPosts"]>>
  140. >;
  141. export type CreatePostResult = NonNullable<
  142. Awaited<ReturnType<ReturnType<typeof getPostController>["createPost"]>>
  143. >;
  144. export type ListPreviousPostsResult = NonNullable<
  145. Awaited<ReturnType<ReturnType<typeof getPostController>["listPreviousPosts"]>>
  146. >;