DataService hinzugefügt
This commit is contained in:
47
ReallifeGamemode.DataService/Controllers/UserController.cs
Normal file
47
ReallifeGamemode.DataService/Controllers/UserController.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.DataService.Types;
|
||||
|
||||
namespace ReallifeGamemode.DataService.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("DataService/User")]
|
||||
[Produces("application/json")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly DatabaseContext dbContext;
|
||||
|
||||
public UserController(DatabaseContext dbContext)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
|
||||
[HttpGet("Data")]
|
||||
public ActionResult<GetUserDataResponse> Data()
|
||||
{
|
||||
User user = dbContext.Users.Where(u => u.Id == UserId).FirstOrDefault();
|
||||
|
||||
if(user == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return new GetUserDataResponse()
|
||||
{
|
||||
Name = user.Name,
|
||||
AdminLevel = user.AdminLevel,
|
||||
RegistrationDate = user.RegistrationDate
|
||||
};
|
||||
}
|
||||
|
||||
private int UserId => int.Parse(User.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault()?.Value ?? "0");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user