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
13 changes: 9 additions & 4 deletions Carbon.Sample.API.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32002.261
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Carbon.Sample.API", "Carbon.Sample.API\Carbon.Sample.API.csproj", "{7F22ED01-F04B-4BA5-987C-951E18B09A86}"
EndProject
Expand All @@ -17,20 +17,25 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CarbonSample-api", "CarbonS
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{5D38D641-82EA-4617-8539-3E09D874F754}"
ProjectSection(SolutionItems) = preProject
helm\CarbonSample-api\templates\_helpers.tpl = helm\CarbonSample-api\templates\_helpers.tpl
helm\CarbonSample-api\templates\configmap.yaml = helm\CarbonSample-api\templates\configmap.yaml
helm\CarbonSample-api\templates\deployment.yaml = helm\CarbonSample-api\templates\deployment.yaml
helm\CarbonSample-api\templates\hpa.yaml = helm\CarbonSample-api\templates\hpa.yaml
helm\CarbonSample-api\templates\ingress.yaml = helm\CarbonSample-api\templates\ingress.yaml
helm\CarbonSample-api\templates\NOTES.txt = helm\CarbonSample-api\templates\NOTES.txt
helm\CarbonSample-api\templates\service.yaml = helm\CarbonSample-api\templates\service.yaml
helm\CarbonSample-api\templates\_helpers.tpl = helm\CarbonSample-api\templates\_helpers.tpl
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Entity-Framework-Migrations", "Entity-Framework-Migrations", "{EEA2E57D-B073-4468-AB48-A9950FD30CB8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Carbon.Sample.API.MSSQL", "Entity-Framework-Migrations\Carbon.Sample.API.MSSQL\Carbon.Sample.API.MSSQL.csproj", "{D66DB63D-EA75-4035-BB98-4D24AD4081F9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carbon.Sample.API.PostgreSQL", "Entity-Framework-Migrations\Carbon.Sample.API.PostgreSQL\Carbon.Sample.API.PostgreSQL.csproj", "{1B266A4F-FFF1-44E1-BFFD-94BE9C20B3B8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Carbon.Sample.API.PostgreSQL", "Entity-Framework-Migrations\Carbon.Sample.API.PostgreSQL\Carbon.Sample.API.PostgreSQL.csproj", "{1B266A4F-FFF1-44E1-BFFD-94BE9C20B3B8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{369D6094-C34A-4AF5-8ACE-F1671080D27D}"
ProjectSection(SolutionItems) = preProject
nuget.config = nuget.config
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
25 changes: 0 additions & 25 deletions Carbon.Sample.API/Application/Consumers/DesiredDataConsumer.cs

This file was deleted.

22 changes: 22 additions & 0 deletions Carbon.Sample.API/Application/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Carbon.WebApplication;
using Carbon.WebApplication.TenantManagementHandler.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Carbon.Sample.API.Infrastructure.Filters;

namespace Carbon.Sample.API.Application.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Route kısmı basede olması sıkıntı olabilir; v1,v2 gibi versiyon bazlı controller ve ya routları yönetmeye başlamamız lazım. Base de olursa hep v1 olarak gidebilir. Bu nedenle route u controller a alıp ilgili kullanımı ile alakalı da ufak bir summary yazarsak süper olur

[Authorize(AuthenticationSchemes = "Bearer")]
[TypeFilter(typeof(BasePropertyBindingActionFilter))]
public abstract class BaseController : CarbonTenantManagedController
{
protected BaseController(List<ISolutionFilteredService> solutionServices,
List<IOwnershipFilteredService> ownershipFilteres)
: base(solutionServices, ownershipFilteres)
{
}
}
}
57 changes: 0 additions & 57 deletions Carbon.Sample.API/Application/Controllers/DataController.cs

This file was deleted.

202 changes: 92 additions & 110 deletions Carbon.Sample.API/Application/Controllers/SampleController.cs
Original file line number Diff line number Diff line change
@@ -1,129 +1,111 @@
using Carbon.PagedList;
using Carbon.Sample.API.Application.Dto;
using Carbon.Sample.API.Application.Dto;
using Carbon.Sample.API.Domain.Services.Abstract;
using Carbon.Sample.API.Infrastructure;
using Carbon.WebApplication;
using Carbon.WebApplication.HttpAtrributes;
using Carbon.WebApplication.TenantManagementHandler.ControllerAttributes;
using Carbon.WebApplication.TenantManagementHandler.Interfaces;

using HybridModelBinding;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;

namespace Carbon.Sample.API.Application.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class SampleController : CarbonTenantManagedController
{
private readonly ISampleService _sampleService;
public SampleController(ISampleService sampleService) : base(new List<ISolutionFilteredService>() { sampleService }, new List<IOwnershipFilteredService>() { sampleService })
{
_sampleService = sampleService;
}
public class SampleController : BaseController
{
private readonly ISampleService _sampleService;

public SampleController(ISampleService sampleService)
: base(new List<ISolutionFilteredService>() { sampleService },
new List<IOwnershipFilteredService>() { sampleService })
{
_sampleService = sampleService;
}

/// <summary>
/// Get all Samples by filter with Get HTTP Method
/// </summary>
/// <param name="tenantId">Tenant Id</param>
/// <param name="sampleFilterDto">Sample Filter</param>
/// <returns>Sample List</returns>
[HttpGetCarbon]
//[Route("GetSamples")]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(IPagedList<SampleDto>), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[SolutionFilter]
[OwnershipFilter("Sample_Read")]
public async Task<IActionResult> GetSamples([FromHeader] Guid tenantId, [FromHybrid] SampleFilterDto sampleFilterDto)
{
if (tenantId == Guid.Empty)
throw new SampleException(ErrorCodes.NoTenantSpecified);
try
{
var Samples = await _sampleService.Filter(sampleFilterDto);
return PagedListOk(Samples);
}
catch (KeyNotFoundException)
{
return NotFound();
}
}

/// <summary>
/// Create Sample
/// </summary>
/// <param name="model">Sample creator model</param>
/// <param name="tenantId">Tenant Id</param>
/// <returns>Created Sample's Id</returns>
[HttpPostCarbon]
//[Route("CreateSample")]
[ProducesResponseType((int)HttpStatusCode.Created)]
[SolutionFilter]
[OwnershipFilter("Sample_Create")]
public async Task<IActionResult> CreateSample([FromBody] SampleCreateDto model, [FromHeader] Guid tenantId)
{
model.TenantId = tenantId;
var result = await _sampleService.CreateAsync(model);
/// <summary>
/// Create Sample
/// </summary>
/// <param name="request">Sample filter model</param>
/// <param name="tenantId">Tenant Id</param>
/// <returns>Created Sample's Id</returns>
[HttpPostCarbon]
[Route("GetAll")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[SolutionFilter]
[OwnershipFilter("Sample_Create")]
public async Task<IActionResult> GetAllAsync([FromBody] SampleFilterDto request)
{
var result = await _sampleService.GetAllAsync(request);
return Ok(result);
}

return CreatedAtAction(nameof(CreateSample), new { id = result.Id }, new { id = result.Id });
}
/// <summary>
/// Create Sample
/// </summary>
/// <param name="request">Sample creator model</param>
/// <param name="tenantId">Tenant Id</param>
/// <returns>Created Sample's Id</returns>
[HttpPostCarbon]
[ProducesResponseType((int)HttpStatusCode.Created)]
[SolutionFilter]
[OwnershipFilter("Sample_Create")]
public async Task<IActionResult> CreateSample([FromBody] SampleCreateDto request)
{
var result = await _sampleService.CreateAsync(request);
return CreatedAtAction(nameof(CreateSample), new { id = result.Id }, new { id = result.Id });
}

/// <summary>
/// Updates Sample
/// </summary>
/// <param name="model">Sample updater model</param>
/// <param name="tenantId">Tenant Id</param>
/// <param name="id">Updated Sample id</param>
/// <returns>Sample's last state</returns>
[HttpPutCarbon]
[Route("{id:Guid}")]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[SolutionFilter]
[OwnershipFilter("Sample_Update")]
public async Task<IActionResult> UpdateSample([FromBody] SampleUpdateDto model, [FromHeader] Guid tenantId, Guid id)
{
model.Id = id;
model.TenantId = tenantId;
var result = await _sampleService.UpdateAsync(model);
return Ok(result);
}
/// <summary>
/// Updates Sample
/// </summary>
/// <param name="model">Sample updater model</param>
/// <param name="tenantId">Tenant Id</param>
/// <param name="id">Updated Sample id</param>
/// <returns>Sample's last state</returns>
[HttpPutCarbon]
[Route("{id:Guid}")]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[SolutionFilter]
[OwnershipFilter("Sample_Update")]
public async Task<IActionResult> UpdateSample([FromBody] SampleUpdateDto model, [FromHeader] Guid tenantId,
Guid id)
{
model.Id = id;
model.TenantId = tenantId;
var result = await _sampleService.UpdateAsync(model);
return Ok(result);
}

/// <summary>
/// Deletes the Sample given by id
/// </summary>
/// <param name="id">Sample id</param>
/// <param name="tenantId">Tenant Id</param>
/// <returns>No Content</returns>
[HttpDeleteCarbon]
[Route("{id:Guid}")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[SolutionFilter]
[OwnershipFilter("Sample_Delete")]
public async Task<IActionResult> DeleteSample([FromBody] SampleDeleteDto model, Guid id, [FromHeader] Guid tenantId)
{
model.Id = id;
model.TenantId = tenantId;
/// <summary>
/// Deletes the Sample given by id
/// </summary>
/// <param name="id">Sample id</param>
/// <param name="tenantId">Tenant Id</param>
/// <returns>No Content</returns>
[HttpDeleteCarbon]
[Route("{id:Guid}")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[SolutionFilter]
[OwnershipFilter("Sample_Delete")]
public async Task<IActionResult> DeleteSample([FromBody] SampleDeleteDto model, Guid id,
[FromHeader] Guid tenantId)
{
model.Id = id;
model.TenantId = tenantId;

try
{
await _sampleService.DeleteAsync(model);
return DeletedOk();
}
catch (SampleException ex)
{
return BadRequest(ex);
}
}
}
}
try
{
await _sampleService.DeleteAsync(model);
return DeletedOk();
}
catch (SampleException ex)
{
return BadRequest(ex);
}
}
}
}
26 changes: 26 additions & 0 deletions Carbon.Sample.API/Application/Dto/Base/BaseRequestPagedDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Carbon.Common;
using Carbon.WebApplication.TenantManagementHandler.Dtos;
using Carbon.WebApplication.TenantManagementHandler.Interfaces;
using Carbon.WebApplication;
using System.Collections.Generic;
using Carbon.Sample.API.Settings.Constants;

namespace Carbon.Sample.API.Application.Dto.Base
{
public abstract class BaseRequestDto<T> : RoleFilteredBaseDto<T>, ISolutionFilteredDto where T : class
{
public ICollection<EntitySolutionRelationDto> RelationalOwners { get; set; }
}
public class BaseRequestPagedDto<T> : BaseRequestDto<T>, IOrderableDto, IPageableDto where T : class
{
public IList<Orderable> Orderables { get; set; }
public int PageSize { get; set; }
public int PageIndex { get; set; }

public BaseRequestPagedDto()
{
PageSize = ApplicationConstant.DefaultPageSize;
PageIndex = ApplicationConstant.DefaultIndex;
}
}
}
Loading