Update DI for games API controller

dashboard
Pat Hartl 2023-01-11 20:49:31 -06:00
parent 21f8cbd992
commit 5809b7fa3d
1 changed files with 7 additions and 11 deletions

View File

@ -1,5 +1,6 @@
using LANCommander.Data; using LANCommander.Data;
using LANCommander.Data.Models; using LANCommander.Data.Models;
using LANCommander.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -10,29 +11,24 @@ namespace LANCommander.Controllers.Api
[ApiController] [ApiController]
public class GamesController : ControllerBase public class GamesController : ControllerBase
{ {
private DatabaseContext Context; private readonly GameService GameService;
public GamesController(DatabaseContext context) public GamesController(GameService gameService)
{ {
Context = context;
GameService = gameService;
} }
[HttpGet] [HttpGet]
public IEnumerable<Game> Get() public IEnumerable<Game> Get()
{ {
using (var repo = new Repository<Game>(Context, HttpContext)) return GameService.Get();
{
return repo.Get(g => true).ToList();
}
} }
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<Game> Get(Guid id) public async Task<Game> Get(Guid id)
{ {
using (var repo = new Repository<Game>(Context, HttpContext)) return await GameService.Get(id);
{
return await repo.Find(id);
}
} }
} }
} }