refactor mostly..
This commit is contained in:
parent
63913b432c
commit
3d3ce211b3
|
|
@ -17,7 +17,7 @@ namespace ProjectGrid.Controllers
|
|||
private readonly ILogger<TicTacTocController> _logger;
|
||||
|
||||
//static readonly Models.IUserRepository repository = new Models.UserRepository();
|
||||
private readonly Models.IUserRepository repository;
|
||||
private readonly ITicTacToctRepository repository;
|
||||
|
||||
public TicTacTocController(ILogger<TicTacTocController> logger, DataAccessContext context)
|
||||
{
|
||||
|
|
@ -27,15 +27,15 @@ namespace ProjectGrid.Controllers
|
|||
|
||||
[HttpGet]
|
||||
[Route("api/ttt/GetBoard")]
|
||||
public IEnumerable<Models.UserModel> GetAllUsers()
|
||||
public Models.TicTacTocBoard GetBoard()
|
||||
{
|
||||
return repository.GetAll();
|
||||
return repository.GetBoard();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/ttt/SetPiece")]
|
||||
[Consumes("application/json")]
|
||||
public Models.UserModel PostUser(Models.UserModel item)
|
||||
public Models.UserModel PostMove(Models.UserModel item)
|
||||
{
|
||||
return repository.Add(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace ProjectGrid.Controllers
|
|||
private readonly ILogger<UsersController> _logger;
|
||||
|
||||
//static readonly Models.IUserRepository repository = new Models.UserRepository();
|
||||
private readonly Models.IUserRepository repository;
|
||||
private readonly IUserRepository repository;
|
||||
|
||||
public UsersController(ILogger<UsersController> logger, DataAccessContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ProjectGrid.Models;
|
||||
|
||||
|
||||
namespace ProjectGrid.Data
|
||||
{
|
||||
public partial class DataAccessContext : ITicTacToctRepository
|
||||
{
|
||||
|
||||
public bool AddPiece(TicTacTocMove user)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public Models.TicTacTocBoard GetBoard()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
using ProjectGrid.Models;
|
||||
|
||||
namespace ProjectGrid.Data
|
||||
{
|
||||
public interface ITicTacToctRepository
|
||||
{
|
||||
TicTacTocBoard GetBoard();
|
||||
|
||||
bool AddPiece(TicTacTocMove user);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
using ProjectGrid.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ProjectGrid.Data
|
||||
{
|
||||
public interface IUserRepository
|
||||
{
|
||||
IEnumerable<UserModel> GetAll();
|
||||
|
||||
UserModel Add(UserModel user);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using ProjectGrid;
|
||||
using ProjectGrid.Data;
|
||||
using ProjectGrid.Models;
|
||||
using System;
|
||||
|
||||
namespace ProjectGrid
|
||||
{
|
||||
public class TicTacTocManager
|
||||
{
|
||||
|
||||
private ITicTacToctRepository _repo;
|
||||
|
||||
private TicTacTocBoard _board;
|
||||
|
||||
public TicTacTocManager(ITicTacToctRepository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ProjectGrid.Models
|
||||
{
|
||||
public interface IUserRepository
|
||||
{
|
||||
IEnumerable<UserModel> GetAll();
|
||||
|
||||
UserModel Add(UserModel user);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +1,35 @@
|
|||
using ProjectGrid.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ProjectGrid.Models
|
||||
{
|
||||
public class UserRepository: IUserRepository
|
||||
public class UserRepository : IUserRepository
|
||||
{
|
||||
private List<UserModel> users = new List<UserModel>();
|
||||
private int _nextId = 1;
|
||||
|
||||
public UserRepository()
|
||||
{
|
||||
private List<UserModel> users = new List<UserModel>();
|
||||
private int _nextId = 1;
|
||||
|
||||
public UserRepository()
|
||||
{
|
||||
Add(new UserModel { firstName= "first1", lastName="last1", email="email1@gmail.com"});
|
||||
Add(new UserModel { firstName= "first2", lastName="last2", email="email2@gmail.com"});
|
||||
Add(new UserModel { firstName= "first3", lastName="last3", email="email3@gmail.com"});
|
||||
}
|
||||
|
||||
public IEnumerable<UserModel> GetAll()
|
||||
{
|
||||
return users;
|
||||
}
|
||||
|
||||
public UserModel Add(UserModel item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentNullException("item");
|
||||
}
|
||||
item.Id = _nextId++;
|
||||
users.Add(item);
|
||||
return item;
|
||||
}
|
||||
Add(new UserModel { firstName = "first1", lastName = "last1", email = "email1@gmail.com" });
|
||||
Add(new UserModel { firstName = "first2", lastName = "last2", email = "email2@gmail.com" });
|
||||
Add(new UserModel { firstName = "first3", lastName = "last3", email = "email3@gmail.com" });
|
||||
}
|
||||
|
||||
public IEnumerable<UserModel> GetAll()
|
||||
{
|
||||
return users;
|
||||
}
|
||||
|
||||
public UserModel Add(UserModel item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentNullException("item");
|
||||
}
|
||||
item.Id = _nextId++;
|
||||
users.Add(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.17.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue