Skip to content

Commit

Permalink
Fixed quotes from JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Atulin committed Aug 30, 2024
1 parent 17ae78d commit 5b72ecb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Ogma3/Api/V1/Quotes/CreateQuotesFromJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ internal static void CustomizeEndpoint(IEndpointConventionBuilder endpoint)
=> endpoint
.DisableAntiforgery();

public sealed record Query(QuoteDto[] Quotes);

private static async ValueTask<ResponseType> HandleAsync(
QuoteDto[] request,
Query request,
ApplicationDbContext context,
CancellationToken cancellationToken
)
{
var quotes = request.Select(q => new Quote
var quotes = request.Quotes.Select(q => new Quote
{
Body = q.Body,
Author = q.Author,
Expand Down
5 changes: 3 additions & 2 deletions Ogma3/wwwroot/js/generated/paths-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
CommentsControllerPostData,
CreateFaqCommand,
CreateQuoteCommand,
CreateQuotesFromJsonQuery,
CreateRoleCommand,
CreateShelfCommand,
CreateTagCommand,
Expand Down Expand Up @@ -229,9 +230,9 @@ export const PutApiQuotes = async (body: UpdateQuoteCommand, headers?: HeadersIn
options,
);

export const PostApiQuotesJson = async (headers?: HeadersInit, options?: RequestInit) => await typedFetch<number>("/api/quotes/json",
export const PostApiQuotesJson = async (body: CreateQuotesFromJsonQuery, headers?: HeadersInit, options?: RequestInit) => await typedFetch<number>("/api/quotes/json",
'POST',
undefined,
body,
headers,
options,
);
Expand Down
4 changes: 4 additions & 0 deletions Ogma3/wwwroot/js/generated/types-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export interface CreateQuoteCommand {
author: string;
}

export interface CreateQuotesFromJsonQuery {
quotes: object;
}

export interface UpdateQuoteCommand {
id: number;
body: string;
Expand Down
2 changes: 1 addition & 1 deletion Ogma3/wwwroot/js/src/admin/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ new Vue({

// Upload Json
fromJson: async function() {
const res = await createQuotesFromJson(this.json);
const res = await createQuotesFromJson({quotes: this.json});
alert(`Created ${await res.json()} quotes`);
}
},
Expand Down

0 comments on commit 5b72ecb

Please sign in to comment.