加入專案檔案。
This commit is contained in:
@@ -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>
|
||||
33
CoreProfilerExample.Service/Extensions/MapperExtension.cs
Normal file
33
CoreProfilerExample.Service/Extensions/MapperExtension.cs
Normal 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
21
CoreProfilerExample.Service/Implements/WeatherService.cs
Normal file
21
CoreProfilerExample.Service/Implements/WeatherService.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
10
CoreProfilerExample.Service/Interfaces/IWeatherService.cs
Normal file
10
CoreProfilerExample.Service/Interfaces/IWeatherService.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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; } = [];
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user