mycorerepository/MyCore/Controllers/UserController.cs

99 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Server;
using MyCore.Models;
using MyCore.Services;
namespace MyCore.Controllers
{
[Authorize(Roles = "Admin")]
[Route("api/user")]
[ApiController]
public class UserController : ControllerBase
{
private UserService _userService;
private TokenService _tokenService;
public UserController(UserService userService, TokenService tokenService)
{
_userService = userService;
_tokenService = tokenService;
}
// GET api/user
/// <summary>
/// Get a list of user
/// </summary>
[HttpGet]
public ActionResult<IEnumerable<UserInfo>> Get()
{
//return new string[] { "value1", "value2" };
//return _userService.GetUsers();
return null;
}
// GET api/user/5
/// <summary>
/// Get a specific user
/// </summary>
/// <param name="id">id user</param>
[HttpGet("{id}")]
public ActionResult<UserInfo> Get(string id)
{
UserInfo user = new UserInfo();
user.FirstName = "Thomas";
user.Id = "01";
return user;
//return _userService.GetUser(id);
}
// POST: User/Create
/// <summary>
///
/// </summary>
[AllowAnonymous]
[HttpPost]
public ActionResult<UserInfo> CreateUser([FromBody] UserInfo newUser)
{
if (newUser != null)
{
newUser.Token = _tokenService.GenerateToken(newUser.Email).ToString();
UserInfo userCreated = _userService.CreateUser(newUser);
return userCreated;
}
return StatusCode(500);
}
/*
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
// For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
// For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
// For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
}*/
}
}