diff --git a/Carbon.Sample.API.sln b/Carbon.Sample.API.sln index 3aa1170..6663508 100644 --- a/Carbon.Sample.API.sln +++ b/Carbon.Sample.API.sln @@ -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 @@ -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 diff --git a/Carbon.Sample.API/Application/Consumers/DesiredDataConsumer.cs b/Carbon.Sample.API/Application/Consumers/DesiredDataConsumer.cs deleted file mode 100644 index 86ad071..0000000 --- a/Carbon.Sample.API/Application/Consumers/DesiredDataConsumer.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Carbon.Sample.API.Application.Dto; -using Carbon.Sample.API.Domain.Services.Abstract; - -using MassTransit; - -using Serilog; - -using System.Threading.Tasks; - -namespace Carbon.Sample.API.Application.Consumers -{ - public class DesiredDataConsumer : IConsumer - { - private readonly IDataService _dataService; - public DesiredDataConsumer(IDataService dataService) - { - _dataService = dataService; - } - public async Task Consume(ConsumeContext context) - { - Log.Information($"Deisred Data Requested: AssetID:{context.Message.AssetId} - CorrelationId:{context.Message.CorrelationId}"); - await _dataService.SetDesiredTelemetryValueOnDataLog(context.Message.AssetId, context.Message.TelemetryId, context.Message.Value); - } - } -} diff --git a/Carbon.Sample.API/Application/Controllers/BaseController.cs b/Carbon.Sample.API/Application/Controllers/BaseController.cs new file mode 100644 index 0000000..d01098c --- /dev/null +++ b/Carbon.Sample.API/Application/Controllers/BaseController.cs @@ -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]")] + [Authorize(AuthenticationSchemes = "Bearer")] + [TypeFilter(typeof(BasePropertyBindingActionFilter))] + public abstract class BaseController : CarbonTenantManagedController + { + protected BaseController(List solutionServices, + List ownershipFilteres) + : base(solutionServices, ownershipFilteres) + { + } + } +} \ No newline at end of file diff --git a/Carbon.Sample.API/Application/Controllers/DataController.cs b/Carbon.Sample.API/Application/Controllers/DataController.cs deleted file mode 100644 index 3b5b57a..0000000 --- a/Carbon.Sample.API/Application/Controllers/DataController.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Carbon.Sample.API.Application.Dto; -using Carbon.Sample.API.Domain.Services.Abstract; -using Carbon.WebApplication; -using Carbon.WebApplication.HttpAtrributes; - -using HybridModelBinding; - -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -using System; -using System.Threading.Tasks; - -namespace Carbon.Sample.API.Application.Controllers -{ - [Route("api/v1/[controller]")] - [ApiController] - [Authorize(AuthenticationSchemes = "Bearer")] - public class DataController : CarbonController - { - private readonly IDataService _dataService; - - public DataController(IDataService dataService) - { - _dataService = dataService; - } - - /// - /// Temporary Action to test and valid the business - /// - /// Carbon sets tenantId from Authorization header automatically - /// - /// - [HttpGetCarbon] - [Route("{assetId:Guid}/telemetry/{telemetryId:Guid}")] - public async Task GetLatestData([FromHybrid] GetLatestDataDto getLatestDataDto, [FromHeader] Guid tenantId) - { - var result = await _dataService.GetLatestDataByAssetAndTelemetryId(getLatestDataDto.AssetId, getLatestDataDto.TelemetryId, tenantId); - - return ResponseOk(result); - } - - /// - /// ModelContainer calls this method to send a desired telemetry value - /// - /// - /// - [HttpPostCarbon] - [Route("SendDesiredTelemetryDataToP360")] - public async Task SendDesiredTelemetryDataToP360([FromHybrid] DesiredDataDto desiredDataDto) - { - var resp = await _dataService.SetDesiredTelemetryValueOnDataLog(desiredDataDto.AssetId, desiredDataDto.TelemetryId, desiredDataDto.Value); - return ResponseOk(resp); - } - - } -} diff --git a/Carbon.Sample.API/Application/Controllers/SampleController.cs b/Carbon.Sample.API/Application/Controllers/SampleController.cs index 03dfce9..59573d1 100644 --- a/Carbon.Sample.API/Application/Controllers/SampleController.cs +++ b/Carbon.Sample.API/Application/Controllers/SampleController.cs @@ -1,17 +1,10 @@ -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; @@ -19,111 +12,100 @@ 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() { sampleService }, new List() { sampleService }) - { - _sampleService = sampleService; - } + public class SampleController : BaseController + { + private readonly ISampleService _sampleService; + + public SampleController(ISampleService sampleService) + : base(new List() { sampleService }, + new List() { sampleService }) + { + _sampleService = sampleService; + } - /// - /// Get all Samples by filter with Get HTTP Method - /// - /// Tenant Id - /// Sample Filter - /// Sample List - [HttpGetCarbon] - //[Route("GetSamples")] - [ProducesResponseType((int)HttpStatusCode.NotFound)] - [ProducesResponseType(typeof(IPagedList), (int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [SolutionFilter] - [OwnershipFilter("Sample_Read")] - public async Task 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(); - } - } - /// - /// Create Sample - /// - /// Sample creator model - /// Tenant Id - /// Created Sample's Id - [HttpPostCarbon] - //[Route("CreateSample")] - [ProducesResponseType((int)HttpStatusCode.Created)] - [SolutionFilter] - [OwnershipFilter("Sample_Create")] - public async Task CreateSample([FromBody] SampleCreateDto model, [FromHeader] Guid tenantId) - { - model.TenantId = tenantId; - var result = await _sampleService.CreateAsync(model); + /// + /// Create Sample + /// + /// Sample filter model + /// Tenant Id + /// Created Sample's Id + [HttpPostCarbon] + [Route("GetAll")] + [ProducesResponseType((int)HttpStatusCode.OK)] + [SolutionFilter] + [OwnershipFilter("Sample_Create")] + public async Task 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 }); - } + /// + /// Create Sample + /// + /// Sample creator model + /// Tenant Id + /// Created Sample's Id + [HttpPostCarbon] + [ProducesResponseType((int)HttpStatusCode.Created)] + [SolutionFilter] + [OwnershipFilter("Sample_Create")] + public async Task CreateSample([FromBody] SampleCreateDto request) + { + var result = await _sampleService.CreateAsync(request); + return CreatedAtAction(nameof(CreateSample), new { id = result.Id }, new { id = result.Id }); + } - /// - /// Updates Sample - /// - /// Sample updater model - /// Tenant Id - /// Updated Sample id - /// Sample's last state - [HttpPutCarbon] - [Route("{id:Guid}")] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType((int)HttpStatusCode.OK)] - [SolutionFilter] - [OwnershipFilter("Sample_Update")] - public async Task UpdateSample([FromBody] SampleUpdateDto model, [FromHeader] Guid tenantId, Guid id) - { - model.Id = id; - model.TenantId = tenantId; - var result = await _sampleService.UpdateAsync(model); - return Ok(result); - } + /// + /// Updates Sample + /// + /// Sample updater model + /// Tenant Id + /// Updated Sample id + /// Sample's last state + [HttpPutCarbon] + [Route("{id:Guid}")] + [ProducesResponseType((int)HttpStatusCode.BadRequest)] + [ProducesResponseType((int)HttpStatusCode.OK)] + [SolutionFilter] + [OwnershipFilter("Sample_Update")] + public async Task UpdateSample([FromBody] SampleUpdateDto model, [FromHeader] Guid tenantId, + Guid id) + { + model.Id = id; + model.TenantId = tenantId; + var result = await _sampleService.UpdateAsync(model); + return Ok(result); + } - /// - /// Deletes the Sample given by id - /// - /// Sample id - /// Tenant Id - /// No Content - [HttpDeleteCarbon] - [Route("{id:Guid}")] - [ProducesResponseType((int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [SolutionFilter] - [OwnershipFilter("Sample_Delete")] - public async Task DeleteSample([FromBody] SampleDeleteDto model, Guid id, [FromHeader] Guid tenantId) - { - model.Id = id; - model.TenantId = tenantId; + /// + /// Deletes the Sample given by id + /// + /// Sample id + /// Tenant Id + /// No Content + [HttpDeleteCarbon] + [Route("{id:Guid}")] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest)] + [SolutionFilter] + [OwnershipFilter("Sample_Delete")] + public async Task 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); + } + } + } +} \ No newline at end of file diff --git a/Carbon.Sample.API/Application/Dto/Base/BaseRequestPagedDto.cs b/Carbon.Sample.API/Application/Dto/Base/BaseRequestPagedDto.cs new file mode 100644 index 0000000..f1cc03f --- /dev/null +++ b/Carbon.Sample.API/Application/Dto/Base/BaseRequestPagedDto.cs @@ -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 : RoleFilteredBaseDto, ISolutionFilteredDto where T : class + { + public ICollection RelationalOwners { get; set; } + } + public class BaseRequestPagedDto : BaseRequestDto, IOrderableDto, IPageableDto where T : class + { + public IList Orderables { get; set; } + public int PageSize { get; set; } + public int PageIndex { get; set; } + + public BaseRequestPagedDto() + { + PageSize = ApplicationConstant.DefaultPageSize; + PageIndex = ApplicationConstant.DefaultIndex; + } + } +} diff --git a/Carbon.Sample.API/Application/Dto/Base/Paged.cs b/Carbon.Sample.API/Application/Dto/Base/Paged.cs new file mode 100644 index 0000000..c9a5e40 --- /dev/null +++ b/Carbon.Sample.API/Application/Dto/Base/Paged.cs @@ -0,0 +1,24 @@ +using Carbon.PagedList; +using System.Collections.Generic; + +namespace Carbon.Sample.API.Application.Dto.Base +{ + public class Paged : IPagedList + { + public int TotalPageCount { get; set; } + public int TotalCount { get; set; } + public int FilteredCount { get; set; } + public int PageIndex { get; set; } + public ICollection List { get; set; } + public int PageCount { get; set; } + public int TotalItemCount { get; set; } + public int PageNumber { get; set; } + public int PageSize { get; set; } + public bool HasPreviousPage { get; set; } + public bool HasNextPage { get; set; } + public bool IsFirstPage { get; set; } + public bool IsLastPage { get; set; } + public int FirstItemOnPage { get; set; } + public int LastItemOnPage { get; set; } + } +} diff --git a/Carbon.Sample.API/Application/Dto/LatestDataDto.cs b/Carbon.Sample.API/Application/Dto/LatestDataDto.cs deleted file mode 100644 index 4c0c299..0000000 --- a/Carbon.Sample.API/Application/Dto/LatestDataDto.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Carbon.Sample.API.Domain.Entities; - -using System; - -namespace Carbon.Sample.API.Application.Dto -{ - public class LatestDataDto - { - public Guid AssetId { get; set; } - public String AssetName { get; set; } - public Guid TelemetryId { get; set; } - public String TelemetryName { get; set; } - public string ContainerId { get; set; } - public Guid SensorId { get; set; } - public decimal Value { get; set; } - public string ValueAsStr { get; set; } - public DataType DataType { get; set; } - public DateTime Date { get; set; } - public Guid TenantId { get; set; } - } -} diff --git a/Carbon.Sample.API/Application/Dto/SampleCreateDto.cs b/Carbon.Sample.API/Application/Dto/SampleCreateDto.cs index e177288..f24896a 100644 --- a/Carbon.Sample.API/Application/Dto/SampleCreateDto.cs +++ b/Carbon.Sample.API/Application/Dto/SampleCreateDto.cs @@ -1,10 +1,10 @@ -using System; +using Carbon.Sample.API.Application.Dto.Base; +using System; namespace Carbon.Sample.API.Application.Dto { - public class SampleCreateDto - { - public string Name { get; set; } - public Guid TenantId { get; set; } - } + public class SampleCreateDto : BaseRequestDto + { + public string Name { get; set; } + } } diff --git a/Carbon.Sample.API/Application/Dto/SampleFilterDto.cs b/Carbon.Sample.API/Application/Dto/SampleFilterDto.cs index 56f8ee2..b56005a 100644 --- a/Carbon.Sample.API/Application/Dto/SampleFilterDto.cs +++ b/Carbon.Sample.API/Application/Dto/SampleFilterDto.cs @@ -1,19 +1,13 @@ -using Carbon.Common; -using Carbon.Domain.Abstractions.Data; - +using Carbon.Sample.API.Application.Dto.Base; using System; using System.Collections.Generic; namespace Carbon.Sample.API.Application.Dto { - public class SampleFilterDto : IOrderableData, IPageableData - { - public IList Ids { get; set; } - public string Name { get; set; } - public bool? IsActive { get; set; } - public Guid TenantId { get; set; } - public int PageSize { get; set; } - public int PageIndex { get; set; } - public IList Orderables { get; set; } - } -} + public class SampleFilterDto : BaseRequestPagedDto + { + public IList Ids { get; set; } + public string Name { get; set; } + public bool? IsActive { get; set; } + } +} \ No newline at end of file diff --git a/Carbon.Sample.API/Application/Dto/Validators/Base/BaseRequestValidator.cs b/Carbon.Sample.API/Application/Dto/Validators/Base/BaseRequestValidator.cs new file mode 100644 index 0000000..cad1756 --- /dev/null +++ b/Carbon.Sample.API/Application/Dto/Validators/Base/BaseRequestValidator.cs @@ -0,0 +1,30 @@ +using Carbon.Sample.API.Infrastructure; +using FluentValidation.Results; +using FluentValidation; +using Carbon.Sample.API.Application.Dto.Base; +using Carbon.WebApplication; + +namespace Carbon.Sample.API.Application.Dto.Validators.Base +{ + //TO DO: Moved to carbon. + public class BaseRequestValidator : BaseDtoValidator + { + public BaseRequestValidator() + { + + } + protected override bool PreValidate(ValidationContext context, ValidationResult result) + { + if (context.InstanceToValidate == null) + { + result.Errors.Add(new ValidationFailure() + { + ErrorMessage = "Dto cannot be null!", + ErrorCode = ErrorCodes.DtoCannotBeNull.ToString() + }); + return false; + } + return true; + } + } +} diff --git a/Carbon.Sample.API/Application/Dto/Validators/DesiredDataDtoValidator.cs b/Carbon.Sample.API/Application/Dto/Validators/DesiredDataDtoValidator.cs index 2c7af98..bed5a64 100644 --- a/Carbon.Sample.API/Application/Dto/Validators/DesiredDataDtoValidator.cs +++ b/Carbon.Sample.API/Application/Dto/Validators/DesiredDataDtoValidator.cs @@ -1,18 +1,17 @@ -using Carbon.WebApplication; - +using Carbon.Sample.API.Application.Dto.Validators.Base; using FluentValidation; namespace Carbon.Sample.API.Application.Dto.Validators { - public class DesiredDataDtoValidator : BaseDtoValidator - { - public DesiredDataDtoValidator() - { - RuleFor(x => x.AssetId).NotEmpty(); - RuleFor(x => x.TelemetryId).NotEmpty(); + public class DesiredDataDtoValidator : BaseRequestValidator + { + public DesiredDataDtoValidator() + { + RuleFor(x => x.AssetId).NotEmpty(); + RuleFor(x => x.TelemetryId).NotEmpty(); - RuleFor(x => x.Value).NotEmpty(); - RuleFor(x => x.TenantId).NotEmpty(); - } - } + RuleFor(x => x.Value).NotEmpty(); + RuleFor(x => x.TenantId).NotEmpty(); + } + } } diff --git a/Carbon.Sample.API/Application/Dto/Validators/GetLatestDataDtoValidator.cs b/Carbon.Sample.API/Application/Dto/Validators/GetLatestDataDtoValidator.cs index c36d1fa..e6109ad 100644 --- a/Carbon.Sample.API/Application/Dto/Validators/GetLatestDataDtoValidator.cs +++ b/Carbon.Sample.API/Application/Dto/Validators/GetLatestDataDtoValidator.cs @@ -1,16 +1,14 @@ -using Carbon.WebApplication; - +using Carbon.Sample.API.Application.Dto.Validators.Base; using FluentValidation; namespace Carbon.Sample.API.Application.Dto.Validators { - public class GetLatestDataDtoValidator : BaseDtoValidator + public class GetLatestDataDtoValidator : BaseRequestValidator { public GetLatestDataDtoValidator() { RuleFor(x => x.AssetId).NotNull().NotEmpty(); RuleFor(x => x.TelemetryId).NotNull().NotEmpty(); - } } -} +} \ No newline at end of file diff --git a/Carbon.Sample.API/Application/Dto/Validators/SampleCreateDtoValidator.cs b/Carbon.Sample.API/Application/Dto/Validators/SampleCreateDtoValidator.cs index 8dc31e2..2621793 100644 --- a/Carbon.Sample.API/Application/Dto/Validators/SampleCreateDtoValidator.cs +++ b/Carbon.Sample.API/Application/Dto/Validators/SampleCreateDtoValidator.cs @@ -1,15 +1,13 @@ -using Carbon.WebApplication; - +using Carbon.Sample.API.Application.Dto.Validators.Base; using FluentValidation; namespace Carbon.Sample.API.Application.Dto.Validators { - public class SampleCreateDtoValidator : BaseDtoValidator - { - public SampleCreateDtoValidator() - { - RuleFor(x => x.Name).NotEmpty(); - RuleFor(x => x.TenantId).NotEmpty(); - } - } + public class SampleCreateDtoValidator : BaseRequestValidator + { + public SampleCreateDtoValidator() + { + RuleFor(x => x.Name).NotEmpty(); + } + } } diff --git a/Carbon.Sample.API/Application/Dto/Validators/SampleDeleteDtoValidator.cs b/Carbon.Sample.API/Application/Dto/Validators/SampleDeleteDtoValidator.cs index 1df9a3e..9ce5f3d 100644 --- a/Carbon.Sample.API/Application/Dto/Validators/SampleDeleteDtoValidator.cs +++ b/Carbon.Sample.API/Application/Dto/Validators/SampleDeleteDtoValidator.cs @@ -1,4 +1,5 @@ -using Carbon.WebApplication; +using Carbon.Sample.API.Application.Dto.Validators.Base; +using Carbon.WebApplication; using FluentValidation; @@ -6,7 +7,7 @@ namespace Carbon.Sample.API.Application.Dto.Validators { - public class SampleDeleteDtoValidator : BaseDtoValidator + public class SampleDeleteDtoValidator : BaseRequestValidator { public SampleDeleteDtoValidator() { diff --git a/Carbon.Sample.API/Application/Dto/Validators/SampleFilterDtoValidator.cs b/Carbon.Sample.API/Application/Dto/Validators/SampleFilterDtoValidator.cs index ad76177..d6d441a 100644 --- a/Carbon.Sample.API/Application/Dto/Validators/SampleFilterDtoValidator.cs +++ b/Carbon.Sample.API/Application/Dto/Validators/SampleFilterDtoValidator.cs @@ -1,19 +1,15 @@ -using Carbon.WebApplication; - +using Carbon.Sample.API.Application.Dto.Validators.Base; using FluentValidation; - using System; using System.Linq; namespace Carbon.Sample.API.Application.Dto.Validators { - public class SampleFilterDtoValidator : BaseDtoValidator - { - public SampleFilterDtoValidator() - { - RuleFor(x => x.Ids).Must(x => x == null || !x.Any(y => y != Guid.Empty)); - RuleFor(x => x.Name).NotEmpty(); - RuleFor(x => x.TenantId).NotEmpty(); - } - } + public class SampleFilterDtoValidator : BaseRequestValidator + { + public SampleFilterDtoValidator() + { + RuleFor(x => x.Ids).Must(x => x == null || !x.Any(y => y != Guid.Empty)); + } + } } diff --git a/Carbon.Sample.API/Application/Dto/Validators/SampleUpdateDtoValidator.cs b/Carbon.Sample.API/Application/Dto/Validators/SampleUpdateDtoValidator.cs index 447eacd..183b496 100644 --- a/Carbon.Sample.API/Application/Dto/Validators/SampleUpdateDtoValidator.cs +++ b/Carbon.Sample.API/Application/Dto/Validators/SampleUpdateDtoValidator.cs @@ -1,16 +1,15 @@ -using Carbon.WebApplication; - +using Carbon.Sample.API.Application.Dto.Validators.Base; using FluentValidation; namespace Carbon.Sample.API.Application.Dto.Validators { - public class SampleUpdateDtoValidator : BaseDtoValidator - { - public SampleUpdateDtoValidator() - { - RuleFor(x => x.Id).NotEmpty(); - RuleFor(x => x.Name).NotEmpty(); - RuleFor(x => x.TenantId).NotEmpty(); - } - } + public class SampleUpdateDtoValidator : BaseRequestValidator + { + public SampleUpdateDtoValidator() + { + RuleFor(x => x.Id).NotEmpty(); + RuleFor(x => x.Name).NotEmpty(); + RuleFor(x => x.TenantId).NotEmpty(); + } + } } diff --git a/Carbon.Sample.API/CHANGELOG.md b/Carbon.Sample.API/CHANGELOG.md index 5adbb18..032729f 100644 --- a/Carbon.Sample.API/CHANGELOG.md +++ b/Carbon.Sample.API/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.0] - 2021-02-27 +### Updated +- Upgraded .Net6 & Updated Nuget Packages. +- Refactor. + ## [1.1.0] - 2021-01-13 ### Added - New Samples added for ElasticSearch, Redis, Masstransit, Solution Features, Repository diff --git a/Carbon.Sample.API/Carbon.Sample.API.csproj b/Carbon.Sample.API/Carbon.Sample.API.csproj index 2bc22cf..f3c8085 100644 --- a/Carbon.Sample.API/Carbon.Sample.API.csproj +++ b/Carbon.Sample.API/Carbon.Sample.API.csproj @@ -1,49 +1,50 @@  - - net5.0 - fb14851d-80e8-4bc3-93cc-83fa440d76d7 - Linux - 1.1.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + net6.0 + fb14851d-80e8-4bc3-93cc-83fa440d76d7 + Linux + 2.0.0 + + + + + .\Carbon.Sample.API.xml + 1701;1702;1591 + + + + + + + + + + + + + + + + Always + + + Always + + + Always + + + + + + Always + + + + + + + diff --git a/Carbon.Sample.API/Carbon.Sample.API.xml b/Carbon.Sample.API/Carbon.Sample.API.xml new file mode 100644 index 0000000..8c0a19d --- /dev/null +++ b/Carbon.Sample.API/Carbon.Sample.API.xml @@ -0,0 +1,362 @@ + + + + Carbon.Sample.API + + + + + Create Sample + + Sample filter model + Tenant Id + Created Sample's Id + + + + Create Sample + + Sample creator model + Tenant Id + Created Sample's Id + + + + Updates Sample + + Sample updater model + Tenant Id + Updated Sample id + Sample's last state + + + + Deletes the Sample given by id + + Sample id + Tenant Id + No Content + + + + A strongly-typed resource class, for looking up localized strings, etc. + + + + + Returns the cached ResourceManager instance used by this class. + + + + + Overrides the current thread's CurrentUICulture property for all + resource lookups using this strongly typed resource class. + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + + Looks up a localized string similar to . + + + + diff --git a/Carbon.Sample.API/Dockerfile b/Carbon.Sample.API/Dockerfile index 777f8da..12dfd4f 100644 --- a/Carbon.Sample.API/Dockerfile +++ b/Carbon.Sample.API/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base WORKDIR /app EXPOSE 8080 ENV ASPNETCORE_URLS=http://+:8080 @@ -6,9 +6,8 @@ RUN addgroup --system --gid 1001 customgroup \ && adduser --system --uid 1001 --ingroup customgroup --shell /bin/sh customuser RUN chown customuser:customgroup /app && chmod -R 777 /app -FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src -COPY ["Carbon.Sample.API/NuGet.Config", "Carbon.Sample.API/"] COPY ["Carbon.Sample.API/Carbon.Sample.API.csproj", "Carbon.Sample.API/"] RUN dotnet restore --disable-parallel "Carbon.Sample.API/Carbon.Sample.API.csproj" COPY . . diff --git a/Carbon.Sample.API/Domain/Entities/TimeSerieDataLog.cs b/Carbon.Sample.API/Domain/Entities/TimeSerieDataLog.cs deleted file mode 100644 index 761969d..0000000 --- a/Carbon.Sample.API/Domain/Entities/TimeSerieDataLog.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Carbon.TimeSeriesDb.Abstractions.Attributes; -using Carbon.TimeSeriesDb.Abstractions.Entities; - -using System; - -namespace Carbon.Sample.API.Domain.Entities -{ - public enum DataType - { - Numeric = 0, - String = 1 - } - - public class TimeSerieDataLog : TimeSerieEntityBase - { - public Guid AssetId { get; set; } - public String AssetName { get; set; } - public Guid TelemetryId { get; set; } - public String TelemetryName { get; set; } - public string ContainerId { get; set; } - public Guid SensorId { get; set; } - public decimal Value { get; set; } - public string ValueAsStr { get; set; } - public DataType DataType { get; set; } - [TimeSerie] - public DateTime Date { get; set; } - public Guid TenantId { get; set; } - public Guid? TimeSerieDataLogLabelRelationId { get; set; } - } - - -} diff --git a/Carbon.Sample.API/Domain/Repositories/Abstract/IDataRepository.cs b/Carbon.Sample.API/Domain/Repositories/Abstract/IDataRepository.cs deleted file mode 100644 index 4679e55..0000000 --- a/Carbon.Sample.API/Domain/Repositories/Abstract/IDataRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Carbon.TimeSeriesDb.Abstractions.Entities; -using Carbon.TimeSeriesDb.Abstractions.Repositories; - -using System; -using System.Threading.Tasks; - -namespace Carbon.Sample.API.Domain.Repositories.Abstract -{ - public interface IDataRepository : ITimeSeriesEntityRepository - where TEntity : class, ITimeSeriesEntity - { - public Task GetLatestDataByAssetAndTelemetryId(Guid assetId, Guid telemetryId, Guid tenantId); - } -} diff --git a/Carbon.Sample.API/Domain/Repositories/Abstract/ISampleElasticRepository.cs b/Carbon.Sample.API/Domain/Repositories/Abstract/ISampleElasticRepository.cs deleted file mode 100644 index 71c037f..0000000 --- a/Carbon.Sample.API/Domain/Repositories/Abstract/ISampleElasticRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Carbon.ElasticSearch.Abstractions; -using Carbon.Sample.API.Domain.Entities; - -namespace Carbon.Sample.API.Domain.Repositories.Abstract -{ - public interface ISampleElasticRepository : IElasticRepository - { - } -} diff --git a/Carbon.Sample.API/Domain/Repositories/Abstract/ISampleRepository.cs b/Carbon.Sample.API/Domain/Repositories/Abstract/ISampleRepository.cs index 6519593..a8b3f19 100644 --- a/Carbon.Sample.API/Domain/Repositories/Abstract/ISampleRepository.cs +++ b/Carbon.Sample.API/Domain/Repositories/Abstract/ISampleRepository.cs @@ -1,15 +1,17 @@ using Carbon.Common.TenantManagementHandler.Interfaces; using Carbon.Domain.Abstractions.Repositories; -using Carbon.PagedList; -using Carbon.Sample.API.Application.Dto; using Carbon.Sample.API.Domain.Entities; - using System.Threading.Tasks; +using Carbon.Sample.API.Application.Dto; +using Carbon.Sample.API.Application.Dto.Base; +using System.Linq.Expressions; +using System; namespace Carbon.Sample.API.Domain.Repositories.Abstract { - public interface ISampleRepository : IRepository, ISolutionFilteredRepository, IOwnershipFilteredRepository - { - Task> Filter(SampleFilterDto filterDto); - } -} + public interface ISampleRepository : IRepository, ISolutionFilteredRepository, IOwnershipFilteredRepository + { + Task GetByIdAsync(Expression> filters); + Task> GetAllAsync(SampleFilterDto filter); + } +} \ No newline at end of file diff --git a/Carbon.Sample.API/Domain/Repositories/DataRepository.cs b/Carbon.Sample.API/Domain/Repositories/DataRepository.cs deleted file mode 100644 index b5e9144..0000000 --- a/Carbon.Sample.API/Domain/Repositories/DataRepository.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Carbon.Sample.API.Domain.Entities; -using Carbon.Sample.API.Domain.Repositories.Abstract; -using Carbon.Sample.API.Infrastructure.Contexts.TimeSeriesContexts; -using Carbon.TimeScaleDb.EntityFrameworkCore; - -using Microsoft.EntityFrameworkCore; - -using System; -using System.Linq; -using System.Threading.Tasks; - -namespace Carbon.Sample.API.Domain.Repositories -{ - public class DataRepository : EFTimeScaleDbWithReadOnlyRepository, IDataRepository - { - private readonly TimeSerieDataLogContext _timeSerieDataLogContext; - private readonly TimeSerieDataLogReadOnlyContext _timeSerieDataLogReadOnlyContext; - - public DataRepository(TimeSerieDataLogContext context, TimeSerieDataLogReadOnlyContext rContext) : base(context, rContext) - { - _timeSerieDataLogContext = context; - _timeSerieDataLogReadOnlyContext = rContext; - } - - public async Task GetLatestDataByAssetAndTelemetryId(Guid assetId, Guid telemetryId, Guid tenantId) - { - return await _timeSerieDataLogReadOnlyContext.Set().Where(k => k.AssetId == assetId && k.TelemetryId == telemetryId && k.TenantId == tenantId).OrderByDescending(k => k.Date).FirstOrDefaultAsync(); - } - } -} diff --git a/Carbon.Sample.API/Domain/Repositories/SampleElasticRepository.cs b/Carbon.Sample.API/Domain/Repositories/SampleElasticRepository.cs deleted file mode 100644 index 00b7f23..0000000 --- a/Carbon.Sample.API/Domain/Repositories/SampleElasticRepository.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Carbon.ElasticSearch; -using Carbon.ElasticSearch.Abstractions; -using Carbon.Sample.API.Domain.Entities; -using Carbon.Sample.API.Domain.Repositories.Abstract; - -namespace Carbon.Sample.API.Domain.Repositories -{ - public class SampleElasticRepository : BaseElasticRepository, ISampleElasticRepository - { - private readonly string _indexName; - public SampleElasticRepository(IElasticSettings elasticSettings) : base(elasticSettings) - { - _indexName = nameof(SampleEntity).ToLower(); - } - - public override string Index => _indexName; - } -} diff --git a/Carbon.Sample.API/Domain/Repositories/SampleRepository.cs b/Carbon.Sample.API/Domain/Repositories/SampleRepository.cs index f8736da..f369e2b 100644 --- a/Carbon.Sample.API/Domain/Repositories/SampleRepository.cs +++ b/Carbon.Sample.API/Domain/Repositories/SampleRepository.cs @@ -1,100 +1,90 @@ -using Carbon.Domain.EntityFrameworkCore; -using Carbon.PagedList; -using Carbon.Redis; +using Carbon.Common; +using Carbon.Domain.EntityFrameworkCore; using Carbon.Sample.API.Application.Dto; +using Carbon.Sample.API.Application.Dto.Base; using Carbon.Sample.API.Domain.Entities; using Carbon.Sample.API.Domain.Repositories.Abstract; -using Carbon.Sample.API.Infrastructure; using Carbon.Sample.API.Infrastructure.Contexts.SampleContext; - -using Mapster; - -using Nest; - -using StackExchange.Redis; - +using Microsoft.EntityFrameworkCore; using System; -using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; namespace Carbon.Sample.API.Domain.Repositories { - public class SampleRepository : EFTenantManagedRepository, ISampleRepository - { - private readonly IDatabase _redisDb; - private readonly ISampleElasticRepository _esRepo; - public SampleRepository(SampleDBContext context, IDatabase redisDb, ISampleElasticRepository esRepo) : base(context) - { - _redisDb = redisDb; - _esRepo = esRepo; - } - public override async Task CreateAsync(SampleEntity entity) - { - entity = await base.CreateAsync(entity); - await _redisDb.Set(CacheKeyConstants.SampleEntity.GenerateKeyById(entity.Id), entity); - await _esRepo.AddAsync(entity); - return entity; - } - public override async Task GetByIdAsync(Guid id) - { - var cacheResult = await _redisDb.Get(CacheKeyConstants.SampleEntity.GenerateKeyById(id)); - if (cacheResult.cachedObject != null) - return cacheResult.cachedObject; - var entity = await base.GetByIdAsync(id); - if (entity != null) - await _redisDb.Set(CacheKeyConstants.SampleEntity.GenerateKeyById(id), entity); - return entity; - } - public override async Task UpdateAsync(SampleEntity entity) - { - var updatedEntity = await base.UpdateAsync(entity); - await _redisDb.Set(CacheKeyConstants.SampleEntity.GenerateKeyById(updatedEntity.Id), updatedEntity); - await _esRepo.UpdateAsync(entity); - return updatedEntity; - } - public override async Task DeleteAsync(Guid id) - { - var entity = await base.DeleteAsync(id); - if (entity != null) - { - await _redisDb.RemoveKey(CacheKeyConstants.SampleEntity.GenerateKeyById(entity.Id)); - await _esRepo.DeleteByIdAsync(id.ToString()); - } - return entity; - } - public async Task> Filter(SampleFilterDto filterDto) - { - var filters = new List, QueryContainer>>(); + public class SampleRepository : EFTenantManagedRepository, ISampleRepository + { + public SampleRepository(SampleDBContext context) : base(context) + { + } + + public override async Task CreateAsync(SampleEntity entity) + { + entity = await base.CreateAsync(entity); + return entity; + } + + public async Task GetByIdAsync(Expression> filters) + { + var entity = await context.SampleEntity.FirstOrDefaultAsync(filters); + return entity; + } + + public override async Task UpdateAsync(SampleEntity entity) + { + var updatedEntity = await base.UpdateAsync(entity); + return updatedEntity; + } + + public override async Task DeleteAsync(Guid id) + { + var entity = await base.DeleteAsync(id); + return entity; + } + + public async Task> GetAllAsync(SampleFilterDto filter) + { + var query = context.SampleEntity + .AsNoTracking() + .Where(x => !x.IsDeleted); + + if (filter.TenantId != Guid.Empty) + { + query = query.Where(x => x.TenantId == filter.TenantId); + } + + if (filter.Ids != null && filter.Ids.Count > 0) + { + query = query.Where(x => filter.Ids.Contains(x.Id)); + } + + if (filter.IsActive.HasValue) + { + query = query.Where(x => x.IsActive == filter.IsActive); + } + + query = query.OrderBy(filter.Orderables); + + int totalPagesCount = 1; + var totalDataCount = query.Count(); + + if (filter.PageSize != 0) + { + totalPagesCount = query.CalculatePageCount(filter.PageSize); + query = query.SkipTake(filter.PageIndex, filter.PageSize); + } - filters.Add(r => r.Term(c => c - .Field(x => x.TenantId) - .Value(filterDto.TenantId))); + var result = await query.ToListAsync(); - if (filterDto.Ids?.Any(x => x != Guid.Empty) ?? false) - { - filters.Add(r => r.Terms(c => c - .Field(x => x.Id) - .Terms(filterDto.Ids.Where(x => x != Guid.Empty))) - ); - } - if (!string.IsNullOrWhiteSpace(filterDto.Name)) - { - filters.Add(r => r.Terms(c => c - .Field(x => x.Name) - .Terms(filterDto.Name)) - ); - } - if (filterDto.IsActive.HasValue) - { - filters.Add(r => r.Terms(c => c - .Field(x => x.IsActive) - .Terms(filterDto.IsActive.Value)) - ); - } - //ES paging is bit problematic, if you use paged data use with caution - var results = await _esRepo.FilterAsync(filters); - return new PagedList(results.Select(x => x.Adapt()).ToList(), filterDto.PageIndex, filterDto.PageSize); - } - } -} + return new Paged + { + List = result, + PageIndex = filter.PageIndex, + PageSize = filter.PageSize, + TotalPageCount = totalPagesCount, + TotalCount = totalDataCount + }; + } + } +} \ No newline at end of file diff --git a/Carbon.Sample.API/Domain/Services/Abstract/IDataService.cs b/Carbon.Sample.API/Domain/Services/Abstract/IDataService.cs deleted file mode 100644 index 18db48b..0000000 --- a/Carbon.Sample.API/Domain/Services/Abstract/IDataService.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Carbon.Sample.API.Application.Dto; - -using System; -using System.Threading.Tasks; - -namespace Carbon.Sample.API.Domain.Services.Abstract -{ - public interface IDataService - { - Task GetLatestDataByAssetAndTelemetryId(Guid assetId, Guid telemetryId, Guid tenantId); - Task SetDesiredTelemetryValueOnDataLog(Guid assetId, Guid telemetryId, string value); - } -} diff --git a/Carbon.Sample.API/Domain/Services/Abstract/ISampleService.cs b/Carbon.Sample.API/Domain/Services/Abstract/ISampleService.cs index 42a577b..fd051b9 100644 --- a/Carbon.Sample.API/Domain/Services/Abstract/ISampleService.cs +++ b/Carbon.Sample.API/Domain/Services/Abstract/ISampleService.cs @@ -1,18 +1,18 @@ using Carbon.PagedList; using Carbon.Sample.API.Application.Dto; +using Carbon.Sample.API.Application.Dto.Base; using Carbon.WebApplication.TenantManagementHandler.Interfaces; - +using System; using System.Threading.Tasks; namespace Carbon.Sample.API.Domain.Services.Abstract { - public interface ISampleService : ISolutionFilteredService, IOwnershipFilteredService - { - Task CreateAsync(SampleCreateDto dto); - - Task UpdateAsync(SampleUpdateDto dto); - - Task DeleteAsync(SampleDeleteDto dto); - Task> Filter(SampleFilterDto dto); - } + public interface ISampleService : ISolutionFilteredService, IOwnershipFilteredService + { + Task CreateAsync(SampleCreateDto dto); + Task UpdateAsync(SampleUpdateDto dto); + Task DeleteAsync(SampleDeleteDto dto); + Task GetByIdAsync(Guid id, Guid tenantId); + Task> GetAllAsync(SampleFilterDto filter); + } } diff --git a/Carbon.Sample.API/Domain/Services/DataService.cs b/Carbon.Sample.API/Domain/Services/DataService.cs deleted file mode 100644 index 1016d4d..0000000 --- a/Carbon.Sample.API/Domain/Services/DataService.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Carbon.HttpClient.Auth.IdentityServerSupport; -using Carbon.Sample.API.Application.Dto; -using Carbon.Sample.API.Domain.Entities; -using Carbon.Sample.API.Domain.Repositories.Abstract; -using Carbon.Sample.API.Domain.Services.Abstract; - -using Mapster; - -using Microsoft.Extensions.Configuration; - -using Newtonsoft.Json; - -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; - -namespace Carbon.Sample.API.Domain.Services -{ - public class DataService : IDataService - { - private readonly IDataRepository _testCarbonRepository; - private readonly AuthHttpClientFactory _clientFactory; - private readonly string _datalogapi; - private readonly IConfiguration _config; - - public DataService(IDataRepository testCarbonRepository, AuthHttpClientFactory clientFactory, IConfiguration config) - { - _config = config; - _testCarbonRepository = testCarbonRepository; - _clientFactory = clientFactory; - _datalogapi = _config.GetValue("DataLogUri"); - - } - - public async Task GetLatestDataByAssetAndTelemetryId(Guid assetId, Guid telemetryId, Guid tenantId) - { - var entity = await _testCarbonRepository.GetLatestDataByAssetAndTelemetryId(assetId, telemetryId, tenantId); - return entity.Adapt(); - } - - public async Task SetDesiredTelemetryValueOnDataLog(Guid assetId, Guid telemetryId, string value) - { - var authClient = _clientFactory.CreateAuthClient("RAM"); - var clientForAsset = authClient.HttpClient; - clientForAsset.DefaultRequestHeaders.Accept.Clear(); - clientForAsset.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - HttpRequestMessage httpRequestMessageToDataLog = new HttpRequestMessage(); - - var uribuilder = new UriBuilder(_datalogapi + "DataLog/SetDesiredData"); - string daUrlRuleLog = uribuilder.ToString(); - - httpRequestMessageToDataLog.RequestUri = new Uri(daUrlRuleLog); - var jStr = JsonConvert.SerializeObject(new DesiredDataForDataLogDto() - { - AssetFilterDto = new AssetFilterForDataDto() { AssetId = assetId }, - TelemetryFilterDto = new TelemetryFilterForDataDto() { TelemetryId = telemetryId }, - ValueAsStr = value - }); - httpRequestMessageToDataLog.Content = new StringContent(jStr, Encoding.UTF8, "application/json"); - httpRequestMessageToDataLog.Method = HttpMethod.Post; - - var resp = await _clientFactory.SendAsync(authClient, httpRequestMessageToDataLog); - var respStr = await resp.Content.ReadAsStringAsync(); - return resp.IsSuccessStatusCode; - } - - - } -} diff --git a/Carbon.Sample.API/Domain/Services/SampleService.cs b/Carbon.Sample.API/Domain/Services/SampleService.cs index e048234..391fa0c 100644 --- a/Carbon.Sample.API/Domain/Services/SampleService.cs +++ b/Carbon.Sample.API/Domain/Services/SampleService.cs @@ -1,63 +1,71 @@ using Carbon.Common.TenantManagementHandler.Interfaces; -using Carbon.PagedList; using Carbon.Sample.API.Application.Dto; +using Carbon.Sample.API.Application.Dto.Base; using Carbon.Sample.API.Domain.Entities; using Carbon.Sample.API.Domain.Repositories.Abstract; using Carbon.Sample.API.Domain.Services.Abstract; using Carbon.WebApplication.TenantManagementHandler.Abstracts; - using Mapster; - +using System; using System.Collections.Generic; using System.Threading.Tasks; namespace Carbon.Sample.API.Domain.Services { - public class SampleService : TenantManagedServiceBase, ISampleService - { - private readonly ISampleRepository _sampleRepository; - public SampleService(ISampleRepository sampleRepository) - : base(new List() { sampleRepository }, new List() { sampleRepository }) - { - _sampleRepository = sampleRepository; - } - public async Task CreateAsync(SampleCreateDto dto) - { - //Do bussiness related operations here - var entity = dto.Adapt(); - await _sampleRepository.CreateAsync(entity); - var result = entity.Adapt(); - - return result; - } - - public async Task UpdateAsync(SampleUpdateDto dto) - { - //Do bussiness related operations here - var entity = dto.Adapt(); - await _sampleRepository.UpdateAsync(entity); - var result = entity.Adapt(); - - return result; - } - - public async Task DeleteAsync(SampleDeleteDto dto) - { - //Do bussiness related operations here - if (dto.Id.HasValue) - await _sampleRepository.DeleteAsync(dto.Id.Value); - else - { - var entity = await _sampleRepository.GetAsync(x => x.Name == dto.Name); - if (entity != null) - await _sampleRepository.DeleteAsync(entity.Id); - } - } - - public async Task> Filter(SampleFilterDto dto) - { - //Do bussiness related operations here - return await _sampleRepository.Filter(dto); - } - } -} + public class SampleService : TenantManagedServiceBase, ISampleService + { + private readonly ISampleRepository _sampleRepository; + public SampleService(ISampleRepository sampleRepository) + : base(new List() { sampleRepository }, new List() { sampleRepository }) + { + _sampleRepository = sampleRepository; + } + + + public async Task CreateAsync(SampleCreateDto dto) + { + //Do bussiness related operations here + var entity = dto.Adapt(); + await _sampleRepository.CreateAsync(entity); + var result = entity.Adapt(); + + return result; + } + public async Task UpdateAsync(SampleUpdateDto dto) + { + //Do bussiness related operations here + var entity = dto.Adapt(); + await _sampleRepository.UpdateAsync(entity); + var result = entity.Adapt(); + + return result; + } + public async Task DeleteAsync(SampleDeleteDto dto) + { + //Do bussiness related operations here + if (dto.Id.HasValue) + await _sampleRepository.DeleteAsync(dto.Id.Value); + else + { + var entity = await _sampleRepository.GetAsync(x => x.Name == dto.Name); + if (entity != null) + await _sampleRepository.DeleteAsync(entity.Id); + } + } + + public async Task GetByIdAsync(Guid id, Guid tenantId) + { + var entity = await _sampleRepository.GetByIdAsync(x => x.Id == id && x.TenantId == tenantId && !x.IsDeleted && x.IsActive); + var result = entity.Adapt(); + return result; + } + + public async Task> GetAllAsync(SampleFilterDto filter) + { + var entities = await _sampleRepository.GetAllAsync(filter); + var result = entities?.Adapt>(); + + return result; + } + } +} \ No newline at end of file diff --git a/Carbon.Sample.API/Infrastructure/CacheKeyConstants.cs b/Carbon.Sample.API/Infrastructure/Caching/CacheKeyConstants.cs similarity index 100% rename from Carbon.Sample.API/Infrastructure/CacheKeyConstants.cs rename to Carbon.Sample.API/Infrastructure/Caching/CacheKeyConstants.cs diff --git a/Carbon.Sample.API/Infrastructure/Contexts/SampleContext/SampleDBContext.cs b/Carbon.Sample.API/Infrastructure/Contexts/SampleContext/SampleDBContext.cs index 551ce6d..2a00dc2 100644 --- a/Carbon.Sample.API/Infrastructure/Contexts/SampleContext/SampleDBContext.cs +++ b/Carbon.Sample.API/Infrastructure/Contexts/SampleContext/SampleDBContext.cs @@ -2,31 +2,27 @@ using Carbon.Domain.EntityFrameworkCore; using Carbon.Sample.API.Domain.Entities; using Carbon.Sample.API.Infrastructure.Contexts.SampleContext.EntityConfigurations; - using Microsoft.EntityFrameworkCore; namespace Carbon.Sample.API.Infrastructure.Contexts.SampleContext { - public class SampleDBContext : CarbonContext - { - public SampleDBContext(DbContextOptions options) : base(options) - { + public class SampleDBContext : CarbonContext + { + public SampleDBContext(DbContextOptions options) : base(options) + { - } + } - public virtual DbSet SampleEntity { get; set; } - public virtual DbSet EntitySolutionRelation { get; set; } + public virtual DbSet SampleEntity { get; set; } + public virtual DbSet EntitySolutionRelation { get; set; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - => optionsBuilder - .UseLazyLoadingProxies(); - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.ApplyConfiguration(new SampleEntityConfiguration()); - modelBuilder.ApplyConfiguration(new EntitySolutionRelationEntityConfiguration()); - base.OnModelCreating(modelBuilder); - } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new SampleEntityConfiguration()); + modelBuilder.ApplyConfiguration(new EntitySolutionRelationEntityConfiguration()); + base.OnModelCreating(modelBuilder); + } - } + } } diff --git a/Carbon.Sample.API/Infrastructure/Contexts/SampleContext/SampleDBContextDesignFactory.cs b/Carbon.Sample.API/Infrastructure/Contexts/SampleContext/SampleDBContextDesignFactory.cs index c8f2807..94cb1fe 100644 --- a/Carbon.Sample.API/Infrastructure/Contexts/SampleContext/SampleDBContextDesignFactory.cs +++ b/Carbon.Sample.API/Infrastructure/Contexts/SampleContext/SampleDBContextDesignFactory.cs @@ -5,33 +5,33 @@ namespace Carbon.Sample.API.Infrastructure.Contexts.SampleContext { - public class SampleDBContextDesignFactory : IDesignTimeDbContextFactory - { - public SampleDBContext CreateDbContext(string[] args) - { + public class SampleDBContextDesignFactory : IDesignTimeDbContextFactory + { + public SampleDBContext CreateDbContext(string[] args) + { - var target = "PostgreSQL"; - var mssqlconnectionString = "Server=localhost,1433;Database=sampledb;User ID=sampledb_user;Password='thissamplepassword';Connect Timeout=30;"; - var postgreConnectionString = "Server=localhost;Database=postgres;User ID=postgres;Password=password;"; + var target = "PostgreSQL"; + var mssqlconnectionString = "Server=localhost,1433;Database=sampledb;User ID=sampledb_user;Password='thissamplepassword';Connect Timeout=30;"; + var postgreConnectionString = "Server=localhost;Database=postgres;User ID=postgres;Password=password;"; - var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name + "." + target; + var migrationsAssembly = typeof(Program).GetTypeInfo().Assembly.GetName().Name + "." + target; - if (target == "PostgreSQL") - { - var optionsBuilder = new DbContextOptionsBuilder() - .UseNpgsql(postgreConnectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); + if (target == "PostgreSQL") + { + var optionsBuilder = new DbContextOptionsBuilder() + .UseNpgsql(postgreConnectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); - return new SampleDBContext(optionsBuilder.Options); - } - else - { - var optionsBuilder = new DbContextOptionsBuilder() - .UseSqlServer(mssqlconnectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); + return new SampleDBContext(optionsBuilder.Options); + } + else + { + var optionsBuilder = new DbContextOptionsBuilder() + .UseSqlServer(mssqlconnectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); - return new SampleDBContext(optionsBuilder.Options); - } + return new SampleDBContext(optionsBuilder.Options); + } - } - } + } + } } diff --git a/Carbon.Sample.API/Infrastructure/Contexts/TimeSeriesContexts/TimeSerieDataLogContext.cs b/Carbon.Sample.API/Infrastructure/Contexts/TimeSeriesContexts/TimeSerieDataLogContext.cs deleted file mode 100644 index c8339e7..0000000 --- a/Carbon.Sample.API/Infrastructure/Contexts/TimeSeriesContexts/TimeSerieDataLogContext.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Carbon.Sample.API.Domain.Entities; -using Carbon.TimeScaleDb.EntityFrameworkCore; - -using Microsoft.EntityFrameworkCore; - -namespace Carbon.Sample.API.Infrastructure.Contexts.TimeSeriesContexts -{ - public class TimeSerieDataLogContext : CarbonTimeScaleDbContext - { - public TimeSerieDataLogContext(DbContextOptions options) : base(options) - { - - } - public DbSet TimeSerieDataLog { get; set; } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - } - } - -} diff --git a/Carbon.Sample.API/Infrastructure/Contexts/TimeSeriesContexts/TimeSerieDataLogReadOnlyContext.cs b/Carbon.Sample.API/Infrastructure/Contexts/TimeSeriesContexts/TimeSerieDataLogReadOnlyContext.cs deleted file mode 100644 index 85e1b50..0000000 --- a/Carbon.Sample.API/Infrastructure/Contexts/TimeSeriesContexts/TimeSerieDataLogReadOnlyContext.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Carbon.Sample.API.Domain.Entities; -using Carbon.TimeScaleDb.EntityFrameworkCore; - -using Microsoft.EntityFrameworkCore; - -namespace Carbon.Sample.API.Infrastructure.Contexts.TimeSeriesContexts -{ - public class TimeSerieDataLogReadOnlyContext : CarbonTimeScaleDbReadOnlyContext - { - public TimeSerieDataLogReadOnlyContext(DbContextOptions options) : base(options) - { - - } - public DbSet TimeSerieDataLog { get; set; } - - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - } - } -} diff --git a/Carbon.Sample.API/Infrastructure/ElasticSettingExtensions.cs b/Carbon.Sample.API/Infrastructure/ElasticSettingExtensions.cs deleted file mode 100644 index b109ae4..0000000 --- a/Carbon.Sample.API/Infrastructure/ElasticSettingExtensions.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Carbon.ElasticSearch.Abstractions; -using Carbon.Sample.API.Domain.Entities; - -using System.Collections.Generic; - -namespace Carbon.Sample.API.Infrastructure -{ - public static class ElasticSettingExtensions - { - - public static void SetElasticConfiguration(this IElasticSettings options) - { - var mappings = new List(); - - mappings.Add(new ElasticIndexMapping(nameof(SampleEntity).ToLower(), c => - c.Map(m => - m.AutoMap().Properties(ps => ps.Keyword(s => s.Name(n => n.Id))) - .Properties(ps => ps.Keyword(s => s.Name(n => n.TenantId))) - ).Settings(x => x.Setting("mapping.total_fields.limit", "100000")) - )); - - options.SetIndexsAndAutoMappings(mappings.ToArray()); - } - } -} diff --git a/Carbon.Sample.API/Infrastructure/ErrorCodes.cs b/Carbon.Sample.API/Infrastructure/ErrorCodes.cs deleted file mode 100644 index 410b432..0000000 --- a/Carbon.Sample.API/Infrastructure/ErrorCodes.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Carbon.Sample.API.Infrastructure -{ - public enum ErrorCodes - { - //Give a spesific error code for errors - None = 0, - NoTenantSpecified = 1, - PageSizeIsNotInRange = 1011, - PageIndexIsNotInRange = 1012, - SampleCreateDtoIsNotValid = 2030, - SampleDuplicated = 2031, - SampleDeleteDtoIsNotValid = 2032, - SampleNotFound = 2033, - SampleUpdateDtoIsNotValid = 2034, - } -} diff --git a/Carbon.Sample.API/Infrastructure/Exceptions/ErrorCodes.cs b/Carbon.Sample.API/Infrastructure/Exceptions/ErrorCodes.cs new file mode 100644 index 0000000..bde7617 --- /dev/null +++ b/Carbon.Sample.API/Infrastructure/Exceptions/ErrorCodes.cs @@ -0,0 +1,17 @@ +namespace Carbon.Sample.API.Infrastructure +{ + public enum ErrorCodes + { + //Give a spesific error code for errors + None = 0, + NoTenantSpecified = 1, + PageSizeIsNotInRange = 1011, + PageIndexIsNotInRange = 1012, + SampleCreateDtoIsNotValid = 2030, + SampleDuplicated = 2031, + SampleDeleteDtoIsNotValid = 2032, + SampleNotFound = 2033, + SampleUpdateDtoIsNotValid = 2034, + DtoCannotBeNull = 2055 + } +} diff --git a/Carbon.Sample.API/Infrastructure/SampleException.cs b/Carbon.Sample.API/Infrastructure/Exceptions/SampleException.cs similarity index 100% rename from Carbon.Sample.API/Infrastructure/SampleException.cs rename to Carbon.Sample.API/Infrastructure/Exceptions/SampleException.cs diff --git a/Carbon.Sample.API/Infrastructure/Extensions/ServiceCollectionExtensions.cs b/Carbon.Sample.API/Infrastructure/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..bab098d --- /dev/null +++ b/Carbon.Sample.API/Infrastructure/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,33 @@ +using Carbon.Sample.API.Domain.Repositories.Abstract; +using Carbon.Sample.API.Domain.Repositories; +using Carbon.Sample.API.Domain.Services.Abstract; +using Carbon.Sample.API.Domain.Services; +using Microsoft.Extensions.DependencyInjection; + +namespace Carbon.Sample.API.Infrastructure.Extensions +{ + public static class ServiceCollectionExtensions + { + public static void AddApplicationDependencies(this IServiceCollection services) + { + services.AddScoped(); + services.AddScoped(); + } + + public static void AddCustomCors(this IServiceCollection serviceCollection, string cors) + { + serviceCollection.AddCors(options => + { + options.AddPolicy(cors, builder => + { + builder.WithOrigins("*") + .AllowAnyHeader() + .AllowAnyMethod() + .AllowAnyOrigin(); + }); + }); + } + } + + +} diff --git a/Carbon.Sample.API/Infrastructure/Extensions/WebApplicationExtensions.cs b/Carbon.Sample.API/Infrastructure/Extensions/WebApplicationExtensions.cs new file mode 100644 index 0000000..ebb108e --- /dev/null +++ b/Carbon.Sample.API/Infrastructure/Extensions/WebApplicationExtensions.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Localization; +using System.Collections.Generic; +using System.Globalization; + +namespace Carbon.Sample.API.Infrastructure.Extensions +{ + public static class WebApplicationExtensions + { + public static void UseCustomRequestLocalization(this IApplicationBuilder application) + { + IList supportedCultures = new List + { + new CultureInfo("en-US"), + new CultureInfo("tr-TR"), + }; + + application.UseRequestLocalization(new RequestLocalizationOptions + { + DefaultRequestCulture = new RequestCulture("en-US"), + SupportedCultures = supportedCultures, + SupportedUICultures = supportedCultures + }); + } + } +} diff --git a/Carbon.Sample.API/Infrastructure/Filters/BasePropertyBindingActionFilter.cs b/Carbon.Sample.API/Infrastructure/Filters/BasePropertyBindingActionFilter.cs new file mode 100644 index 0000000..becaf80 --- /dev/null +++ b/Carbon.Sample.API/Infrastructure/Filters/BasePropertyBindingActionFilter.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Linq; +using Carbon.Common; +using Carbon.Sample.API.Settings.Constants; +using Carbon.WebApplication.TenantManagementHandler.Extensions; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace Carbon.Sample.API.Infrastructure.Filters; +public class BasePropertyBindingActionFilter : IActionFilter +{ + public void OnActionExecuting(ActionExecutingContext context) + { + if (!context.ActionArguments.ContainsKey("request")) return; + + var request = context.ActionArguments["request"]; + + var user = ((ControllerBase)context.Controller).User; + + var tenantId = request?.GetType().GetProperties().FirstOrDefault(x => x.Name == "TenantId"); + if (tenantId == null) return; + tenantId.SetValue(request, user.GetTenantId()); + + var orderables = request?.GetType().GetProperties().FirstOrDefault(x => x.Name == "Orderables"); + if (orderables?.GetValue(request) == null) + { + orderables.SetValue(request, new List() { new() { Value = ApplicationConstant.DefaultOrderBy, IsAscending = false } }); + } + } + + public void OnActionExecuted(ActionExecutedContext context) + { + } +} \ No newline at end of file diff --git a/Carbon.Sample.API/Infrastructure/SolutionMigration.cs b/Carbon.Sample.API/Infrastructure/SolutionMigration/SolutionMigration.cs similarity index 100% rename from Carbon.Sample.API/Infrastructure/SolutionMigration.cs rename to Carbon.Sample.API/Infrastructure/SolutionMigration/SolutionMigration.cs diff --git a/Carbon.Sample.API/Program.cs b/Carbon.Sample.API/Program.cs index ffd80f5..b890f46 100644 --- a/Carbon.Sample.API/Program.cs +++ b/Carbon.Sample.API/Program.cs @@ -1,23 +1,70 @@ +using Carbon.Redis; +using Carbon.Sample.API.Infrastructure.Contexts.SampleContext; using Carbon.WebApplication; +using Carbon.WebApplication.EntityFrameworkCore; +using Carbon.WebApplication.SolutionService; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using System; +using Carbon.Sample.API.Infrastructure; +using Carbon.Sample.API.Infrastructure.Extensions; +using Carbon.HttpClient.Auth; +using Carbon.WebApplication.Middlewares; +using Carbon.WebApplication.SolutionService.Domain; +using Carbon.WebApplication.TenantManagementHandler.Dtos.ErrorHandling; +using Microsoft.Extensions.Configuration; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; +Console.Title = @"CARBON_SAMPLE_API"; +const string cors = "_carbon-sample"; +var builder = WebApplication.CreateBuilder(args); -namespace Carbon.Sample.API +builder.AddCarbonServices((services) => { - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseCarbonFeatures(); - webBuilder.UseStartup(); - }); - } -} + services.AddBearerAuthentication(builder.Configuration); + services.AddLocalization(o => { o.ResourcesPath = "Resources"; }); + // :TODO carbon + services.AddCustomCors(cors); + services.AddRedisPersister(builder.Configuration); + services.AddDatabaseContext(builder.Configuration); + services.AddApplicationDependencies(); + services.AddHttpClientAuth(); + //Enables Solution based saga events for feature list etc + services.ConfigureAsSolutionService(builder.Configuration); + return services; +}); +var app = builder.Build(); +app.AddCarbonApplication((application) => +{ + application.UseCors(cors); + application.UseHsts(); + application.UseHttpsRedirection(); + application.UseCustomRequestLocalization(); + app.CreateAuthentication("RAM"); + app.UseBearerTokenInRequestDto(); + app.MigrateDatabase(); + + #region Error Handling Registration + + var errorHandlingConfig = new ErrorHandlingConfig(); + builder.Configuration.GetSection("ErrorHandling").Bind(errorHandlingConfig); + if (!string.IsNullOrEmpty(errorHandlingConfig.Url)) + { + app.RegisterApplicationError(application.Environment, errorHandlingConfig); + } + + #endregion + + #region Solution Migration Registration + + var featuresets = SolutionMigration.GetFeatureSetMigration(); + foreach (var featureset in featuresets) + { + app.RegisterAsFeatureSet(new FeatureSetCreationRequest() + { FeatureSet = featureset, SolutionId = new Guid("D0F8427B-C637-42ED-F4BE-08D7F1B05268") }); + } + + #endregion + + return application; +}); +app.Run(); \ No newline at end of file diff --git a/Carbon.Sample.API/Properties/launchSettings.json b/Carbon.Sample.API/Properties/launchSettings.json index 8d48cc9..78d5278 100644 --- a/Carbon.Sample.API/Properties/launchSettings.json +++ b/Carbon.Sample.API/Properties/launchSettings.json @@ -1,34 +1,17 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:35418", - "sslPort": 44352 - } - }, "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, "Carbon.Sample.API": { + "applicationUrl": "https://localhost:5001;http://localhost:5000", "commandName": "Project", - "launchBrowser": true, - "launchUrl": "swagger", "environmentVariables": { "CONFIGURATION_TYPE": "FILE", - "FILE_CONFIG_PATHS": "appsettings.Development.json", + "FILE_CONFIG_PATHS": "appsettings.kube_test.json", "ENVIRONMENT_TYPE": "Kestrel", - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "kube_test" }, - "dotnetRunMessages": "true", - "applicationUrl": "https://localhost:5001;http://localhost:5000" + "launchBrowser": true, + "launchUrl": "swagger" }, "Docker": { "commandName": "Docker", diff --git a/Carbon.Sample.API/Resources/Errors.Designer.cs b/Carbon.Sample.API/Resources/Errors.Designer.cs new file mode 100644 index 0000000..fcacf14 --- /dev/null +++ b/Carbon.Sample.API/Resources/Errors.Designer.cs @@ -0,0 +1,618 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Platform360.MES.Fault.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Errors { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Errors() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Platform360.MES.Fault.Resources.Errors", typeof(Errors).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3001 { + get { + return ResourceManager.GetString("3001", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3002 { + get { + return ResourceManager.GetString("3002", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3003 { + get { + return ResourceManager.GetString("3003", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3004 { + get { + return ResourceManager.GetString("3004", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3009 { + get { + return ResourceManager.GetString("3009", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3010 { + get { + return ResourceManager.GetString("3010", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3011 { + get { + return ResourceManager.GetString("3011", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3012 { + get { + return ResourceManager.GetString("3012", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3013 { + get { + return ResourceManager.GetString("3013", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3014 { + get { + return ResourceManager.GetString("3014", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3015 { + get { + return ResourceManager.GetString("3015", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3016 { + get { + return ResourceManager.GetString("3016", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3017 { + get { + return ResourceManager.GetString("3017", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3018 { + get { + return ResourceManager.GetString("3018", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3019 { + get { + return ResourceManager.GetString("3019", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3020 { + get { + return ResourceManager.GetString("3020", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3021 { + get { + return ResourceManager.GetString("3021", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _3022 { + get { + return ResourceManager.GetString("3022", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4000 { + get { + return ResourceManager.GetString("4000", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4001 { + get { + return ResourceManager.GetString("4001", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4002 { + get { + return ResourceManager.GetString("4002", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4003 { + get { + return ResourceManager.GetString("4003", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4004 { + get { + return ResourceManager.GetString("4004", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4005 { + get { + return ResourceManager.GetString("4005", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4006 { + get { + return ResourceManager.GetString("4006", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4007 { + get { + return ResourceManager.GetString("4007", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4008 { + get { + return ResourceManager.GetString("4008", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4009 { + get { + return ResourceManager.GetString("4009", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4010 { + get { + return ResourceManager.GetString("4010", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _4011 { + get { + return ResourceManager.GetString("4011", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5000 { + get { + return ResourceManager.GetString("5000", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5001 { + get { + return ResourceManager.GetString("5001", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5002 { + get { + return ResourceManager.GetString("5002", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5003 { + get { + return ResourceManager.GetString("5003", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5004 { + get { + return ResourceManager.GetString("5004", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5005 { + get { + return ResourceManager.GetString("5005", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5006 { + get { + return ResourceManager.GetString("5006", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5007 { + get { + return ResourceManager.GetString("5007", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5008 { + get { + return ResourceManager.GetString("5008", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5009 { + get { + return ResourceManager.GetString("5009", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5010 { + get { + return ResourceManager.GetString("5010", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5011 { + get { + return ResourceManager.GetString("5011", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5012 { + get { + return ResourceManager.GetString("5012", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5013 { + get { + return ResourceManager.GetString("5013", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5014 { + get { + return ResourceManager.GetString("5014", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5015 { + get { + return ResourceManager.GetString("5015", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5016 { + get { + return ResourceManager.GetString("5016", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5017 { + get { + return ResourceManager.GetString("5017", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5018 { + get { + return ResourceManager.GetString("5018", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5019 { + get { + return ResourceManager.GetString("5019", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5020 { + get { + return ResourceManager.GetString("5020", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5021 { + get { + return ResourceManager.GetString("5021", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5022 { + get { + return ResourceManager.GetString("5022", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5023 { + get { + return ResourceManager.GetString("5023", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5024 { + get { + return ResourceManager.GetString("5024", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5025 { + get { + return ResourceManager.GetString("5025", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5026 { + get { + return ResourceManager.GetString("5026", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5027 { + get { + return ResourceManager.GetString("5027", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5036 + { + get + { + return ResourceManager.GetString("5036", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5037 + { + get + { + return ResourceManager.GetString("5037", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to . + /// + public static string _5038 + { + get + { + return ResourceManager.GetString("5038", resourceCulture); + } + } + } +} diff --git a/Carbon.Sample.API/Resources/Errors.en-US.resx b/Carbon.Sample.API/Resources/Errors.en-US.resx new file mode 100644 index 0000000..f4e1973 --- /dev/null +++ b/Carbon.Sample.API/Resources/Errors.en-US.resx @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + TenantIdCannotBeNull + + + FaultCreateDtoIsNotValid + + + FaultCouldNotBeFound  + + + FaultIdCannotBeNull + + + FaultDeleteDtoIsNotValid + + + FaultCreateError + + + FaultUpdateError + + + FaultDeleteError + + \ No newline at end of file diff --git a/Carbon.Sample.API/Resources/Errors.resx b/Carbon.Sample.API/Resources/Errors.resx new file mode 100644 index 0000000..436cadd --- /dev/null +++ b/Carbon.Sample.API/Resources/Errors.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Carbon.Sample.API/Resources/Errors.tr-TR.resx b/Carbon.Sample.API/Resources/Errors.tr-TR.resx new file mode 100644 index 0000000..218c6f8 --- /dev/null +++ b/Carbon.Sample.API/Resources/Errors.tr-TR.resx @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Tenant Id alanı boş bırakılamaz! + + + Kayıt oluşturma isteği geçerli değil. + + + Kayıt bulunamadı. + + + Id boş gönderilemez. + + + Kayıt silme isteği geçerli değil. + + + Kayıt oluşturma hatası. + + + Kayıt güncelleme hatası. + + + Kayıt silme hatası. + + \ No newline at end of file diff --git a/Carbon.Sample.API/Settings/Constants/ApplicationConstant.cs b/Carbon.Sample.API/Settings/Constants/ApplicationConstant.cs new file mode 100644 index 0000000..5fc7e0a --- /dev/null +++ b/Carbon.Sample.API/Settings/Constants/ApplicationConstant.cs @@ -0,0 +1,9 @@ +namespace Carbon.Sample.API.Settings.Constants +{ + public static class ApplicationConstant + { + public const int DefaultIndex = 1; + public const int DefaultPageSize = 250; + public const string DefaultOrderBy = "UpdatedDate"; + } +} diff --git a/Carbon.Sample.API/Startup.cs b/Carbon.Sample.API/Startup.cs deleted file mode 100644 index 0246d4d..0000000 --- a/Carbon.Sample.API/Startup.cs +++ /dev/null @@ -1,96 +0,0 @@ -using Carbon.ElasticSearch; -using Carbon.HttpClient.Auth; -using Carbon.MassTransit; -using Carbon.Redis; -using Carbon.Sample.API.Application.Consumers; -using Carbon.Sample.API.Domain.Entities; -using Carbon.Sample.API.Domain.Repositories; -using Carbon.Sample.API.Domain.Repositories.Abstract; -using Carbon.Sample.API.Domain.Services; -using Carbon.Sample.API.Domain.Services.Abstract; -using Carbon.Sample.API.Infrastructure; -using Carbon.Sample.API.Infrastructure.Contexts.SampleContext; -using Carbon.Sample.API.Infrastructure.Contexts.TimeSeriesContexts; -using Carbon.TimeScaleDb.EntityFrameworkCore; -using Carbon.WebApplication; -using Carbon.WebApplication.EntityFrameworkCore; -using Carbon.WebApplication.Middlewares; -using Carbon.WebApplication.SolutionService; -using Carbon.WebApplication.SolutionService.Domain; - -using MassTransit; - -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -using System; - -namespace Carbon.Sample.API -{ - public class Startup : CarbonStartup - { - public Startup(IConfiguration configuration, IWebHostEnvironment environment) : base(configuration, environment, false, false) - { - } - - public override void CustomConfigureServices(IServiceCollection services) - { - services.AddHttpClientAuth(); - services.AddBearerAuthentication(Configuration); - services.AddTimeScaleDatabaseWithReadOnlyReplicaContext(Configuration); - - services.AddElasticSearchPersister(Configuration, options => - { - options.SetElasticConfiguration(); - options.Build(); - }); - - services.AddRedisPersister(Configuration); - - services.AddDatabaseContext(Configuration); - - services.AddMassTransitBus(cfg => - { - cfg.AddConsumer(); - cfg.AddRabbitMqBus(Configuration, (provider, busFactoryConfig) => - { - busFactoryConfig.PurgeOnStartup = false; - busFactoryConfig.ReceiveEndpoint("ExchangeNameForDesiredData", x => - { - x.Consumer(provider); - x.ClearMessageDeserializers(); - x.UseRawJsonSerializer(); - }); - }); - }); - - services.AddScoped, DataRepository>(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - - //Enables Solution based saga events for feature list etc - services.ConfigureAsSolutionService(Configuration); - - } - - public override void CustomConfigure(IApplicationBuilder app, IWebHostEnvironment env) - { - app.CreateAuthentication("RAM"); - app.UseBearerTokenInRequestDto(); - app.MigrateDatabase(); - - var featuresets = SolutionMigration.GetFeatureSetMigration(); - foreach (var featureset in featuresets) - { - app.RegisterAsFeatureSet(new FeatureSetCreationRequest() { FeatureSet = featureset, SolutionId = new Guid("SolutionSpesificGuid") }); - } - } - - - - } -} diff --git a/Entity-Framework-Migrations/Carbon.Sample.API.MSSQL/Carbon.Sample.API.MSSQL.csproj b/Entity-Framework-Migrations/Carbon.Sample.API.MSSQL/Carbon.Sample.API.MSSQL.csproj index 97dd9fa..ac56aed 100644 --- a/Entity-Framework-Migrations/Carbon.Sample.API.MSSQL/Carbon.Sample.API.MSSQL.csproj +++ b/Entity-Framework-Migrations/Carbon.Sample.API.MSSQL/Carbon.Sample.API.MSSQL.csproj @@ -1,22 +1,13 @@  - - - net5.0 - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - ..\..\Carbon.Sample.API\bin\ - - + + net6.0 + + + + + + + + ..\..\Carbon.Sample.API\bin\ + diff --git a/Entity-Framework-Migrations/Carbon.Sample.API.PostgreSQL/Carbon.Sample.API.PostgreSQL.csproj b/Entity-Framework-Migrations/Carbon.Sample.API.PostgreSQL/Carbon.Sample.API.PostgreSQL.csproj index 6f70b23..c426f29 100644 --- a/Entity-Framework-Migrations/Carbon.Sample.API.PostgreSQL/Carbon.Sample.API.PostgreSQL.csproj +++ b/Entity-Framework-Migrations/Carbon.Sample.API.PostgreSQL/Carbon.Sample.API.PostgreSQL.csproj @@ -1,19 +1,12 @@  - - - net5.0 - - - - ..\..\Carbon.Sample.API\bin\ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + net6.0 + + + + ..\..\Carbon.Sample.API\bin\ + + + + diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..d8f90e2 --- /dev/null +++ b/nuget.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file