🍻 i was trying to implement AutoMapper but i was to drunk SORRYgit status

pull/22/head
Ismail TAHA JANAN 2 years ago
parent 332f702685
commit a219699271

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using cat_cafe.Entities;
using cat_cafe.Repositories;
using cat_cafe.Dto;
namespace cat_cafe.Controllers
{
@ -23,7 +24,7 @@ namespace cat_cafe.Controllers
// GET: api/Customers
[HttpGet]
public async Task<ActionResult<IEnumerable<Customer>>> GetCustomers()
public async Task<ActionResult<IEnumerable<CustomerDto>>> GetCustomers()
{
if (_context.Customers == null)
{
@ -34,7 +35,7 @@ namespace cat_cafe.Controllers
// GET: api/Customers/5
[HttpGet("{id}")]
public async Task<ActionResult<Customer>> GetCustomer(long id)
public async Task<ActionResult<CustomerD>> GetCustomer(long id)
{
if (_context.Customers == null)
{

@ -0,0 +1,11 @@
using System;
namespace cat_cafe.Dto
{
public class CatDto
{
public long Id { get; set; }
public string? Name { get; set; }
public int Age { get; set; } = 0;
}
}

@ -0,0 +1,11 @@
using System;
namespace cat_cafe.Dto
{
public class CustomerDto
{
public long Id { get; set; }
public string? FullName { get; set; }
public int Age { get; set; } = 0;
}
}

@ -6,6 +6,5 @@
public string? Name { get; set; }
public int Age { get; set; } = 0;
}
}

@ -0,0 +1,17 @@
using System;
using AutoMapper;
using cat_cafe.Entities;
using cat_cafe.Dto;
namespace cat_cafe.Mappers
{
public class CustomerMapper:Profile
{
public CustomerMapper()
{
CreateMap<Customer, CustomerDto>();
CreateMap<CustomerDto, Customer>();
}
}
}

@ -0,0 +1,31 @@
using System;
using cat_cafe.Entities;
using cat_cafe.Repositories;
using cat_cafe.Dto;
using cat_cafe.Mappers;
namespace cat_cafe.Services
{
public class CustomeService
{
public CustomeService()
{
}
private readonly CustomerContext _context;
public Task<List<CustomerDto>>? getAll()
{
if (_context.Customers == null)
{
return null;
}
/**
* here i stoped
*/
return Mappers.CustomerMapper(await _context.Customers.ToListAsync());
}
}
}

@ -16,6 +16,20 @@
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.11" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="AutoMapper" Version="12.0.0" />
<PackageReference Include="AutoFixture" Version="4.17.0" />
</ItemGroup>
<ItemGroup>
<None Remove="Dto\" />
<None Remove="Services\" />
<None Remove="Mappers\" />
<None Remove="AutoMapper" />
<None Remove="AutoFixture" />
</ItemGroup>
<ItemGroup>
<Folder Include="Dto\" />
<Folder Include="Services\" />
<Folder Include="Mappers\" />
</ItemGroup>
</Project>

Loading…
Cancel
Save