Skip to content

Commit

Permalink
add search errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed May 2, 2024
1 parent 64f15dc commit a1056d0
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 30 deletions.
15 changes: 14 additions & 1 deletion docs/schema/V1/schema.verified.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface DialogByIdError {
message: String!
}

interface SearchDialogError {
message: String!
}

type Activity {
id: UUID!
createdAt: DateTime
Expand Down Expand Up @@ -154,11 +158,20 @@ type SearchDialog {
seenSinceLastUpdate: [SeenLog!]!
}

type SearchDialogForbidden implements SearchDialogError {
message: String!
}

type SearchDialogValidationError implements SearchDialogError {
message: String!
}

type SearchDialogsPayload {
items: [SearchDialog!]!
items: [SearchDialog!]
hasNextPage: Boolean!
continuationToken: String
orderBy: String!
errors: [SearchDialogError!]!
}

type SeenLog {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using Digdir.Domain.Dialogporten.GraphQL.EndUser.DialogById;
using Digdir.Domain.Dialogporten.GraphQL.EndUser.SearchDialogs;

namespace Digdir.Domain.Dialogporten.GraphQL.EndUser.Common;



public sealed class Localization
{
public string Value { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Digdir.Domain.Dialogporten.GraphQL.EndUser.Common;
using Digdir.Domain.Dialogporten.GraphQL.EndUser.SearchDialogs;

namespace Digdir.Domain.Dialogporten.GraphQL.EndUser.DialogById;

Expand Down
17 changes: 7 additions & 10 deletions src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@ public async Task<SearchDialogsPayload> SearchDialogs(
SearchDialogInput input,
CancellationToken cancellationToken)
{

var searchDialogQuery = mapper.Map<SearchDialogQuery>(input);

var result = await mediator.Send(searchDialogQuery, cancellationToken);

var searchResultOneOf = result.Match(
paginatedList => paginatedList,
// TODO: Error handling
validationError => throw new NotImplementedException("Validation error"),
forbidden => throw new NotImplementedException("Forbidden"));

var dialogSearchResult = mapper.Map<SearchDialogsPayload>(searchResultOneOf);

return dialogSearchResult;
return result.Match(
mapper.Map<SearchDialogsPayload>,
validationError => new SearchDialogsPayload
{
Errors = [.. validationError.Errors.Select(x => new SearchDialogValidationError { Message = x.ErrorMessage })]
},
forbidden => new SearchDialogsPayload { Errors = [new SearchDialogForbidden()] });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public MappingProfile()
CreateMap<SearchDialogInput, SearchDialogQuery>()
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.Status));

CreateMap<PaginatedList<SearchDialogDto>, SearchDialogsPayload>();
CreateMap<PaginatedList<SearchDialogDto>, SearchDialogsPayload>()
.ForMember(dest => dest.Items, opt => opt.MapFrom(src => src.Items));

CreateMap<SearchDialogDto, SearchDialog>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,50 @@

namespace Digdir.Domain.Dialogporten.GraphQL.EndUser.SearchDialogs;

[InterfaceType("SearchDialogError")]
public interface ISearchDialogError
{
public string Message { get; set; }
}

public sealed class SearchDialogForbidden : ISearchDialogError
{
public string Message { get; set; } = "Forbidden";
}

public sealed class SearchDialogValidationError : ISearchDialogError
{
public string Message { get; set; } = null!;
}

public sealed class SearchDialogsPayload
{
public List<SearchDialog> Items { get; } = [];
public List<SearchDialog>? Items { get; init; }
public bool HasNextPage { get; }
public string? ContinuationToken { get; }
public string OrderBy { get; } = null!;
public List<ISearchDialogError> Errors { get; init; } = [];
}

public sealed class SearchDialog
{
public Guid Id { get; set; }
public string Org { get; set; } = null!;
public string ServiceResource { get; set; } = null!;
public string Party { get; set; } = null!;
public int? Progress { get; set; }
public int? GuiAttachmentCount { get; set; }
public string? ExtendedStatus { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
public DateTimeOffset? DueAt { get; set; }

public DialogStatus Status { get; set; }

public Activity? LatestActivity { get; set; }

public List<Content> Content { get; set; } = [];
public List<SeenLog> SeenSinceLastUpdate { get; set; } = [];
public Guid Id { get; init; }
public string Org { get; init; } = null!;
public string ServiceResource { get; init; } = null!;
public string Party { get; init; } = null!;
public int? Progress { get; init; }
public int? GuiAttachmentCount { get; init; }
public string? ExtendedStatus { get; init; }
public DateTimeOffset CreatedAt { get; init; }
public DateTimeOffset UpdatedAt { get; init; }
public DateTimeOffset? DueAt { get; init; }

public DialogStatus Status { get; init; }

public Activity? LatestActivity { get; init; }

public List<Content> Content { get; init; } = [];
public List<SeenLog> SeenSinceLastUpdate { get; init; } = [];
}

public sealed class SearchDialogInput
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Digdir.Domain.Dialogporten.GraphQL.EndUser;
using Digdir.Domain.Dialogporten.GraphQL.EndUser.DialogById;
using Digdir.Domain.Dialogporten.GraphQL.EndUser.SearchDialogs;
using Digdir.Domain.Dialogporten.Infrastructure.Persistence;

namespace Digdir.Domain.Dialogporten.GraphQL;
Expand All @@ -18,6 +19,8 @@ public static IServiceCollection AddDialogportenGraphQl(
.AddType<DialogByIdDeleted>()
.AddType<DialogByIdNotFound>()
.AddType<DialogByIdForbidden>()
.AddType<SearchDialogValidationError>()
.AddType<SearchDialogForbidden>()
.Services;
}
}

0 comments on commit a1056d0

Please sign in to comment.