Skip to content

Commit 53b68fc

Browse files
committed
update 01-crud
1 parent 8856420 commit 53b68fc

40 files changed

Lines changed: 3966 additions & 18665 deletions

06-rest-api/01-concepts/01-crud/.babelrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

06-rest-api/01-concepts/01-crud/.vscode/launch.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

06-rest-api/01-concepts/01-crud/.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

06-rest-api/01-concepts/01-crud/README.md

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ npm install
1818
npm start
1919
```
2020

21-
- Update `getHotelCollection` api method:
21+
## Update `getHotelCollection` API method
2222

2323
### Fetch version
2424

@@ -50,7 +50,7 @@ export const getHotelCollection = async (): Promise<HotelEntityApi[]> => {
5050
_./src/pods/hotel-collection/api/hotel-collection.api.ts_
5151

5252
```diff
53-
+ import Axios from 'axios';
53+
+ import axios from 'axios';
5454
import { HotelEntityApi } from './hotel-collection.api-model';
5555
import { mockHotelCollection } from './hotel-collection.mock-data';
5656

@@ -59,18 +59,15 @@ let hotelCollection = [...mockHotelCollection];
5959

6060
export const getHotelCollection = async (): Promise<HotelEntityApi[]> => {
6161
- return hotelCollection;
62-
+ const { data } = await Axios.get<HotelEntityApi[]>(url);
62+
+ const { data } = await axios.get<HotelEntityApi[]>(url);
6363
+ return data;
6464
};
6565

6666
...
6767

6868
```
6969

70-
- Update `deleteHotel` api method:
71-
72-
> NOTE: There is an issue with delete method
73-
> Check [issue](https://github.com/typicode/json-server/issues/760)
70+
## Update `deleteHotel` API method
7471

7572
### Fetch version
7673

@@ -85,8 +82,6 @@ const url = '/api/hotels';
8582

8683
...
8784

88-
+ // json-server delete issue: It deletes all collection instead of single one.
89-
+ // https://github.com/typicode/json-server/issues/760
9085
export const deleteHotel = async (id: string): Promise<boolean> => {
9186
- hotelCollection = hotelCollection.filter((h) => h.id !== id);
9287
- return true;
@@ -101,7 +96,7 @@ export const deleteHotel = async (id: string): Promise<boolean> => {
10196
_./src/pods/hotel-collection/api/hotel-collection.api.ts_
10297

10398
```diff
104-
import Axios from 'axios';
99+
import axios from 'axios';
105100
import { HotelEntityApi } from './hotel-collection.api-model';
106101
- import { mockHotelCollection } from './hotel-collection.mock-data';
107102

@@ -110,19 +105,17 @@ const url = '/api/hotels';
110105

111106
...
112107

113-
+ // json-server delete issue: It deletes all collection instead of single one.
114-
+ // https://github.com/typicode/json-server/issues/760
115108
export const deleteHotel = async (id: string): Promise<boolean> => {
116109
- hotelCollection = hotelCollection.filter((h) => h.id !== id);
117-
+ await Axios.delete(`${url}/${id}`);
110+
+ await axios.delete(`${url}/${id}`);
118111
return true;
119112
};
120113

121114
```
122115

123-
- Delete `./src/pods/hotel-collection/api/hotel-collection.mock-data.ts`, not used.
116+
Delete `./src/pods/hotel-collection/api/hotel-collection.mock-data.ts`, not used.
124117

125-
- Update `getHotel` api method:
118+
## Update `getHotel` API method
126119

127120
### Fetch version
128121

@@ -155,7 +148,7 @@ export const getHotel = async (id: string): Promise<Hotel> => {
155148
_./src/pods/hotel/api/hotel.api.ts_
156149

157150
```diff
158-
+ import Axios from 'axios';
151+
+ import axios from 'axios';
159152
import { Hotel } from './hotel.api-model';
160153
import { Lookup } from 'common/models';
161154
- import { mockCities, mockHotelCollection } from './hotel.mock-data';
@@ -165,16 +158,15 @@ import { Lookup } from 'common/models';
165158

166159
export const getHotel = async (id: string): Promise<Hotel> => {
167160
- return mockHotelCollection.find((h) => h.id === id);
168-
+ const { data } = await Axios.get<Hotel>(`${hotelListUrl}/${id}`);
169-
161+
+ const { data } = await axios.get<Hotel>(`${hotelListUrl}/${id}`);
170162
+ return data;
171163
};
172164

173165
...
174166

175167
```
176168

177-
- Update `getCities` api method:
169+
## Update `getCities` API method
178170

179171
### Fetch version
180172

@@ -209,7 +201,7 @@ export const getCities = async (): Promise<Lookup[]> => {
209201
_./src/pods/hotel/api/hotel.api.ts_
210202

211203
```diff
212-
import Axios from 'axios';
204+
import axios from 'axios';
213205
import { Hotel } from './hotel.api-model';
214206
import { Lookup } from 'common/models';
215207
- import { mockCities } from './hotel.mock-data';
@@ -221,16 +213,15 @@ const hotelListUrl = '/api/hotels';
221213

222214
export const getCities = async (): Promise<Lookup[]> => {
223215
- return mockCities;
224-
+ const { data } = await Axios.get<Lookup[]>(cityListUrl);
225-
216+
+ const { data } = await axios.get<Lookup[]>(cityListUrl);
226217
+ return data;
227218
};
228219

229220
...
230221

231222
```
232223

233-
- Update `saveHotel` api method:
224+
## Update `saveHotel` API method
234225

235226
### Fetch version
236227

@@ -271,16 +262,16 @@ _./src/pods/hotel/api/hotel.api.ts_
271262

272263
export const saveHotel = async (hotel: Hotel): Promise<boolean> => {
273264
+ if (hotel.id) {
274-
+ await Axios.put<Hotel>(`${hotelListUrl}/${hotel.id}`, hotel);
265+
+ await axios.put<Hotel>(`${hotelListUrl}/${hotel.id}`, hotel);
275266
+ } else {
276-
+ await Axios.post<Hotel>(hotelListUrl, hotel);
267+
+ await axios.post<Hotel>(hotelListUrl, hotel);
277268
+ }
278269
return true;
279270
};
280271

281272
```
282273

283-
- Delete `./src/pods/hotel/api/hotel.mock-data.ts`, not used.
274+
Delete `./src/pods/hotel/api/hotel.mock-data.ts`, not used.
284275

285276
# About Basefactor + Lemoncode
286277

06-rest-api/01-concepts/01-crud/config/webpack/base.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

06-rest-api/01-concepts/01-crud/config/webpack/dev.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

06-rest-api/01-concepts/01-crud/config/webpack/helpers.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

06-rest-api/01-concepts/01-crud/config/webpack/prod.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

06-rest-api/01-concepts/01-crud/dev.env

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Hotel App</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
<script type="module" src="/src/index.tsx"></script>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)