added CreatedBy to surveys
This commit is contained in:
parent
3b6952364c
commit
dbcdfac698
7 changed files with 443 additions and 22 deletions
|
|
@ -1,7 +1,8 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SurveyBackend.Core.Services;
|
||||
using SurveyBackend.DTOs;
|
||||
using SurveyBackend.Mappers.UserDTOs;
|
||||
using IAuthorizationService = SurveyBackend.Core.Services.IAuthorizationService;
|
||||
|
||||
namespace SurveyBackend.Controllers;
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ public class AuthController : ControllerBase
|
|||
_authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("login")]
|
||||
public async Task<IActionResult> LogIn([FromBody] UserLoginDto loginData)
|
||||
{
|
||||
|
|
@ -23,10 +25,12 @@ public class AuthController : ControllerBase
|
|||
return Ok(new { token = token });
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("register")]
|
||||
public async Task<IActionResult> Register([FromBody] UserRegistrationDto registerData)
|
||||
{
|
||||
var token = await _authorizationService.RegisterUser(UserRegistrationMapper.UserRegistrationToModel(registerData));
|
||||
var token = await _authorizationService.RegisterUser(
|
||||
UserRegistrationMapper.UserRegistrationToModel(registerData));
|
||||
return Ok(new { token = token });
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SurveyBackend.DTOs.Survey;
|
||||
using SurveyLib.Core.Models;
|
||||
|
|
@ -17,6 +19,7 @@ public class SurveyController : ControllerBase
|
|||
_surveyService = surveyService;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
|
|
@ -24,6 +27,7 @@ public class SurveyController : ControllerBase
|
|||
return Ok(result);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
|
|
@ -31,18 +35,23 @@ public class SurveyController : ControllerBase
|
|||
return result is not null ? Ok(result) : NotFound();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Post([FromBody] CreateSurveyDTO dto)
|
||||
{
|
||||
var userId = Convert.ToInt32(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value);
|
||||
|
||||
var survey = new Survey
|
||||
{
|
||||
Title = dto.Title,
|
||||
Description = dto.Description,
|
||||
CreatedBy = userId,
|
||||
};
|
||||
await _surveyService.AddSurveyAsync(survey);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> Delete(int id)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue