broadcast.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use server";
  2. import { fetchJson } from "@/lib/utils/server";
  3. import { ResultDto } from "@/dtos/response/common";
  4. import { BroadcastInfo, BroadcastListResponse } from "@/types/broadcast";
  5. // 방송 목록 조회 (페이지네이션 지원)
  6. export async function fetchBroadcastList(
  7. page: number = 1,
  8. limit: number = 20
  9. ): Promise<ResultDto<BroadcastListResponse>> {
  10. return await fetchJson<BroadcastListResponse>(`/api/broadcasts?page=${page}&limit=${limit}`, {
  11. method: "GET",
  12. headers: {
  13. Accept: "application/json",
  14. },
  15. });
  16. }
  17. // 인기 방송 목록 조회
  18. export async function fetchPopularBroadcasts(
  19. limit: number = 5
  20. ): Promise<ResultDto<BroadcastInfo[]>> {
  21. return await fetchJson<BroadcastInfo[]>(`/api/broadcasts/popular?limit=${limit}`, {
  22. method: "GET",
  23. headers: {
  24. Accept: "application/json",
  25. },
  26. });
  27. }
  28. // 실시간 방송 목록 조회
  29. export async function fetchLiveBroadcasts(
  30. page: number = 1,
  31. limit: number = 20
  32. ): Promise<ResultDto<BroadcastListResponse>> {
  33. return await fetchJson<BroadcastListResponse>(
  34. `/api/broadcasts/live?page=${page}&limit=${limit}`,
  35. {
  36. method: "GET",
  37. headers: {
  38. Accept: "application/json",
  39. },
  40. }
  41. );
  42. }
  43. // 방송 상세 정보 조회
  44. export async function fetchBroadcastDetail(broadcastId: string): Promise<ResultDto<BroadcastInfo>> {
  45. return await fetchJson<BroadcastInfo>(`/api/broadcasts/${broadcastId}`, {
  46. method: "GET",
  47. headers: {
  48. Accept: "application/json",
  49. },
  50. });
  51. }
  52. // 카테고리별 방송 목록 조회
  53. export async function fetchBroadcastsByCategory(
  54. category: string,
  55. page: number = 1,
  56. limit: number = 20
  57. ): Promise<ResultDto<BroadcastListResponse>> {
  58. return await fetchJson<BroadcastListResponse>(
  59. `/api/broadcasts/category/${category}?page=${page}&limit=${limit}`,
  60. {
  61. method: "GET",
  62. headers: {
  63. Accept: "application/json",
  64. },
  65. }
  66. );
  67. }
  68. // 방송 검색
  69. export async function searchBroadcasts(
  70. query: string,
  71. page: number = 1,
  72. limit: number = 20
  73. ): Promise<ResultDto<BroadcastListResponse>> {
  74. return await fetchJson<BroadcastListResponse>(
  75. `/api/broadcasts/search?q=${encodeURIComponent(query)}&page=${page}&limit=${limit}`,
  76. {
  77. method: "GET",
  78. headers: {
  79. Accept: "application/json",
  80. },
  81. }
  82. );
  83. }