Skip to content
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Bb]in
obj
.vscode
[L,l]ogs
*.log
Binary file added CURRiCULO.pdf
Binary file not shown.
25 changes: 25 additions & 0 deletions Classes/DTOs/AdminDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace dorotec_backend_test.Classes.DTOs;

/// <summary> DTO para as informações de um Administrador. </summary>
public class AdminDTO
{
/// <summary></summary>
[JsonIgnore]
public int? Id { get; set; }

/// <summary> Nome pessoal. </summary>
[MaxLength(63)]
public string? Name { get; set; }

/// <summary> Nome de login para o posterior acesso. </summary>
/// <remarks> Deve ser único. </remarks>
[MaxLength(32)]
public string Login { get; set; }

/// <summary> Senha. </summary>
[MaxLength(100)]
public string? Password { get; set; }
}
40 changes: 40 additions & 0 deletions Classes/DTOs/BookDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace dorotec_backend_test.Classes.DTOs;

/// <summary> DTO para os metadados de um livro. </summary>
public class BookDTO
{
/// <summary></summary>
public BookDTO()
{ }

/// <summary></summary>
[JsonIgnore]
public int? Id { get; set; }

/// <summary> Preço do Livro. </summary>
public int? Price { get; set; }

/// <summary> Nome do Livro. </summary>
[MaxLength(123)]
public string? Name { get; set; }

/// <summary> Nome do Autor. </summary>
[MaxLength(123)]
public string? Author { get; set; }

/// <summary> Gênero do Livro. </summary>
[MaxLength(63)]
public string? Genre { get; set; }

/// <summary> Edição da Publicação. </summary>
public int? Edition { get; set; }

/// <summary> Quantidade de Páginas. </summary>
public int? Pages { get; set; }

/// <summary> Data da Publicação. </summary>
public DateTime? PublishDate { get; set; }
}
44 changes: 44 additions & 0 deletions Classes/DTOs/BookFilterDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace dorotec_backend_test.Classes.DTOs;

/// <summary> Informações para a filtragem de uma busca por um ou mais livros. </summary>
public class BookFilterDTO
{
/// <summary> Índice da página. </summary>
[Required]
[DefaultValue(1)]
[Range(1, Int32.MaxValue)]
public int Index { get; set; }

/// <summary> Quantidade de registros por página. </summary>
[Required]
[Range(1, 30)]
[DefaultValue(5)]
public byte Size { get; set; }

/// <summary> Preço mínimo do Livro. </summary>
public int? MinPrice { get; set; }

/// <summary> Preço máximo do Livro. </summary>
public int? MaxPrice { get; set; }

/// <summary> Nome do Livro. </summary>
[MaxLength(123)]
public string? Name { get; set; }

/// <summary> Nome do Autor. </summary>
[MaxLength(123)]
public string? Author { get; set; }

/// <summary> Gênero do Livro. </summary>
[MaxLength(63)]
public string? Genre { get; set; }

/// <summary> Edição da Publicação. </summary>
public int? Edition { get; set; }

/// <summary> Quantidade de Páginas. </summary>
public int? Pages { get; set; }
}
17 changes: 17 additions & 0 deletions Classes/DTOs/LoginDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;

namespace dorotec_backend_test.Classes.DTOs;

/// <summary> DTO para obter acesso de Administrador à aplicação. </summary>
public class LoginDTO
{
/// <summary> Nome único de login. </summary>
[Required]
[MaxLength(32)]
public string Login { get; set; }

/// <summary> Senha. </summary>
[Required]
[MaxLength(100)]
public string Password { get; set; }
}
17 changes: 17 additions & 0 deletions Classes/DTOs/LoginResponseDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace dorotec_backend_test.Classes.DTOs;

/// <summary> Informações de resposta à uma requisição de login. </summary>
public class LoginResponseDTO
{
public LoginResponseDTO(string name, string token)
{
this.Name = name;
this.Token = token;
}

/// <summary> Nome do Administrador. </summary>
public string Name { get; set; }

/// <summary> Token de acesso JWT. </summary>
public string Token { get; set; }
}
16 changes: 16 additions & 0 deletions Classes/Exceptions/CannotDeleteResourceException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace dorotec_backend_test.Classes.Exceptions;

public class CannotDeleteResourceException : Exception
{
public CannotDeleteResourceException()
{
}

public CannotDeleteResourceException(string? message) : base(message)
{
}

public CannotDeleteResourceException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
23 changes: 23 additions & 0 deletions Classes/Exceptions/ResourceAlreadyExistsException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace dorotec_backend_test.Classes.Exceptions;

public class ResourceAlreadyExistsException : Exception
{
public ResourceAlreadyExistsException()
{
}

public ResourceAlreadyExistsException(string? message) : base(message)
{
}

public ResourceAlreadyExistsException(string? message, Exception? innerException) : base(message, innerException)
{
}

public static void Test(){}
}
16 changes: 16 additions & 0 deletions Classes/Exceptions/ResourceNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace dorotec_backend_test.Classes.Exceptions;

public class ResourceNotFoundException : Exception
{
public ResourceNotFoundException()
{
}

public ResourceNotFoundException(string? message) : base(message)
{
}

public ResourceNotFoundException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
16 changes: 16 additions & 0 deletions Classes/Exceptions/UnauthorizedRequestException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace dorotec_backend_test.Classes.Exceptions;

public class UnauthorizedRequestException : Exception
{
public UnauthorizedRequestException()
{
}

public UnauthorizedRequestException(string? message) : base(message)
{
}

public UnauthorizedRequestException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
19 changes: 19 additions & 0 deletions Classes/Mapping/AdminProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using AutoMapper;
using dorotec_backend_test.Classes.DTOs;
using dorotec_backend_test.Models;

namespace dorotec_backend_test.Classes.Mapping;

public class AdminProfile : Profile
{
public AdminProfile()
{
CreateMap<int?, int>()
.ConvertUsing((source, destination) => source ?? destination);

CreateMap<Admin, AdminDTO>()
.ForMember(dto => dto.Password, options => options.Ignore());
CreateMap<AdminDTO, Admin>()
.ForMember(admin => admin.Password, options => options.Ignore());
}
}
20 changes: 20 additions & 0 deletions Classes/Mapping/BookProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using AutoMapper;
using dorotec_backend_test.Classes.DTOs;
using dorotec_backend_test.Models;

namespace dorotec_backend_test.Classes.Mapping;

public class BookProfile : Profile
{
public BookProfile()
{
CreateMap<int?, int>()
.ConvertUsing((source, destination) => source ?? destination);

CreateMap<Book, BookDTO>();
CreateMap<BookDTO, Book>()
.ForMember(member => member.Id, options => options.Ignore())
.ForAllMembers((options => options.Condition((source, destination, sourceValue)
=> sourceValue is not null)));
}
}
21 changes: 21 additions & 0 deletions Classes/Pagination/PageFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace dorotec_backend_test.Classes.Pagination;

public class PageFilter
{
public int PageIndex { get; set; }
public byte Take { get; set; }
public int Skip => (this.PageIndex - 1) * Take;

public PageFilter(int index, byte size)
{
// Nunca menos que 1
this.PageIndex = index < 1
? 1
: index;

// Nunca mais que 20
this.Take = size > (byte)20
? (byte)20
: size;
}
}
42 changes: 42 additions & 0 deletions Classes/Pagination/PageResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace dorotec_backend_test.Classes.Pagination;

public class PageResult<T> where T : class
{
/// <summary> Registros contidos na página. </summary>
public List<T> Data { get; }
private readonly PageFilter Filter;

/// <summary> Índice da página. </summary>
public int PageIndex { get => this.Filter.PageIndex; }

/// <summary> Quantidade de registros por página. </summary>
public int PageSize { get => this.Filter.Take; }

/// <summary> Quantidade total de registros em todas as páginas. </summary>
public long TotalRecords { get; }

/// <summary> Quantidade total de páginas. </summary>
public int TotalPages
{
get => Convert.ToInt32
(
Math.Ceiling(
((double)TotalRecords / (double)this.PageSize))
);
}

public PageResult(List<T> data, int index, byte size, long total)
{
this.Data = data;
this.Filter = new PageFilter(index, size);

this.TotalRecords = total;
}
public PageResult(List<T> data, PageFilter filter, long total)
{
this.Data = data;
this.Filter = filter;

this.TotalRecords = total;
}
}
Loading