Add basic API endpoint to get games
parent
74abbd0503
commit
640a75abdd
|
@ -0,0 +1,36 @@
|
|||
using LANCommander.Data;
|
||||
using LANCommander.Data.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LANCommander.Controllers.Api
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class GamesController : ControllerBase
|
||||
{
|
||||
private DatabaseContext Context;
|
||||
|
||||
public GamesController(DatabaseContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<Game> Get()
|
||||
{
|
||||
using (var repo = new Repository<Game>(Context, HttpContext))
|
||||
{
|
||||
return repo.Get(g => true).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<Game> Get(Guid id)
|
||||
{
|
||||
using (var repo = new Repository<Game>(Context, HttpContext))
|
||||
{
|
||||
return await repo.Find(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,39 @@
|
|||
using Microsoft.AspNetCore.Identity;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LANCommander.Data.Models
|
||||
{
|
||||
[Table("Users")]
|
||||
public class User : IdentityUser<Guid>
|
||||
{
|
||||
// Ignore the following properties from leaking into REST requests
|
||||
[JsonIgnore]
|
||||
public override string? PasswordHash { get; set; }
|
||||
[JsonIgnore]
|
||||
public override string? SecurityStamp { get; set; }
|
||||
[JsonIgnore]
|
||||
public override string? Email { get; set; }
|
||||
[JsonIgnore]
|
||||
public override string? NormalizedEmail { get; set; }
|
||||
[JsonIgnore]
|
||||
public override bool EmailConfirmed { get; set; }
|
||||
[JsonIgnore]
|
||||
public override string? NormalizedUserName { get; set; }
|
||||
[JsonIgnore]
|
||||
public override string? ConcurrencyStamp { get; set; }
|
||||
[JsonIgnore]
|
||||
public override string? PhoneNumber { get; set; }
|
||||
[JsonIgnore]
|
||||
public override bool PhoneNumberConfirmed { get; set; }
|
||||
[JsonIgnore]
|
||||
public override bool TwoFactorEnabled { get; set; }
|
||||
[JsonIgnore]
|
||||
public override DateTimeOffset? LockoutEnd { get; set; }
|
||||
[JsonIgnore]
|
||||
public override bool LockoutEnabled { get; set; }
|
||||
[JsonIgnore]
|
||||
public override int AccessFailedCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,10 @@ builder.Services.AddDefaultIdentity<User>((IdentityOptions options) => {
|
|||
.AddRoles<Role>()
|
||||
.AddEntityFrameworkStores<LANCommander.Data.DatabaseContext>();
|
||||
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddControllersWithViews().AddJsonOptions(x =>
|
||||
{
|
||||
x.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
Loading…
Reference in New Issue