Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Include a Product entity with pictures for sampling anonymous endpoints and downloading #61

Merged
merged 21 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions src/Content/Backend/Solution/.template.config/ide.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"isVisible": true
},
{
"id": "filesSupport",
"id": "excludeFilesSupport",
"name": {
"text": "Include files support and structure"
"text": "Exclude files support and structure"
},
"isVisible": true
},
Expand Down
62 changes: 52 additions & 10 deletions src/Content/Backend/Solution/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"displayName": "Exclude Common projects",
"description": "Exclude all the Common.* projects from the solution generated"
},
"filesSupport": {
"excludeFilesSupport": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"displayName": "Include files support and structure",
"description": "Include support for Azure BlobStorage and file handling structure"
"displayName": "Exclude files support and structure",
"description": "Exclude support for Azure BlobStorage and file handling structure"
},
"massTransitIntegration": {
"type": "parameter",
Expand Down Expand Up @@ -144,7 +144,9 @@
"**/*.filelist",
"**/*.user",
"**/*.lock.json",
"**/.vs/**/*"
"**/.vs/**/*",
"**/logs/**",
"**/TestResults/**"
],
"modifiers": [
{
Expand All @@ -156,25 +158,43 @@
]
},
{
"condition": "(!filesSupport)",
"condition": "(excludeFilesSupport)",
"exclude": [
"Monaco.Template.Backend.Common.BlobStorage/**/*",
"Monaco.Template.Backend.Common.BlobStorage.Tests/**/*",
"Monaco.Template.Backend.Api/Controllers/FilesController.cs",
"Monaco.Template.Backend.Api/Controllers/ImagesController.cs",
"Monaco.Template.Backend.Api/Controllers/ProductsController.cs",
"Monaco.Template.Backend.Api/DTOs/ProductCreateEditDto.cs",
"Monaco.Template.Backend.Api/DTOs/Extensions/ProductExtensions.cs",
"Monaco.Template.Backend.Application/Features/File/**/*",
"Monaco.Template.Backend.Application/Features/Image/**/*",
"Monaco.Template.Backend.Application/Features/Product/**/*",
"Monaco.Template.Backend.Application/DTOs/Extensions/FileExtensions.cs",
"Monaco.Template.Backend.Application/DTOs/File*.cs",
"Monaco.Template.Backend.Application/DTOs/Extensions/ProductExtensions.cs",
"Monaco.Template.Backend.Application/DTOs/FileDto.cs",
"Monaco.Template.Backend.Application/DTOs/ImageDto.cs",
"Monaco.Template.Backend.Application/DTOs/ProductDto.cs",
"Monaco.Template.Backend.Application/Services/**/*FileService.*",
"Monaco.Template.Backend.Application.Infrastructure/EntityConfigurations/DocumentEntityConfiguration.cs",
"Monaco.Template.Backend.Application.Infrastructure/EntityConfigurations/FileEntityConfiguration.cs",
"Monaco.Template.Backend.Application.Infrastructure/EntityConfigurations/ImageEntityConfiguration.cs",
"Monaco.Template.Backend.Application.Infrastructure/EntityConfigurations/ProductEntityConfiguration.cs",
"Monaco.Template.Backend.Application.Tests/Services/FileServiceTests.cs",
"Monaco.Template.Backend.Application.Tests/Features/File/**/*",
"Monaco.Template.Backend.Application.Tests/Features/Product/**/*",
"Monaco.Template.Backend.Common.Tests/Factories/Entities/DocumentFactory.cs",
"Monaco.Template.Backend.Common.Tests/Factories/Entities/ImageFactory.cs",
"Monaco.Template.Backend.Common.Tests/Factories/Entities/ProductFactory.cs",
"Monaco.Template.Backend.Domain/Model/Document.cs",
"Monaco.Template.Backend.Domain/Model/File.cs",
"Monaco.Template.Backend.Domain/Model/Image.cs"
"Monaco.Template.Backend.Domain/Model/GpsPosition.cs",
"Monaco.Template.Backend.Domain/Model/Image.cs",
"Monaco.Template.Backend.Domain/Model/ImageDimensions.cs",
"Monaco.Template.Backend.Domain/Model/Product.cs",
"Monaco.Template.Backend.Domain.Tests/DocumentTests.cs",
"Monaco.Template.Backend.Domain.Tests/GpsPositionTests.cs",
"Monaco.Template.Backend.Domain.Tests/ImageDimensionsTests.cs",
"Monaco.Template.Backend.Domain.Tests/ImageTests.cs",
"Monaco.Template.Backend.Domain.Tests/ProductTests.cs"
]
},
{
Expand Down Expand Up @@ -550,6 +570,28 @@
"a2689ae3-3643-6250-a748-8f055cc72da8",
"be447a08-0a85-5779-8c65-cf15c2c9a5a8",
"c776f397-182b-6d0d-09f2-4e440dc093d3",
"d8623b90-59c1-4753-a0e6-f2dbd4305c9b"
"d8623b90-59c1-4753-a0e6-f2dbd4305c9b",
"205ad146-f5c4-4e7a-9419-8a2ea73b19d4",
"547e2363-08f5-4f67-9d5a-fed1bc883af8",
"d3d92cbf-7dea-404b-9b3b-e0e01d01b181",
"d10429c7-e0b3-47a9-ad34-a99eb2c1ae0d",
"718b5472-a9bb-4dba-a1c5-e48f8f5020e5",
"fa17826b-1ce9-4ec0-bff5-da0e1754ab7b",
"ab73883d-7755-458c-99b1-daed2e7d1fc7",
"b3df1fee-f37f-4bff-a6e6-b801324228f0",
"e38db072-8687-40eb-a35b-f9c375da1e01",
"83845f6b-6f32-43db-9de3-71299b05a7ee",
"39089091-f930-4d29-b20c-14e2a7a3a861",
"dfe90700-c265-49d6-8cdc-23855b75ef03",
"1c1a942e-ec7d-4312-aa4f-f0a571da0bce",
"6d7fab52-2a08-46ed-8a19-fe27284baa47",
"fc94d7d8-5d72-47e6-a4de-4c1512d71e16",
"6d7a94da-fbb7-4d20-b41c-472bed514830",
"c5d70775-bdc7-4826-93b1-0ba233ed4e7e",
"9b95767e-b8c7-4570-961d-13e8e59aae7c",
"d7b400a1-9455-46e1-8322-10ce0a3cbd07",
"39c225ca-9d35-42f9-b535-f477b40182df",
"54c70413-4884-4178-a662-96440d3dca17",
"f053015e-b577-42fa-9cd1-5b723eecb72c"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ public static class Scopes
{
public const string CompaniesRead = "companies:read";
public const string CompaniesWrite = "companies:write";
#if filesSupport
public const string FilesRead = "files:read";
#if (!excludeFilesSupport)
public const string FilesWrite = "files:write";
#endif
public const string ProductsWrite = "products:write";
#endif

public static List<string> List => new()
{
CompaniesRead,
CompaniesWrite,
#if filesSupport
FilesRead,
FilesWrite
#endif
};
public static List<string> List =>
[
CompaniesRead,
CompaniesWrite,
#if (!excludeFilesSupport)
FilesWrite,
ProductsWrite
#endif
];
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,35 @@ public CompaniesController(IMediator mediator)
_mediator = mediator;
}

/// <summary>
/// Gets a list of companies
/// </summary>
/// <returns></returns>
[HttpGet]
#if (!disableAuth)
[Authorize(Scopes.CompaniesRead)]
#endif
public Task<ActionResult<Page<CompanyDto>>> Get() =>
_mediator.ExecuteQueryAsync(new GetCompanyPage.Query(Request.Query));

/// <summary>
/// Gets a company by Id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.CompaniesRead)]
#endif
public Task<ActionResult<CompanyDto?>> Get(Guid id) =>
_mediator.ExecuteQueryAsync(new GetCompanyById.Query(id));

/// <summary>
/// Creates a new company
/// </summary>
/// <param name="apiVersion"></param>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost]
#if (!disableAuth)
[Authorize(Scopes.CompaniesWrite)]
Expand All @@ -52,6 +67,12 @@ public Task<ActionResult<Guid>> Post([FromRoute] ApiVersion apiVersion, [FromBod
"api/v{0}/Companies/{1}",
apiVersion);

/// <summary>
/// Edits an existing company
/// </summary>
/// <param name="id"></param>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPut("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.CompaniesWrite)]
Expand All @@ -61,6 +82,11 @@ public Task<IActionResult> Put(Guid id, [FromBody] CompanyCreateEditDto dto) =>
ModelState,
ResponseType.NoContent);

/// <summary>
/// Deletes a company
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.CompaniesWrite)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#if filesSupport
#if (!excludeFilesSupport)
#if (!disableAuth)
using Monaco.Template.Backend.Api.Auth;
#endif
using Monaco.Template.Backend.Application.DTOs;
using Monaco.Template.Backend.Application.Features.File;
using Monaco.Template.Backend.Common.Api.Application;
using MediatR;
#if (!disableAuth)
using Microsoft.AspNetCore.Authorization;
#endif
using Microsoft.AspNetCore.Mvc;
using System.Net;
using Asp.Versioning;

namespace Monaco.Template.Backend.Api.Controllers;
Expand All @@ -26,6 +24,12 @@ public FilesController(IMediator mediator)
_mediator = mediator;
}

/// <summary>
/// Uploads a new file that remains as temporal until it is referenced somewhere else in the app
/// </summary>
/// <param name="apiVersion"></param>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost]
#if (!disableAuth)
[Authorize(Scopes.FilesWrite)]
Expand All @@ -35,36 +39,5 @@ public Task<ActionResult<Guid>> Post([FromRoute] ApiVersion apiVersion, [FromFor
ModelState,
"api/v{0}/files/{1}",
apiVersion);

[HttpGet("{id:guid}")]
#if (!disableAuth)
[Authorize(Scopes.FilesRead)]
#endif
public Task<ActionResult<FileDto>> Get(Guid id) =>
_mediator.ExecuteQueryAsync(new GetFileById.Query(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 DownloadFileById.Query(id));

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

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 DeleteFile.Command(id),
ModelState);
}
#endif

This file was deleted.

Loading