Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/Application/Documents/Queries/GetAllDocumentsPaginated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,9 @@ public Validator()
RuleLevelCascadeMode = CascadeMode.Stop;

RuleFor(x => x.RoomId)
.Must((query, roomId) =>
{
if (roomId is null)
{
return query.LockerId is null && query.FolderId is null;
}

if (query.LockerId is null)
{
return query.FolderId is null;
}

return true;
}).WithMessage("Container orientation is not consistent");
.Must((query, roomId) => roomId is null
? query.LockerId is null && query.FolderId is null
: query.LockerId is not null || query.FolderId is null).WithMessage("Container orientation is not consistent");
}
}

Expand Down Expand Up @@ -122,6 +111,12 @@ public async Task<PaginatedList<DocumentDto>> Handle(Query request,

documents = documents.Where(x => x.Folder!.Locker.Room.Id == request.RoomId);
}

if (!(request.SearchTerm is null || request.SearchTerm.Trim().Equals(string.Empty)))
{
documents = documents.Where(x =>
x.Title.ToLower().Contains(request.SearchTerm.ToLower()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trym()

}

var sortBy = request.SortBy ?? nameof(DocumentDto.Id);
var sortOrder = request.SortOrder ?? "asc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public async Task ShouldThrowKeyNotFoundException_WhenOnlyRoomIdAndLockerIdArePr

// Act
var action = async () => await SendAsync(query);

// Assert
await action.Should().ThrowAsync<KeyNotFoundException>("Locker does not exist.");

Expand Down