-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api + front): add spaced repetition http service, add new db fie…
…ld, add timezone parsing
- Loading branch information
1 parent
4d9985b
commit 5d49e34
Showing
8 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
apps/front/src/app/shared/http/spaced-repetition.service.ts
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,106 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { HttpClient } from "@angular/common/http"; | ||
import { ApiResponse, ApiResponseOptions, SpacedRepetitionSet } from "@scholarsome/shared"; | ||
import { lastValueFrom } from "rxjs"; | ||
|
||
@Injectable({ | ||
providedIn: "root" | ||
}) | ||
export class SpacedRepetitionService { | ||
constructor(private readonly http: HttpClient) {} | ||
|
||
/** | ||
* Gets a spaced repetition set | ||
* | ||
* @param setId The ID of the set corresponding to the spaced repetition set | ||
* | ||
* @returns `SpacedRepetitionSet` object | ||
*/ | ||
async spacedRepetitionSet(setId: string): Promise<SpacedRepetitionSet | null> { | ||
let spacedRepetitionSet: ApiResponse<SpacedRepetitionSet> | undefined; | ||
|
||
try { | ||
spacedRepetitionSet = await lastValueFrom(this.http.get<ApiResponse<SpacedRepetitionSet>>("/api/spaced-repetition/sets/" + setId)); | ||
} catch (e) { | ||
return null; | ||
} | ||
|
||
if (spacedRepetitionSet.status === ApiResponseOptions.Success) { | ||
return spacedRepetitionSet.data; | ||
} else return null; | ||
} | ||
|
||
/** | ||
* Creates a spaced repetition set | ||
* | ||
* @param setId The ID of the set corresponding to the spaced repetition set | ||
* | ||
* @returns Created `Folder` object | ||
*/ | ||
async createSpacedRepetitionSets(setId: string): Promise<SpacedRepetitionSet | null> { | ||
let spacedRepetitionSet: ApiResponse<SpacedRepetitionSet> | undefined; | ||
|
||
try { | ||
spacedRepetitionSet = await lastValueFrom(this.http.post<ApiResponse<SpacedRepetitionSet>>("/api/spaced-repetition/sets/" + setId, {})); | ||
} catch (e) { | ||
return null; | ||
} | ||
|
||
if (spacedRepetitionSet.status === ApiResponseOptions.Success) { | ||
return spacedRepetitionSet.data; | ||
} else return null; | ||
} | ||
|
||
/** | ||
* Updates a spaced repetition set | ||
* | ||
* @param body.id ID of the folder to be updated | ||
* @param body.title Optional, title of the folder | ||
* @param body.description Optional, description of the folder | ||
* @param body.private Optional, whether the folder should be publicly visible | ||
* @param body.sets Optional, array of the sets that should be within the folder | ||
* | ||
* @returns Updated `Folder` object | ||
*/ | ||
async updateFolder(body: { | ||
id: string; | ||
cardsPerDay?: number; | ||
answerWith?: "TERM" | "DEFINITION" | ||
}): Promise<SpacedRepetitionSet | null> { | ||
let spacedRepetitionSet: ApiResponse<SpacedRepetitionSet> | undefined; | ||
|
||
try { | ||
spacedRepetitionSet = await lastValueFrom(this.http.patch<ApiResponse<SpacedRepetitionSet>>("/api/spaced-repetition/sets/" + body.id, { | ||
cardsPerDay: body.cardsPerDay, | ||
answerWith: body.answerWith | ||
})); | ||
} catch (e) { | ||
return null; | ||
} | ||
|
||
if (spacedRepetitionSet.status === ApiResponseOptions.Success) { | ||
return spacedRepetitionSet.data; | ||
} else return null; | ||
} | ||
|
||
/** | ||
* Deletes a spaced repetition set | ||
* | ||
* @param setId The ID of the set corresponding to the spaced repetition set | ||
* | ||
* @returns Deleted `SpacedRepetitionSet` object | ||
*/ | ||
async deleteSpacedRepetitionSet(setId: string): Promise<SpacedRepetitionSet | null> { | ||
let spacedRepetitionSet: ApiResponse<SpacedRepetitionSet> | undefined; | ||
|
||
try { | ||
spacedRepetitionSet = await lastValueFrom(this.http.delete<ApiResponse<SpacedRepetitionSet>>("/api/spaced-repetition/sets/" + setId)); | ||
} catch (e) { | ||
return null; | ||
} | ||
|
||
if (spacedRepetitionSet.status === ApiResponseOptions.Success) { | ||
return spacedRepetitionSet.data; | ||
} else return null; | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240415211702_add_field_last_studied_at/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE `SpacedRepetitionCard` ADD COLUMN `lastStudiedAt` DATETIME(3) NOT NULL DEFAULT '1970-01-01T00:00:01+00:00'; |
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