frontend
This commit is contained in:
@ -4,6 +4,8 @@ using System.Text.Json.Serialization;
|
||||
using Yuna.Website.Server.Services.DeviceSkillService;
|
||||
using Yuna.Website.Server.Services.DeviceService;
|
||||
using Yuna.Website.Server.Model;
|
||||
using System.Security.Claims;
|
||||
using Yuna.Website.Server.Infrastructure;
|
||||
|
||||
namespace Yuna.Website.Server.API
|
||||
{
|
||||
@ -47,13 +49,18 @@ namespace Yuna.Website.Server.API
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public async Task<IResult> CreateDevice([FromBody] CreateDeviceResult request, IDeviceService deviceService)
|
||||
public async Task<IResult> CreateDevice([FromBody] CreateDeviceResult request, IDeviceService deviceService, HttpContext context)
|
||||
{
|
||||
|
||||
var userId = context.GetUserIdFromCookie();
|
||||
if (userId is null) return Results.Unauthorized();
|
||||
|
||||
var device = new Device()
|
||||
{
|
||||
Description = request.Description,
|
||||
DeviceUrl = request.DeviceUrl,
|
||||
Name = request.Name
|
||||
Name = request.Name,
|
||||
UserId = (long)userId
|
||||
};
|
||||
|
||||
var result = await deviceService.Create(device);
|
||||
@ -74,9 +81,20 @@ namespace Yuna.Website.Server.API
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public async Task<IResult> GetAll(IDeviceService deviceService)
|
||||
public async Task<IResult> GetAll(IDeviceService deviceService, HttpContext context)
|
||||
{
|
||||
var result = await deviceService.GetList();
|
||||
|
||||
var isAdmin = context.GetRoleFromCookie();
|
||||
if(isAdmin)
|
||||
{
|
||||
var adminResult = await deviceService.GetList();
|
||||
return Results.Ok(adminResult);
|
||||
}
|
||||
|
||||
var userId = context.GetUserIdFromCookie();
|
||||
if (userId is null) return Results.Unauthorized();
|
||||
|
||||
var result = await deviceService.GetList((long)userId);
|
||||
return Results.Ok(result);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user