feat: refactor room-related services and update API URLs for improved structure and clarity

This commit is contained in:
Rémi 2025-01-06 11:21:05 +01:00
parent dc858227fa
commit de8742437f
9 changed files with 22 additions and 15 deletions

View File

@ -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";

View File

@ -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 }) => {

View File

@ -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`,
}
};

View File

@ -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 };

View 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 };

View File

@ -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;
},

View File

@ -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);
},
}));

View File

@ -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",
},
},