Skip to content

Commit

Permalink
FEAT: Upgrade to .NET 8 (#51)
Browse files Browse the repository at this point in the history
## Description
Upgrade solution and projects to target newest .NET 8.0 version.

## Related Issue
Closes #50

## Motivation and Context

## How Has This Been Tested?

## Screenshots (if appropriate):

## Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:
- [X] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [X] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.
- [X] All new and existing tests passed.
  • Loading branch information
CesarD authored Nov 23, 2023
1 parent 3dbe7fc commit 8189723
Show file tree
Hide file tree
Showing 64 changed files with 445 additions and 481 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 8.x
- name: Create package
run: nuget pack src/Monaco.Template.nuspec -OutputDirectory .
- name: Push to NuGet
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Each of the different solution templates also provide some basic business compon

### Supported .NET version:

7.0
8.0

### Installation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#if (!disableAuth)

namespace Monaco.Template.Backend.Api.Auth;

public static class Scopes
{
public const string CompaniesRead = "companies:read";
public const string CompaniesWrite = "companies:write";
#if filesSupport
public const string FilesRead = "files:read";
public const string FilesWrite = "files:write";
public const string FilesRead = "files:read";
public const string FilesWrite = "files:write";
#endif

public static List<string> List => new()
{
CompaniesRead,
CompaniesWrite,
#if filesSupport
FilesRead,
FilesWrite
FilesRead,
FilesWrite
#endif
};
};
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediatR;
using Asp.Versioning;
using MediatR;
#if (!disableAuth)
using Microsoft.AspNetCore.Authorization;
#endif
Expand Down Expand Up @@ -29,42 +30,42 @@ public CompaniesController(IMediator mediator)
}

[HttpGet]
#if (!disableAuth)
#if (!disableAuth)
[Authorize(Scopes.CompaniesRead)]
#endif
#endif
public Task<ActionResult<Page<CompanyDto>>> Get() =>
_mediator.ExecuteQueryAsync(new GetCompanyPageQuery(Request.Query));

[HttpGet("{id:guid}")]
#if (!disableAuth)
#if (!disableAuth)
[Authorize(Scopes.CompaniesRead)]
#endif
#endif
public Task<ActionResult<CompanyDto?>> Get(Guid id) =>
_mediator.ExecuteQueryAsync(new GetCompanyByIdQuery(id));

[HttpPost]
#if (!disableAuth)
#if (!disableAuth)
[Authorize(Scopes.CompaniesWrite)]
#endif
#endif
public Task<ActionResult<Guid>> Post([FromRoute] ApiVersion apiVersion, [FromBody] CompanyCreateEditDto dto) =>
_mediator.ExecuteCommandAsync(dto.MapCreateCommand(),
ModelState,
"api/v{0}/Companies/{1}",
apiVersion);

[HttpPut("{id:guid}")]
#if (!disableAuth)
#if (!disableAuth)
[Authorize(Scopes.CompaniesWrite)]
#endif
#endif
public Task<IActionResult> Put(Guid id, [FromBody] CompanyCreateEditDto dto) =>
_mediator.ExecuteCommandAsync(dto.MapEditCommand(id),
ModelState,
ResponseType.NoContent);

[HttpDelete("{id:guid}")]
#if (!disableAuth)
#if (!disableAuth)
[Authorize(Scopes.CompaniesWrite)]
#endif
#endif
public Task<IActionResult> Delete(Guid id) =>
_mediator.ExecuteCommandAsync(new CompanyDeleteCommand(id),
ModelState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,60 @@
#endif
using Microsoft.AspNetCore.Mvc;
using System.Net;
using Asp.Versioning;

namespace Monaco.Template.Backend.Api.Controllers
{
[Route("api/v{apiVersion:apiVersion}/[controller]")]
[ApiController]
public class FilesController : ControllerBase
{
private readonly IMediator _mediator;
namespace Monaco.Template.Backend.Api.Controllers;

public FilesController(IMediator mediator)
{
_mediator = mediator;
}
[Route("api/v{apiVersion:apiVersion}/[controller]")]
[ApiController]
public class FilesController : ControllerBase
{
private readonly IMediator _mediator;

[HttpPost]
#if (!disableAuth)
[Authorize(Scopes.FilesWrite)]
#endif
public Task<ActionResult<Guid>> Post([FromRoute] ApiVersion apiVersion, [FromForm] IFormFile file) =>
_mediator.ExecuteCommandAsync(new FileCreateCommand(file.OpenReadStream(), file.FileName, file.ContentType),
ModelState,
"api/v{0}/files/{1}",
apiVersion);
public FilesController(IMediator mediator)
{
_mediator = mediator;
}

[HttpGet("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
public Task<ActionResult<FileDto>> Get(Guid id) =>
_mediator.ExecuteQueryAsync(new GetFileByIdQuery(id));
[HttpPost]
#if (!disableAuth)
[Authorize(Scopes.FilesWrite)]
#endif
public Task<ActionResult<Guid>> Post([FromRoute] ApiVersion apiVersion, [FromForm] IFormFile file) =>
_mediator.ExecuteCommandAsync(new FileCreateCommand(file.OpenReadStream(), file.FileName, file.ContentType),
ModelState,
"api/v{0}/files/{1}",
apiVersion);

[HttpGet("{id:guid}/Download")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
[ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Download(Guid id)
{
var result = await _mediator.Send(new DownloadFileByIdQuery(id));
[HttpGet("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
public Task<ActionResult<FileDto>> Get(Guid id) =>
_mediator.ExecuteQueryAsync(new GetFileByIdQuery(id));

if (result == null)
return NotFound();
[HttpGet("{id:guid}/Download")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
[ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Download(Guid id)
{
var result = await _mediator.Send(new DownloadFileByIdQuery(id));

return File(result.FileContent, result.ContentType, result.FileName);
}
if (result == null)
return NotFound();

[HttpDelete("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.FilesWrite)]
#endif
public Task<IActionResult> Delete(Guid id) =>
_mediator.ExecuteCommandAsync(new FileDeleteCommand(id),
ModelState);
return File(result.FileContent, result.ContentType, result.FileName);
}

[HttpDelete("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.FilesWrite)]
#endif
public Task<IActionResult> Delete(Guid id) =>
_mediator.ExecuteCommandAsync(new FileDeleteCommand(id),
ModelState);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,63 @@
using System.Net;
using Monaco.Template.Backend.Common.Api.Application;

namespace Monaco.Template.Backend.Api.Controllers
namespace Monaco.Template.Backend.Api.Controllers;

[Route("api/v{apiVersion:apiVersion}/[controller]")]
[ApiController]
public class ImagesController : ControllerBase
{
[Route("api/v{apiVersion:apiVersion}/[controller]")]
[ApiController]
public class ImagesController : ControllerBase
{
private readonly IMediator _mediator;
private readonly IMediator _mediator;

public ImagesController(IMediator mediator)
{
_mediator = mediator;
}
public ImagesController(IMediator mediator)
{
_mediator = mediator;
}

[HttpGet("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
public Task<ActionResult<ImageDto>> Get(Guid id) =>
_mediator.ExecuteQueryAsync(new GetImageByIdQuery(id));
[HttpGet("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
public Task<ActionResult<ImageDto>> Get(Guid id) =>
_mediator.ExecuteQueryAsync(new GetImageByIdQuery(id));

[HttpGet("{id:guid}/Thumbnail")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
public Task<ActionResult<ImageDto>> GetThumbnail(Guid id) =>
_mediator.ExecuteQueryAsync(new GetThumbnailByImageIdQuery(id));
[HttpGet("{id:guid}/Thumbnail")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
public Task<ActionResult<ImageDto>> GetThumbnail(Guid id) =>
_mediator.ExecuteQueryAsync(new GetThumbnailByImageIdQuery(id));

[HttpGet("{id:guid}/Download")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
[ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Download(Guid id)
{
var result = await _mediator.Send(new DownloadFileByIdQuery(id));
[HttpGet("{id:guid}/Download")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
[ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> Download(Guid id)
{
var result = await _mediator.Send(new DownloadFileByIdQuery(id));

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

return File(result.FileContent, result.ContentType, result.FileName);
}
return File(result.FileContent, result.ContentType, result.FileName);
}

[HttpGet("{id:guid}/Thumbnail/Download")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
[ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> DownloadThumbnail(Guid id)
{
var result = await _mediator.Send(new DownloadThumbnailByImageIdQuery(id));
[HttpGet("{id:guid}/Thumbnail/Download")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
[ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
public async Task<IActionResult> DownloadThumbnail(Guid id)
{
var result = await _mediator.Send(new DownloadThumbnailByImageIdQuery(id));

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

return File(result.FileContent, result.ContentType, result.FileName);
}
}
return File(result.FileContent, result.ContentType, result.FileName);
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
namespace Monaco.Template.Backend.Api.DTOs;

public class CompanyCreateEditDto
{
public string? Name { get; set; }
public string? Email { get; set; }
public string? WebSiteUrl { get; set; }
public string? Street { get; set; }
public string? City { get; set; }
public string? County { get; set; }
public string? PostCode { get; set; }

public Guid? CountryId { get; set; }
}
public record CompanyCreateEditDto(string? Name,
string? Email,
string? WebSiteUrl,
string? Street,
string? City,
string? County,
string? PostCode,
Guid? CountryId);
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Monaco.Template.Backend.Api.DTOs.Extensions;
public static class CompanyExtensions
{
public static CompanyCreateCommand MapCreateCommand(this CompanyCreateEditDto value) =>
new(value.Name,
value.Email,
value.WebSiteUrl,
new(value.Name!,
value.Email!,
value.WebSiteUrl!,
value.Street,
value.City,
value.County,
Expand All @@ -16,9 +16,9 @@ public static CompanyCreateCommand MapCreateCommand(this CompanyCreateEditDto va

public static CompanyEditCommand MapEditCommand(this CompanyCreateEditDto value, Guid id) =>
new(id,
value.Name,
value.Email,
value.WebSiteUrl,
value.Name!,
value.Email!,
value.WebSiteUrl!,
value.Street,
value.City,
value.County,
Expand Down
Loading

0 comments on commit 8189723

Please sign in to comment.