1
0

加入專案檔案。

This commit is contained in:
2024-03-25 16:13:35 +08:00
parent c16cecfc42
commit 739e92cee8
26 changed files with 459 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\CoreProfilerExample.Repository\CoreProfilerExample.Repository.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,33 @@
using CoreProfilerExample.Repository.Models.DataModels;
using CoreProfilerExample.Service.Models.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreProfilerExample.Service.Extensions
{
public static class MapperExtension
{
public static async Task<GetWeatherForecastDto> ToDtoAsync(this Task<IEnumerable<WeatherForecastDataModel>> task)
{
var dataModels = await task;
return new GetWeatherForecastDto
{
WeatherForecasts = dataModels.Select(model => model.ToDto()),
};
}
public static GetWeatherForecastItemDto ToDto(this WeatherForecastDataModel dataModel)
{
return new GetWeatherForecastItemDto
{
Date = dataModel.Date,
Summary = dataModel.Summary,
TemperatureC = dataModel.TemperatureC,
};
}
}
}

View File

@@ -0,0 +1,21 @@
using CoreProfilerExample.Repository.Interfaces;
using CoreProfilerExample.Service.Extensions;
using CoreProfilerExample.Service.Interfaces;
using CoreProfilerExample.Service.Models.Dtos;
using CoreProfilerExample.Service.Models.ParameterDtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreProfilerExample.Service.Implements
{
public class WeatherService(IWeatherForecastRepository weatherForecast) : IWeatherService
{
public Task<GetWeatherForecastDto> GetWeatherForecastAsync(GetWeatherForecastParameterDto parameterDto)
{
return weatherForecast.GetAsync(parameterDto.ForecastDays).ToDtoAsync();
}
}
}

View File

@@ -0,0 +1,10 @@
using CoreProfilerExample.Service.Models.Dtos;
using CoreProfilerExample.Service.Models.ParameterDtos;
namespace CoreProfilerExample.Service.Interfaces
{
public interface IWeatherService
{
public Task<GetWeatherForecastDto> GetWeatherForecastAsync(GetWeatherForecastParameterDto parameterDto);
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreProfilerExample.Service.Models.Dtos
{
public class GetWeatherForecastDto
{
public IEnumerable<GetWeatherForecastItemDto> WeatherForecasts { get; set; } = [];
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreProfilerExample.Service.Models.Dtos
{
public class GetWeatherForecastItemDto
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreProfilerExample.Service.Models.ParameterDtos
{
public class GetWeatherForecastParameterDto
{
public int ForecastDays { get; set; }
}
}