Add: JWT authentication in Web API. Related configuration and services are added.
31 lines
731 B
C#
31 lines
731 B
C#
using OptixServe.Core.Data;
|
|
using OptixServe.Core.Models;
|
|
|
|
namespace OptixServe.Core.Services;
|
|
|
|
public interface IUserService
|
|
{
|
|
IEnumerable<User> GetUsers();
|
|
User? GetUserById(string id);
|
|
User? GetUserByUsername(string username);
|
|
}
|
|
|
|
public class UserService(AppDbContext dbContext) : IUserService
|
|
{
|
|
private readonly AppDbContext _dbContext = dbContext;
|
|
|
|
public User? GetUserById(string id)
|
|
{
|
|
return _dbContext.Users.FirstOrDefault(u => u.Id == id);
|
|
}
|
|
|
|
public User? GetUserByUsername(string username)
|
|
{
|
|
return _dbContext.Users.FirstOrDefault(u => u.UserName == username);
|
|
}
|
|
|
|
public IEnumerable<User> GetUsers()
|
|
{
|
|
return _dbContext.Users.AsEnumerable();
|
|
}
|
|
} |