Group FAQs by a topic relation, ordered; drop unused FAQ teaser
This commit is contained in:
1 parent
28944c155a
commit
2ea8856d65
14 files changed
+328
-128
No files matched your search
@@ -313,23 +313,49 @@ public sealed class PocketBaseFixture : IAsyncLifetime
|
||||
title = "Herbstbasar", location = "Schulhof", note = "", @public = true,
|
||||
});
|
||||
|
||||
// Faqs: two topics.
|
||||
// Faq topics: two, ordered. The topics own the grouping and the order the FAQ
|
||||
// page shows the groups in (Mensa before Schließfächer).
|
||||
var lunchTopicId = await CreateRecordAsync(http, "faq_topics", new
|
||||
{
|
||||
title = "Mensa und Mittagessen", slug = "mensa", intro = "",
|
||||
order = 1, @public = true,
|
||||
});
|
||||
var lockerTopicId = await CreateRecordAsync(http, "faq_topics", new
|
||||
{
|
||||
title = "Schließfächer", slug = "schliessfach", intro = "",
|
||||
order = 2, @public = true,
|
||||
});
|
||||
|
||||
// Faqs: each points at its topic through the "topic" relation (the created
|
||||
// topic id), and carries its own order within the topic.
|
||||
await CreateRecordAsync(http, "faqs", new
|
||||
{
|
||||
question = "Wann gibt es Mittagessen?", answer = "Um 12 Uhr.",
|
||||
topic = "Mensa und Mittagessen", @public = true,
|
||||
topic = lunchTopicId, order = 1, @public = true,
|
||||
});
|
||||
await CreateRecordAsync(http, "faqs", new
|
||||
{
|
||||
question = "Wie viel kostet ein Schließfach?", answer = "20 Euro.",
|
||||
topic = "Schließfächer", @public = true,
|
||||
topic = lockerTopicId, order = 1, @public = true,
|
||||
});
|
||||
}
|
||||
|
||||
private static async Task CreateRecordAsync(HttpClient http, string collection, object record)
|
||||
private static async Task<string> CreateRecordAsync(HttpClient http, string collection, object record)
|
||||
{
|
||||
var response = await http.PostAsJsonAsync($"/api/collections/{collection}/records", record);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// Return the created record's id so a caller can seed a relation to it (e.g. a
|
||||
// faq pointing at its topic). Callers that do not need it just ignore the value.
|
||||
var created = await response.Content.ReadFromJsonAsync<CreatedRecord>();
|
||||
return created?.Id ?? throw new InvalidOperationException(
|
||||
$"PocketBase returned no id for the created '{collection}' record.");
|
||||
}
|
||||
|
||||
private sealed record CreatedRecord
|
||||
{
|
||||
[System.Text.Json.Serialization.JsonPropertyName("id")]
|
||||
public string Id { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
private sealed record AuthResponse
|
||||
|
||||
Reference in new issue
Block a user