Remotely/Remotely_Server/API/DevicesController.cs
2021-07-29 07:53:41 -07:00

47 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Remotely_Library.Models;
using Remotely_Server.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Remotely_Server.API
{
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class DevicesController : Controller
{
public DevicesController(DataService dataService, UserManager<RemotelyUser> userManager)
{
this.DataService = dataService;
this.UserManager = userManager;
}
private DataService DataService { get; set; }
private UserManager<RemotelyUser> UserManager { get; set; }
// GET: api/<controller>
[HttpGet]
public async Task<IEnumerable<Device>> Get()
{
var user = await UserManager.GetUserAsync(User);
var devices = DataService.GetAllDevicesForUser(user.Id);
return devices;
}
// GET api/<controller>/5
[HttpGet("{id}")]
public async Task<Device> Get(string id)
{
var user = await UserManager.GetUserAsync(User);
return DataService.GetDeviceForUser(user.Id, id);
}
}
}