source: iknow-api/Controllers/UsersControllers.cs@ 301af3f

Last change on this file since 301af3f was fc7b4b4, checked in by stefansaveski <stefansaveski19@…>, 11 months ago

Implement JWT Authentication and Update User Schema

Replaced repository interface with FinXaccesApi.Repositories in UsersControllers.cs. Updated database schema to use PasswordHash instead of Password. Added new migration files reflecting these changes. Updated service registration in Program.cs to include IAuthService and IUserRepository. Refactored UserRepository.cs and IUserRepository.cs with new methods and namespace changes. Commented out UserService.cs. Updated appsettings with new connection strings and JWT settings. Added BCrypt.Net-Next and System.IdentityModel.Tokens.Jwt packages. Introduced AuthController, UserDTO, AuthService, and IAuthService for handling authentication and user management.

  • Property mode set to 100644
File size: 932 bytes
Line 
1using iknow_api.Core.Models;
2using System.Threading.Tasks;
3using Microsoft.AspNetCore.Mvc;
4using iknow_api.Core.Data;
5using FinXaccesApi.Repositories;
6using iknow_api.Core.Interfaces;
7
8namespace iknow_api.Controllers
9{
10 [ApiController]
11 [Route("user")]
12 public class UsersController : ControllerBase
13 {
14 private readonly IUserService _users;
15
16 public UsersController(IUserService users)
17 {
18 _users = users;
19 }
20
21 [HttpPost("add")]
22 public async Task<IActionResult> Add([FromBody] User user)
23 {
24 var created = await _users.AddUserAsync(user);
25 return Ok(created);
26 }
27
28 [HttpGet("id/{id}")]
29 public async Task<IActionResult> GetById(int id)
30 {
31 var user = await _users.GetUserByIdAsync(id);
32 if (user == null)
33 return NotFound();
34 return Ok(user);
35 }
36 }
37}
Note: See TracBrowser for help on using the repository browser.