Skip to content

Commit

Permalink
Alterada assinatura da interface e repositorio CourseLibrary PagedList
Browse files Browse the repository at this point in the history
  • Loading branch information
suarezrafael committed Aug 13, 2021
1 parent e0faee5 commit ceb17c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
11 changes: 3 additions & 8 deletions CourseLibrary.API/Services/CourseLibraryRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CourseLibrary.API.DbContexts;
using CourseLibrary.API.Entities;
using CourseLibrary.API.Helpers;
using CourseLibrary.API.ResourceParameters;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -123,19 +124,13 @@ public IEnumerable<Author> GetAuthors()
return _context.Authors.ToList<Author>();
}

public IEnumerable<Author> GetAuthors(AuthorsResourceParameters authorsResourceParameters)
public PagedList<Author> GetAuthors(AuthorsResourceParameters authorsResourceParameters)
{
if (authorsResourceParameters == null)
{
throw new ArgumentNullException(nameof(authorsResourceParameters));
}

if (string.IsNullOrWhiteSpace(authorsResourceParameters.MainCategory)
&& string.IsNullOrWhiteSpace(authorsResourceParameters.SearchQuery))
{
return GetAuthors();
}

var collection = _context.Authors as IQueryable<Author>;

if (!string.IsNullOrWhiteSpace(authorsResourceParameters.MainCategory))
Expand All @@ -153,7 +148,7 @@ public IEnumerable<Author> GetAuthors(AuthorsResourceParameters authorsResourceP
|| a.LastName.Contains(searchQuery));
}

return collection.ToList();
return PagedList<Author>.Create(collection, authorsResourceParameters.PageNumber, authorsResourceParameters.PageSize);
}

public IEnumerable<Author> GetAuthors(IEnumerable<Guid> authorIds)
Expand Down
3 changes: 2 additions & 1 deletion CourseLibrary.API/Services/ICourseLibraryRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CourseLibrary.API.Entities;
using CourseLibrary.API.Helpers;
using CourseLibrary.API.ResourceParameters;
using System;
using System.Collections.Generic;
Expand All @@ -13,7 +14,7 @@ public interface ICourseLibraryRepository
void UpdateCourse(Course course);
void DeleteCourse(Course course);
IEnumerable<Author> GetAuthors();
IEnumerable<Author> GetAuthors(AuthorsResourceParameters authorsResourceParameters);
PagedList<Author> GetAuthors(AuthorsResourceParameters authorsResourceParameters);
Author GetAuthor(Guid authorId);
IEnumerable<Author> GetAuthors(IEnumerable<Guid> authorIds);
void AddAuthor(Author author);
Expand Down

0 comments on commit ceb17c7

Please sign in to comment.