-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ssftvyn/module8-task1
- Loading branch information
Showing
16 changed files
with
257 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ApiService from '../framework/api-service.js'; | ||
import {ApiServiceMethod} from '../const'; | ||
|
||
export default class DestinationsApiService extends ApiService{ | ||
get destinations() { | ||
return this._load({url: 'destinations'}) | ||
.then(ApiService.parseResponse); | ||
} | ||
|
||
async updateDestinations(destination) { | ||
const response = await this._load({ | ||
url: `destinations/${destination.id}`, | ||
method: ApiServiceMethod.PUT, | ||
body: JSON.stringify(destination), | ||
headers: new Headers({'Content-Type': 'application/json'}), | ||
}); | ||
const parsedResponse = await ApiService.parseResponse(response); | ||
return parsedResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ApiService from '../framework/api-service.js'; | ||
import {ApiServiceMethod} from '../const'; | ||
|
||
export default class OffersApiService extends ApiService{ | ||
get offers() { | ||
return this._load({url: 'offers'}) | ||
.then(ApiService.parseResponse); | ||
} | ||
|
||
async updateOffers(offer) { | ||
const response = await this._load({ | ||
url: `offers/${offer.type}`, | ||
method: ApiServiceMethod.PUT, | ||
body: JSON.stringify(offer), | ||
headers: new Headers({'Content-Type': 'application/json'}), | ||
}); | ||
const parsedResponse = await ApiService.parseResponse(response); | ||
return parsedResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import ApiService from '../framework/api-service.js'; | ||
import {ApiServiceMethod} from '../const'; | ||
|
||
export default class PointsApiService extends ApiService{ | ||
get points() { | ||
return this._load({url: 'points'}) | ||
.then(ApiService.parseResponse); | ||
} | ||
|
||
async updatePoint(point) { | ||
const response = await this._load({ | ||
url: `points/${point.id}`, | ||
method: ApiServiceMethod.PUT, | ||
body: JSON.stringify(this.#adaptToServer(point)), | ||
headers: new Headers({'Content-Type': 'application/json'}), | ||
}); | ||
const parsedResponse = await ApiService.parseResponse(response); | ||
return parsedResponse; | ||
} | ||
|
||
#adaptToServer(point) { | ||
const adaptedPoint = {...point, | ||
'base_price': point.price, | ||
'date_from': point.startDate instanceof Date ? point.startDate.toISOString() : null, | ||
'date_to': point.endDate instanceof Date ? point.endDate.toISOString() : null, | ||
'is_favorite': point.isFavorite | ||
}; | ||
|
||
delete adaptedPoint.price; | ||
delete adaptedPoint.startDate; | ||
delete adaptedPoint.endDate; | ||
delete adaptedPoint.isFavorite; | ||
return adaptedPoint; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
import {getDestinations} from '../mock/destinations'; | ||
import {UpdateType} from '../const'; | ||
import Observable from '../framework/observable'; | ||
|
||
export default class DestinationsModel extends Observable{ | ||
#destinations = getDestinations(); | ||
#destinationsApiService = null; | ||
#destinations = []; | ||
constructor({destinationsApiService}) { | ||
super(); | ||
this.#destinationsApiService = destinationsApiService; | ||
} | ||
|
||
get destinations(){ | ||
return this.#destinations; | ||
} | ||
|
||
async init(){ | ||
try{ | ||
this.#destinations = await this.#destinationsApiService.destinations; | ||
} catch (error){ | ||
this.#destinations = null; | ||
} | ||
this._notify(UpdateType.INIT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
import {getOffersByType} from '../mock/offers'; | ||
import {UpdateType} from '../const'; | ||
import Observable from '../framework/observable'; | ||
|
||
export default class OffersModel extends Observable{ | ||
#offers = getOffersByType(); | ||
#offersApiService = null; | ||
#offers = []; | ||
constructor({offersApiService}) { | ||
super(); | ||
this.#offersApiService = offersApiService; | ||
} | ||
|
||
get offers(){ | ||
return this.#offers; | ||
} | ||
|
||
async init(){ | ||
try{ | ||
this.#offers = await this.#offersApiService.offers; | ||
} catch (error){ | ||
this.#offers = null; | ||
} | ||
this._notify(UpdateType.INIT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.