Build flashsharp flashcard app
This commit is contained in:
commit
c97759b04c
69 files changed
+6959
No files matched your search
@@ -0,0 +1,63 @@
|
||||
using Flashsharp.Auth;
|
||||
using Flashsharp.Data;
|
||||
using Flashsharp.Domain;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace Flashsharp.Pages;
|
||||
|
||||
public sealed class SearchModel(Store store) : PageModel
|
||||
{
|
||||
public string? Q { get; private set; }
|
||||
|
||||
public string? Tag { get; private set; }
|
||||
|
||||
public long? CourseId { get; private set; }
|
||||
|
||||
public long? LessonId { get; private set; }
|
||||
|
||||
public long? DeckId { get; private set; }
|
||||
|
||||
public string? ScopeName { get; private set; }
|
||||
|
||||
public IReadOnlyList<CardRef> Results { get; private set; } = [];
|
||||
|
||||
public async Task OnGetAsync(
|
||||
string? q,
|
||||
string? tag,
|
||||
long? courseId,
|
||||
long? lessonId,
|
||||
long? deckId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Q = q?.Trim();
|
||||
Tag = tag?.Trim();
|
||||
CourseId = courseId > 0 ? courseId : null;
|
||||
LessonId = lessonId > 0 ? lessonId : null;
|
||||
DeckId = deckId > 0 ? deckId : null;
|
||||
|
||||
if (DeckId is not null)
|
||||
{
|
||||
var deck = await store.GetDeckContextAsync(DeckId.Value, cancellationToken);
|
||||
ScopeName = deck is null ? null : $"{deck.CourseName} / {deck.LessonName} / {deck.Name}";
|
||||
}
|
||||
else if (LessonId is not null)
|
||||
{
|
||||
var lesson = await store.GetLessonAsync(LessonId.Value, User.GetUserId(), cancellationToken);
|
||||
ScopeName = lesson?.Name;
|
||||
}
|
||||
else if (CourseId is not null)
|
||||
{
|
||||
var course = await store.GetCourseAsync(CourseId.Value, User.GetUserId(), cancellationToken);
|
||||
ScopeName = course?.Name;
|
||||
}
|
||||
|
||||
Results = await store.SearchCardsAsync(
|
||||
Q,
|
||||
CourseId,
|
||||
LessonId,
|
||||
DeckId,
|
||||
Tag,
|
||||
50,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user