Skip to content

Commit 4f62ce9

Browse files
committed
Rooms is using Hotels from core.
1 parent 01472a9 commit 4f62ce9

File tree

15 files changed

+113
-33
lines changed

15 files changed

+113
-33
lines changed

apps/backend/src/data.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Hotel, Room } from "hotel-management-shared";
2+
3+
export type BackendHotel = Hotel & {
4+
updateCount: number;
5+
};
6+
7+
export const hotels: BackendHotel[] = [
8+
{ id: 1, name: "City Centre", updateCount: 0 },
9+
{ id: 2, name: "Messe", updateCount: 0 },
10+
{ id: 3, name: "Westend", updateCount: 0 },
11+
];
12+
13+
export type BackendRoom = Room & {
14+
updateCount: number;
15+
};
16+
17+
export const rooms: Record<Hotel["id"], BackendRoom[]> = {
18+
1: [
19+
{ hotelId: 1, id: 1, name: "Left", updateCount: 0 },
20+
{ hotelId: 1, id: 2, name: "Middle", updateCount: 0 },
21+
{ hotelId: 1, id: 3, name: "Center", updateCount: 0 },
22+
],
23+
2: [
24+
{ hotelId: 2, id: 1, name: "Party", updateCount: 0 },
25+
{ hotelId: 2, id: 2, name: "Press", updateCount: 0 },
26+
{ hotelId: 2, id: 3, name: "Wedding", updateCount: 0 },
27+
],
28+
3: [
29+
{ hotelId: 3, id: 1, name: "California", updateCount: 0 },
30+
{ hotelId: 3, id: 2, name: "Oregon", updateCount: 0 },
31+
{ hotelId: 3, id: 3, name: "Washington", updateCount: 0 },
32+
],
33+
};

apps/backend/src/main.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from "node:fs/promises";
22
import cors from "cors";
33
import express from "express";
4-
import { type Hotel } from "hotel-management-shared";
4+
import { hotels, rooms } from "./data";
55

66
const packageJson = JSON.parse(await fs.readFile("./package.json", "utf-8"));
77

@@ -11,20 +11,14 @@ const PORT = 3000;
1111
const app = express();
1212
app.use(cors());
1313

14-
export type BackendHotel = Hotel & {
15-
updateCount: number;
16-
};
17-
18-
const hotels: BackendHotel[] = [
19-
{ id: 1, name: "City Centre", updateCount: 0 },
20-
{ id: 2, name: "Messe", updateCount: 0 },
21-
{ id: 3, name: "Westend", updateCount: 0 },
22-
];
23-
2414
app.get("/hotels", (request, response) => {
2515
response.send(JSON.stringify(hotels));
2616
});
2717

18+
app.get("/rooms/:hotelId", (request, response) => {
19+
response.send(JSON.stringify(rooms[+request.params.hotelId]));
20+
});
21+
2822
app.listen(PORT, () => {
2923
console.info(`${APP_NAME} Listening on port ${PORT}...`);
3024
});

apps/frontend/core/src/components/HotelList.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const props = defineProps<{
88

99
<template>
1010
<ul>
11-
<li v-for="hotel of props.hotels" :key="hotel.id">{{ hotel.name }}</li>
11+
<li v-for="hotel of props.hotels" :key="hotel.id">
12+
<slot name="hotel" v-bind="hotel">{{ hotel.name }}</slot>
13+
</li>
1214
</ul>
1315
</template>

apps/frontend/core/src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import "./assets/main.scss";
22
import { routes } from "./routes";
3+
import HotelList from "./components/HotelList.vue";
4+
import { useHotelsStore } from "./stores/hotels.js";
35

4-
export default {
6+
export {
57
routes,
8+
HotelList,
9+
useHotelsStore
610
};
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ref } from "vue";
21
import { defineStore } from "pinia";
32

43
export const useHotelsStore = defineStore('hotels', () => {
@@ -7,4 +6,4 @@ export const useHotelsStore = defineStore('hotels', () => {
76
};
87

98
return { fetchHotels };
10-
});
9+
});

apps/frontend/luggage/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./assets/main.scss";
22
import { routes } from "./routes";
33

4-
export default {
4+
export {
55
routes,
66
};

apps/frontend/rooms/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"lint": "run -T eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
1818
},
1919
"dependencies": {
20+
"hotel-management-frontend-core": "workspace:apps/frontend/core",
2021
"hotel-management-shared": "workspace:libs/shared"
2122
}
2223
}

apps/frontend/rooms/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./assets/main.scss";
22
import { routes } from "./routes";
33

4-
export default {
4+
export {
55
routes,
66
};
Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
1-
<script setup lang="ts"></script>
1+
<script setup lang="ts">
2+
import { ref } from "vue";
3+
import type { Hotel, Room } from "hotel-management-shared";
4+
import { HotelList, useHotelsStore } from "hotel-management-frontend-core";
5+
import { useRoomsStore } from "../stores/rooms.js";
6+
7+
const loading = ref(true);
8+
9+
const hotelsStore = useHotelsStore();
10+
const hotels = await hotelsStore.fetchHotels();
11+
12+
const roomsStore = useRoomsStore();
13+
const rooms: Record<Hotel["id"], Room[]> = {};
14+
15+
for (const hotel of hotels) {
16+
rooms[hotel.id] = await roomsStore.fetchRoomsForHotel(hotel.id);
17+
}
18+
19+
loading.value = false;
20+
</script>
221

322
<template>
4-
<div class="rooms">
5-
<h1>Rooms</h1>
23+
<div class="rooms" :aria-busy="loading">
24+
<HotelList :hotels="hotels">
25+
<template #hotel="hotel">
26+
<li class="hotel">
27+
<h3 class="hotel-name">{{ hotel.name }}</h3>
28+
<ul>
29+
<li class="room" v-for="room of rooms[hotel.id]" :key="room.id">
30+
<h4>{{ room.name }}</h4>
31+
</li>
32+
</ul>
33+
</li>
34+
</template>
35+
</HotelList>
636
</div>
737
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Hotel } from "hotel-management-shared";
2+
import { defineStore } from "pinia";
3+
4+
export const useRoomsStore = defineStore('rooms', () => {
5+
const fetchRoomsForHotel = async (hotelId: Hotel["id"]) => {
6+
return await (await fetch(`http://localhost:3000/rooms/${hotelId}`)).json();
7+
};
8+
9+
return { fetchRoomsForHotel };
10+
});

0 commit comments

Comments
 (0)