forked from TryCatchLearn/DatingApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d22ada7
commit 3ddb556
Showing
31 changed files
with
407 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text.Json; | ||
|
||
namespace API.Extensions; | ||
|
||
public static class HttpExtensions | ||
{ | ||
public static void AddPaginationHeader(this HttpResponse response, PaginationHeader header) | ||
{ | ||
var jsonOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; | ||
response.Headers.Add("Pagination", JsonSerializer.Serialize(header, jsonOptions)); | ||
response.Headers.Add("Access-Control-Expose-Headers", "Pagination"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using API.Extensions; | ||
using API.Interfaces; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace API.Helpers; | ||
|
||
public class LogUserActivity : IAsyncActionFilter | ||
{ | ||
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) | ||
{ | ||
var resultContext = await next(); | ||
|
||
if (!resultContext.HttpContext.User.Identity.IsAuthenticated) return; | ||
|
||
var userId = resultContext.HttpContext.User.GetUserId(); | ||
|
||
var repo = resultContext.HttpContext.RequestServices.GetRequiredService<IUserRepository>(); | ||
var user = await repo.GetUserByIdAsync(userId); | ||
user.LastActive = DateTime.UtcNow; | ||
await repo.SaveAllAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace API.Helpers; | ||
|
||
public class PagedList<T> : List<T> | ||
{ | ||
public PagedList(IEnumerable<T> items, int count, int pageNumber, int pageSize) | ||
{ | ||
CurrentPage = pageNumber; | ||
TotalPages = (int)Math.Ceiling(count / (double)pageSize); | ||
PageSize = pageSize; | ||
TotalCount = count; | ||
AddRange(items); | ||
} | ||
|
||
public int CurrentPage { get; set; } | ||
public int TotalPages { get; set; } | ||
public int PageSize { get; set; } | ||
public int TotalCount { get; set; } | ||
|
||
public static async Task<PagedList<T>> CreateAsync(IQueryable<T> source, int pageNumber, int pageSize) | ||
{ | ||
var count = await source.CountAsync(); | ||
var items = await source.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToListAsync(); | ||
return new PagedList<T>(items, count, pageNumber, pageSize); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace API; | ||
|
||
public class PaginationHeader | ||
{ | ||
public PaginationHeader(int currentPage, int itemsPerPage, int totalItems, int totalPages) | ||
{ | ||
CurrentPage = currentPage; | ||
ItemsPerPage = itemsPerPage; | ||
TotalItems = totalItems; | ||
TotalPages = totalPages; | ||
} | ||
|
||
public int CurrentPage { get; set; } | ||
public int ItemsPerPage { get; set; } | ||
public int TotalItems { get; set; } | ||
public int TotalPages { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace API; | ||
|
||
public class UserParams | ||
{ | ||
private const int MaxPageSize = 50; | ||
public int PageNumber { get; set; } = 1; | ||
private int _pageSize = 10; | ||
|
||
public int PageSize | ||
{ | ||
get => _pageSize; | ||
set => _pageSize = (value > MaxPageSize) ? MaxPageSize : value; | ||
} | ||
|
||
public string CurrentUsername { get; set; } | ||
public string Gender { get; set; } | ||
public int MinAge { get; set; } = 18; | ||
public int MaxAge { get; set; } = 100; | ||
public string OrderBy { get; set; } = "lastActive"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface Pagination { | ||
currentPage: number; | ||
itemsPerPage: number; | ||
totalItems: number; | ||
totalPages: number; | ||
} | ||
|
||
export class PaginatedResult<T> { | ||
result?: T; | ||
pagination?: Pagination | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ export interface User { | |
username: string; | ||
token: string; | ||
photoUrl: string; | ||
knownAs: string; | ||
gender: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { User } from "./user"; | ||
|
||
export class UserParams { | ||
gender: string; | ||
minAge = 18; | ||
maxAge = 99; | ||
pageNumber = 1; | ||
pageSize = 5; | ||
orderBy = 'lastActive'; | ||
|
||
constructor(user: User) { | ||
this.gender = user.gender === 'female' ? 'male' : 'female' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.