Skip to content

Commit 1653492

Browse files
author
NisanurBulut
committed
controlled profile has already added
1 parent b7bcebf commit 1653492

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

Orhun/src/app/book-list/book-item/book-item.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@ export class BookItemComponent implements OnInit {
1515
constructor(private _profileService: ProfileService, private store: Store<{ profileList: Profile }>) {
1616
}
1717
addToProfile(bookItem: BookItem) {
18-
this._profileService.saveNewProfile(bookItem)
18+
this._profileService.checkProfileExistence(bookItem)
19+
.subscribe(data => {
20+
console.log(Object.entries(data).length);
21+
if (Object.entries(data).length === 0) {
22+
this.saveProfile(bookItem);
23+
}else{
24+
alert('This profile is already attached');
25+
}
26+
});
27+
}
28+
saveProfile(newProfile: BookItem) {
29+
this._profileService.saveNewProfile(newProfile)
1930
.subscribe(data => {
2031
this.store.dispatch(
2132
new profileListActions.AddProfile(data));

Orhun/src/app/db/profile.db.json

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
{
22
"profiles": [
33
{
4-
"profileName": "_oKnzQEACAAJ Profile",
4+
"profileName": "KeteAQAAQBAJ",
55
"bookItem": {
6-
"id": "_oKnzQEACAAJ",
7-
"title": "HARRY POTTER",
8-
"imageLink": "",
9-
"authors": "",
10-
"infoLink": "http://books.google.com.tr/books?id=_oKnzQEACAAJ&dq=harrypotter&hl=&source=gbs_api"
6+
"id": "KeteAQAAQBAJ",
7+
"title": "The Politics of Harry Potter",
8+
"description": "This political analysis of Harry Potter uses the beloved wizarding world to introduce readers to the equally murky and intimidating world of politics. Rowling's work provides us with entries into all of the most important political questions in history, from terrorism and human rights to the classic foundations of political thought.",
9+
"imageLink": "http://books.google.com/books/content?id=KeteAQAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
10+
"authors": "B. Barratt",
11+
"infoLink": "https://play.google.com/store/books/details?id=KeteAQAAQBAJ&source=gbs_api",
12+
"publisher": "Springer"
1113
},
12-
"id": 6
13-
},
14-
{
15-
"profileName": "1PwUEAAAQBAJ Profile",
16-
"bookItem": {
17-
"id": "1PwUEAAAQBAJ",
18-
"title": "Harry Potter 6. Harry Potter ve Melez Prens",
19-
"imageLink": "http://books.google.com/books/content?id=1PwUEAAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
20-
"authors": "J.K Rowling",
21-
"infoLink": "https://play.google.com/store/books/details?id=1PwUEAAAQBAJ&source=gbs_api",
22-
"publisher": " almohreraladbi"
23-
},
24-
"id": 7
14+
"id": 1
2515
}
2616
]
2717
}

Orhun/src/app/profile/profile.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class ProfileComponent implements OnInit {
3030
this._profileService.deleteProfile(profile)
3131
.subscribe(data => {
3232
this.store.dispatch(new profileListActions.DeleteProfile(profile));
33-
this.getProfiles();
3433
});
3534
}
3635
onLoadProfile(profile: Profile) {

Orhun/src/app/profile/profile.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ export class ProfileService {
1010
private profiles: Profile[] = [];
1111
constructor(private _http: HttpClient) { }
1212

13+
checkProfileExistence(book: BookItem): Observable<Profile> {
14+
return this._http.get<Profile>(environment.apiProfileUrl + '?profileName=' + book.id);
15+
}
1316
saveNewProfile(book: BookItem): Observable<Profile> {
14-
const profileName = book.id + ' Profile';
17+
const profileName = book.id;
1518
const profile = new Profile(profileName, book);
1619
return this._http.post<Profile>
1720
(environment.apiProfileUrl, profile);

0 commit comments

Comments
 (0)