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
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Build outputs
bin/
obj/

# Visual Studio / VS Code
.vs/
.vscode/
*.suo
*.user
*.userosscache
*.sln.docstates

# Rider
.idea/
*.sln.iml

# NuGet
*.nupkg
packages/
.nuget/

# Publish and packages
publish/
*.Publish.xml

# Test results
TestResults/
*.trx
*.coverage

# Logs
*.log

# OS files
.DS_Store
Thumbs.db
desktop.ini

# Resharper
_ReSharper*/
*.DotSettings.user

# Generated files
*.generated.cs

# Secrets / local config (opcional)
secrets.json
appsettings.Development.json
17 changes: 17 additions & 0 deletions Library.App/Configurations/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Library.Domain.Intefaces.Repositories;
using Library.Domain.Intefaces.Services;
using Library.Domain.Services;
using Library.Infra.Repositories;

namespace Library.App.Configurations
{
public static class DependencyInjection
{
public static void AddConfigureServices(this IServiceCollection services)
{
services.AddScoped<IBookReposistory, BookRepository>();

services.AddScoped<IBookService, BookService>();
}
}
}
54 changes: 54 additions & 0 deletions Library.App/Controllers/BookController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Library.Domain.Intefaces.Services;
using Library.Domain.Services;
using Library.Shared.Dtos;
using Librery.Shared.Dtos;
using Microsoft.AspNetCore.Mvc;

namespace Library.App.Controllers
{
[ApiController]
[Route("api/books")]
public class BookController : ControllerBase
{
private readonly IBookService _bookService;
public BookController(IBookService bookService)
{
_bookService = bookService;
}

[HttpGet]
public async Task<IActionResult> GetAllBooksAsync([FromQuery] BookFilterDto filterDto)
{
var books = await _bookService.GetAllBooksAsync(filterDto);
if (books == null || !books.Any())
{
return NotFound("No books found.");
}
return Ok(books);
}

[HttpPost("precify")]
public IActionResult PrecifyBooks([FromBody] PrecifierBooksDto ids)
{
var precifiedBooks = _bookService.Precifier(ids);
if (precifiedBooks == null || !precifiedBooks.Any())
{
return NotFound("No books found for the provided IDs.");
}
return Ok(precifiedBooks);
}

[HttpPost("precify/{id:int}")]
public IActionResult GetPrecifiedBook(int id)
{
var result = _bookService.PrecifierOneBook(id);

if (result == null)
return NotFound();

return Ok(result);
}


}
}
30 changes: 30 additions & 0 deletions Library.App/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Acesse https://aka.ms/customizecontainer para saber como personalizar seu contêiner de depuração e como o Visual Studio usa este Dockerfile para criar suas imagens para uma depuração mais rápida.

# Esta fase é usada durante a execução no VS no modo rápido (Padrão para a configuração de Depuração)
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081


# Esta fase é usada para compilar o projeto de serviço
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Library.App/Library.App.csproj", "Library.App/"]
RUN dotnet restore "./Library.App/Library.App.csproj"
COPY . .
WORKDIR "/src/Library.App"
RUN dotnet build "./Library.App.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Esta fase é usada para publicar o projeto de serviço a ser copiado para a fase final
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Library.App.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# Esta fase é usada na produção ou quando executada no VS no modo normal (padrão quando não está usando a configuração de Depuração)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Library.App.dll"]
26 changes: 26 additions & 0 deletions Library.App/Library.App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>cee8c7a5-9994-423f-a122-2a71d08e2243</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Library.Domain\Library.Domain.csproj" />
<ProjectReference Include="..\Library.Infra\Library.Infra.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Mapping\" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Library.App/Library.App.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Library.App_HostAddress = http://localhost:5199

GET {{Library.App_HostAddress}}/weatherforecast/
Accept: application/json

###
25 changes: 25 additions & 0 deletions Library.App/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Library.App.Configurations;
using Microsoft.AspNetCore.Builder;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

builder.Services.AddSwaggerGen();

builder.Services.AddConfigureServices();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();
app.UseRouting();
app.MapControllers();
app.Run();
33 changes: 33 additions & 0 deletions Library.App/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"profiles": {
"http": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5199"
},
"https": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7162;http://localhost:5199"
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "https://json.schemastore.org/launchsettings.json"
}
9 changes: 9 additions & 0 deletions Library.App/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
24 changes: 24 additions & 0 deletions Library.Domain/Entities/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace Library.Domain.Entities
{
public class Book
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("name")]
public string? Name { get; set; }
[JsonPropertyName("price")]
public double Price { get; set; }
[JsonPropertyName("specifications")]
public Specification Specification { get; set; } = new Specification();

public Book()
{

}
}
}
26 changes: 26 additions & 0 deletions Library.Domain/Entities/Specification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Library.Shared.Extensions;
using System.Text.Json.Serialization;

namespace Library.Domain.Entities
{
public class Specification
{
[JsonPropertyName("Originally published")]
public string? OriginallyPublished { get; set; }
[JsonPropertyName("Author")]
public string? Author { get; set; }
[JsonPropertyName("Page count")]
public int PageCount { get; set; }
[JsonPropertyName("Illustrator")]
[JsonConverter(typeof(StringOrArrayConverter))]
public List<string> Illustrator { get; set; } = [];
[JsonPropertyName("Genres")]
[JsonConverter(typeof(StringOrArrayConverter))]
public List<string> Genres { get; set; } = [];

public Specification()
{

}
}
}
16 changes: 16 additions & 0 deletions Library.Domain/Interfaces/Repository/IBookRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Library.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace Library.Domain.Intefaces.Repositories
{
public interface IBookReposistory
{
public IReadOnlyList<Book>? GetAllBooks();

public Book? GetBookById(int id);

}
}
19 changes: 19 additions & 0 deletions Library.Domain/Interfaces/Services/IBookService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Library.Domain.Entities;
using Library.Shared.Dtos;
using Library.Shared.Views;
using Librery.Shared.Dtos;
using System;
using System.Collections.Generic;
using System.Text;

namespace Library.Domain.Intefaces.Services
{
public interface IBookService
{
Task<IReadOnlyList<Book>?> GetAllBooksAsync(BookFilterDto filter);
List<PrecifiedBookView>? Precifier(PrecifierBooksDto ids);

PrecifiedBookView? PrecifierOneBook(int id);
}
}

13 changes: 13 additions & 0 deletions Library.Domain/Library.Domain.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Library.Shared\Library.Shared.csproj" />
</ItemGroup>

</Project>
Loading