Skip to content

Commit

Permalink
Update Business tree + Get all Fake
Browse files Browse the repository at this point in the history
  • Loading branch information
mp-ebp committed Nov 28, 2022
1 parent e273bb1 commit fc95fbd
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 62 deletions.
27 changes: 24 additions & 3 deletions My.DDD.CQRS.Temp6.Api/Controllers/V1/FakeController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos.Fake;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users.Fake;

namespace My.DDD.CQRS.Temp6.Api.Controllers.V1
{
Expand Down Expand Up @@ -31,7 +31,17 @@ public async Task<IActionResult> FakeGetByIdTodo([FromRoute] int id)
}


// GET: api/<FakeController>/{id}
// GET: api/<FakeController>/todos
[HttpGet("todos")]
public async Task<IActionResult> FakeAllTodos()
{
var res = await _mediator.Send(new FakeGetAllTodos());
if (res == null)
return NotFound();
return Ok(res);
}

// GET: api/<FakeController>/users/{id}
[HttpGet("users/{id}")]
public async Task<IActionResult> FakeGetByIdUser([FromRoute] int id)
{
Expand All @@ -40,5 +50,16 @@ public async Task<IActionResult> FakeGetByIdUser([FromRoute] int id)
return NotFound();
return Ok(res);
}


// GET: api/<FakeController>/users
[HttpGet("users")]
public async Task<IActionResult> FakeAllUsers()
{
var res = await _mediator.Send(new FakeGetAllUsers());
if (res == null)
return NotFound();
return Ok(res);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using MediatR;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos.Fake;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using My.DDD.CQRS.Temp6.DBAccess;
using My.DDD.CQRS.Temp6.Contracts.ExempleAggregate.Queries;

namespace My.DDD.CQRS.Temp6.Application.PlaceholderAggregate.Queries.Todos.Fake
{
public class FakeGetAllTodosQuery : IRequestHandler<FakeGetAllTodos, IEnumerable<TodoResult>>
{
private readonly FakeBdContext _fakeDbContext;
public FakeGetAllTodosQuery(FakeBdContext fakeDbContext)
{
_fakeDbContext = fakeDbContext;
}

public async Task<IEnumerable<TodoResult>> Handle(FakeGetAllTodos request, CancellationToken cancellationToken)
{

var result = await _fakeDbContext.GetAllTodos();
var finalResult = new List<TodoResult>();
for (int i = 0; i < result.Count(); i++)
{
var res = result.ElementAt(i);
finalResult.Add(new TodoResult() { Id = res.Id, UserId = res.UserId, Completed = res.Completed, Title = res.Title });
}
return finalResult;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using MediatR;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos.Fake;
using My.DDD.CQRS.Temp6.DBAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace My.DDD.CQRS.Temp6.Application.PlaceholderAggregate.Queries.Todos.Fake
{
public class FakeGetByIdTodoQuery : IRequestHandler<FakeGetByIdTodo, TodoResult?>
{
private readonly FakeBdContext _fakeDbContext;
public FakeGetByIdTodoQuery(FakeBdContext fakeDbContext)
{
_fakeDbContext = fakeDbContext;
}

public async Task<TodoResult?> Handle(FakeGetByIdTodo request, CancellationToken cancellationToken)
{
var res = await _fakeDbContext.GetTodo(request.TodoId);
if (res == null)
return null;
return new TodoResult() { Id = res.Id, UserId = res.UserId, Completed = res.Completed, Title = res.Title };
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using MediatR;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users.Fake;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using My.DDD.CQRS.Temp6.DBAccess;
using My.DDD.CQRS.Temp6.Contracts.ExempleAggregate.Queries;

namespace My.DDD.CQRS.Temp6.Application.PlaceholderAggregate.Queries.Users.Fake
{
public class FakeGetAllUsersQuery : IRequestHandler<FakeGetAllUsers, IEnumerable<UserResult>>
{

private readonly FakeBdContext _fakeDbContext;

public FakeGetAllUsersQuery(FakeBdContext fakeDbContext)
{
_fakeDbContext = fakeDbContext;
}

public async Task<IEnumerable<UserResult>> Handle(FakeGetAllUsers request, CancellationToken cancellationToken)
{
var result = await _fakeDbContext.GetAllUsers();
var finalResult = new List<UserResult>();
for (int i = 0; i < result.Count(); i++)
{
var element = result.ElementAt(i);
finalResult.Add(new UserResult()
{
Id = element.Id,
Name = element.Name,
Email = element.Email,
Username = element.Username,
Phone = element.Phone,
Website = element.Website
});
}
return finalResult;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MediatR;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users;
using My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users.Fake;
using My.DDD.CQRS.Temp6.DBAccess;
using My.DDD.CQRS.Temp6.Domain.PlaceholderAggregate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace My.DDD.CQRS.Temp6.Application.PlaceholderAggregate.Queries.Users.Fake
{
public class FakeGetByIdUserQuery : IRequestHandler<FakeGetByIdUser, UserResult?>
{
private readonly FakeBdContext _fakeDbContext;
public FakeGetByIdUserQuery(FakeBdContext fakeDbContext)
{
_fakeDbContext = fakeDbContext;
}

public async Task<UserResult?> Handle(FakeGetByIdUser request, CancellationToken cancellationToken)
{
var result = await _fakeDbContext.GetUser(request.UserId);
if (result == null)
return null;
return new UserResult() { Id = result.Id, Name = result.Name, Email = result.Email, Username = result.Username, Phone = result.Phone, Website = result.Website };
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos.Fake
{
public class FakeGetAllTodos : IRequest<IEnumerable<TodoResult>>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos
namespace My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Todos.Fake
{
public class FakeGetByIdTodo : IRequest<TodoResult?>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users.Fake
{
public class FakeGetAllUsers : IRequest<IEnumerable<UserResult>>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users
namespace My.DDD.CQRS.Temp6.Contracts.PlaceholderAggregate.Queries.Users.Fake
{
public class FakeGetByIdUser : IRequest<UserResult?>
{
Expand Down

0 comments on commit fc95fbd

Please sign in to comment.