added CreatedBy to surveys
This commit is contained in:
parent
3b6952364c
commit
dbcdfac698
7 changed files with 443 additions and 22 deletions
|
|
@ -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