Skip to content

Commit

Permalink
feat: add slope api
Browse files Browse the repository at this point in the history
  • Loading branch information
Najeong-Kim committed Nov 2, 2024
1 parent 934b400 commit babd1fa
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/app/mobile/slope/[resortId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import WebcamMobileMapPage from '@/views/slop-status/ui/slop-status-page';

const Page = ({ params }: { params: { resortId: string } }) => {
return <WebcamMobileMapPage resortId={+params.resortId} />;
};

export default Page;
8 changes: 8 additions & 0 deletions src/entities/slope/api/get-slope.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { apiClient } from '@/shared/api/base';
import type { SlopeResponse } from '../model';

export const getSlopes = async (resortId: number): Promise<SlopeResponse> => {
const result = await apiClient.get<SlopeResponse>(`/api/slopes/${resortId}`);

return result;
};
1 change: 1 addition & 0 deletions src/entities/slope/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { slopeQueries } from './query/slope.queries';
13 changes: 13 additions & 0 deletions src/entities/slope/api/query/slope.queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { queryOptions } from '@tanstack/react-query';
import { getSlopes } from '../get-slope';

export const slopeQueries = {
all: () => ['slope'],

slopeQueryKey: (resortId: number) => [...slopeQueries.all(), resortId],
slope: (resortId: number) =>
queryOptions({
queryKey: slopeQueries.slopeQueryKey(resortId),
queryFn: () => getSlopes(resortId),
}),
};
2 changes: 2 additions & 0 deletions src/entities/slope/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as slopeApi from './api';
export * from './model';
1 change: 1 addition & 0 deletions src/entities/slope/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { Slope, Webcam, SlopeResponse } from './model';
26 changes: 26 additions & 0 deletions src/entities/slope/model/model.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export type Slope = {
name: string,
difficulty: string,
isDayOperating: true,
isNightOperating: true,
isLateNightOperating: true,
isDawnOperating: true,
isMidnightOperating: true
}

export type Webcam = {
name: string,
number: 0,
description: string,
url: string
}

export type SlopeResponse = {
dayOperatingHours: string,
nightOperatingHours: string,
lateNightOperatingHours: string,
dawnOperatingHours: string,
midnightOperatingHours: string,
slopes: Slope[],
webcams: Webcam[]
}
14 changes: 12 additions & 2 deletions src/views/slop-status/ui/slop-status-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ import SlopMap from '@/features/slop/ui/slop-map';
import SlopStatusList from '@/features/slop/ui/slop-status-list';
import { slopQueries } from '@/entities/slop/api';
import { RESORT_DOMAIN } from '@/entities/slop/model';
import { slopeApi } from '@/entities/slope';
import { cn } from '@/shared/lib';

const SlopStatusPage = ({ params }: { params: { key: keyof typeof RESORT_DOMAIN } }) => {
const SlopStatusPage = ({
params,
resortId,
}: {
params?: { key: keyof typeof RESORT_DOMAIN };
resortId?: number;
}) => {
const { ref, style, containerRef } = useMapPinch();

const { data } = useQuery(slopQueries.list(params.key));
const { data: slopeData } = useQuery(slopeApi.slopeQueries.slope(resortId ?? 1));
console.log(slopeData);

const { data } = useQuery(slopQueries.list(params?.key ?? 'jisan'));

if (!data) return;

Expand Down

0 comments on commit babd1fa

Please sign in to comment.