added UserContext for easy UserId getting
started writing custom services to implement users logic
This commit is contained in:
parent
d810101033
commit
7a1078457d
6 changed files with 83 additions and 6 deletions
|
|
@ -1,10 +1,10 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SurveyBackend.Core.Contexts;
|
||||
using SurveyBackend.DTOs.Survey;
|
||||
using SurveyLib.Core.Models;
|
||||
using SurveyLib.Core.Services;
|
||||
using SurveyLib.Infrastructure.EFCore.Services;
|
||||
|
||||
namespace SurveyBackend.Controllers;
|
||||
|
||||
|
|
@ -13,10 +13,12 @@ namespace SurveyBackend.Controllers;
|
|||
public class SurveyController : ControllerBase
|
||||
{
|
||||
private readonly ISurveyService _surveyService;
|
||||
private readonly IUserContext _userContext;
|
||||
|
||||
public SurveyController(ISurveyService surveyService)
|
||||
public SurveyController(ISurveyService surveyService, IUserContext userContext)
|
||||
{
|
||||
_surveyService = surveyService;
|
||||
_userContext = userContext;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
@ -39,7 +41,7 @@ public class SurveyController : ControllerBase
|
|||
[HttpPost]
|
||||
public async Task<IActionResult> Post([FromBody] CreateSurveyDTO dto)
|
||||
{
|
||||
var userId = Convert.ToInt32(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value);
|
||||
var userId = _userContext.UserId;
|
||||
|
||||
var survey = new Survey
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue