-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cglotr
committed
Jun 18, 2023
1 parent
afed762
commit b6adc12
Showing
11 changed files
with
121 additions
and
35 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,5 @@ | ||
import type { Fav } from "../types/fav" | ||
|
||
export interface FavApi { | ||
add: (token: string, surah: number, verse: number) => Promise<Fav[]> | ||
} |
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,43 @@ | ||
import type { Fav } from "../types/fav" | ||
import type { FavApi } from './fav_api' | ||
import { getUrl } from '../utils/getUrl' | ||
|
||
export class FavApiImpl implements FavApi { | ||
async add(token: string, surah: number, verse: number): Promise<Fav[]> { | ||
const response = await fetch(getUrl("/fav"), { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
surah, | ||
verse | ||
}), | ||
headers: { | ||
'x-access-token': token, | ||
} | ||
}) | ||
|
||
type Json = { | ||
data: { | ||
favorites: { | ||
id: number | ||
surah: number | ||
verse: number | ||
}[] | ||
} | ||
} | ||
|
||
const json: Json = await response.json() | ||
|
||
return json.data.favorites.map((favorite: { | ||
id: number | ||
surah: number | ||
verse: number | ||
}) => { | ||
const fav: Fav = { | ||
id: favorite.id, | ||
surah: favorite.surah, | ||
verse: favorite.verse | ||
} | ||
return fav | ||
}) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface FavManager { | ||
add: (surahVerse: string) => Promise<Set<string>> | ||
remove: (surahVerse: string) => Promise<Set<string>> | ||
get: () => Promise<Set<string>> | ||
} |
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,23 @@ | ||
import type { FavManager } from "./fav_manager" | ||
|
||
const store: Set<string> = new Set() | ||
|
||
export class FavManagerDummy implements FavManager { | ||
async add(surahVerse: string): Promise<Set<string>> { | ||
store.add(surahVerse) | ||
|
||
return Promise.resolve(new Set(store)) | ||
} | ||
|
||
async remove(surahVerse: string): Promise<Set<string>> { | ||
if (store.has(surahVerse)) { | ||
store.delete(surahVerse) | ||
} | ||
|
||
return Promise.resolve(new Set(store)) | ||
} | ||
|
||
async get(): Promise<Set<string>> { | ||
return Promise.resolve(new Set(store)) | ||
} | ||
} |
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 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 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,5 @@ | ||
export type Fav = { | ||
id: number | ||
surah: number | ||
verse: number | ||
} |
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