feat: refactor room-related services and update API URLs for improved structure and clarity
This commit is contained in:
parent
dc858227fa
commit
de8742437f
@ -11,7 +11,7 @@ import {
|
||||
Divider,
|
||||
TimeInput,
|
||||
} from "@nextui-org/react";
|
||||
import { Room } from "./Room";
|
||||
import { Room } from "../../types/room";
|
||||
import moment from "moment";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { RoomCard } from "./Card";
|
||||
import { Room } from "./Room";
|
||||
import { Room } from "../../types/room";
|
||||
import { SkeletonRoomCard } from "./SkeletonRoomCard";
|
||||
|
||||
export const RoomList = ({ rooms }: { rooms: Room[] | null }) => {
|
||||
|
@ -2,6 +2,9 @@ const NEXT_PUBLIC_API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
export const API_URLS = {
|
||||
class: {
|
||||
all: `${NEXT_PUBLIC_API_URL}/class`,
|
||||
all: `${NEXT_PUBLIC_API_URL}/@me/class`,
|
||||
},
|
||||
room: {
|
||||
all: (classId: string) => `${NEXT_PUBLIC_API_URL}/@me/class/${classId}/rooms`,
|
||||
}
|
||||
};
|
||||
|
@ -3,4 +3,4 @@ import { axiosInstance } from "../lib/axios";
|
||||
|
||||
const getAll = () => axiosInstance.get<Class[]>(API_URLS.class.all);
|
||||
|
||||
export const classService = { getAll };
|
||||
export const classesService = { getAll };
|
7
src/app/services/rooms.service.ts
Normal file
7
src/app/services/rooms.service.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { API_URLS } from "../constants/apiUrl.constant";
|
||||
import { axiosInstance } from "../lib/axios";
|
||||
import { Room } from "../types/room";
|
||||
|
||||
const getAll = (classId: string) => axiosInstance.get<Room[]>(API_URLS.room.all(classId));
|
||||
|
||||
export const roomsService = { getAll };
|
@ -1,5 +1,5 @@
|
||||
import { create } from "zustand";
|
||||
import { classService } from "../services/class.service";
|
||||
import { classesService } from "../services/classes.service";
|
||||
|
||||
type ClassStoreState = {
|
||||
classes: Class[];
|
||||
@ -24,7 +24,7 @@ export const useClassStore = create<ClassStore>()((set) => ({
|
||||
}));
|
||||
},
|
||||
fetchClass: async () => {
|
||||
const classResponse = await classService.getAll();
|
||||
const classResponse = await classesService.getAll();
|
||||
useClassStore.getState()._setClass(classResponse.data);
|
||||
return classResponse.data;
|
||||
},
|
||||
|
@ -1,8 +1,8 @@
|
||||
import moment from "moment";
|
||||
import { create } from "zustand";
|
||||
import { Room } from "../components/Room/Room";
|
||||
import { axiosInstance } from "../lib/axios";
|
||||
import { Room } from "../types/room";
|
||||
import { useUserStore } from "./userStore";
|
||||
import { roomsService } from "../services/rooms.service";
|
||||
|
||||
type RoomStoreState = {
|
||||
future: Room[] | null;
|
||||
@ -37,14 +37,11 @@ export const useRoomStore = create<RoomStore>()((set) => ({
|
||||
);
|
||||
set({ future, actual, past });
|
||||
},
|
||||
fetchRooms: () => {
|
||||
fetchRooms: async () => {
|
||||
const selectedClassId = useUserStore.getState().currentClassId;
|
||||
if (!selectedClassId) return;
|
||||
|
||||
axiosInstance
|
||||
.get<Room[]>(`/@me/class/${selectedClassId}/rooms`)
|
||||
.then((classes) => {
|
||||
useRoomStore.getState()._setRooms(classes.data);
|
||||
});
|
||||
const roomResponse = await roomsService.getAll(selectedClassId);
|
||||
useRoomStore.getState()._setRooms(roomResponse.data);
|
||||
},
|
||||
}));
|
||||
|
@ -19,7 +19,7 @@ export const authOptions: AuthOptions = {
|
||||
authorization: {
|
||||
url: process.env.OAUTH_AUTHORIZATION_URL,
|
||||
params: {
|
||||
scope: "openid email profile offline_access",
|
||||
scope: "openid email profile",
|
||||
response_type: "code",
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user