A lot
This commit is contained in:
@@ -45,6 +45,11 @@ namespace KTUSAPS.Controllers
|
||||
[HttpGet("Authed")]
|
||||
public bool IsAuthed() => true;
|
||||
|
||||
[Authorize]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[HttpGet("Claims")]
|
||||
public IEnumerable<object> Claims() => User.Claims.Select((c) => new { c.Type, c.Value });
|
||||
|
||||
[Authorize("admin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[HttpGet("Admin")]
|
||||
|
@@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using KTUSAPS.Data;
|
||||
using KTUSAPS.Data.Model;
|
||||
using KTUSAPS.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace KTUSAPS.Controllers
|
||||
{
|
||||
@@ -32,6 +33,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Authorize("admin")]
|
||||
public async Task<ActionResult<IssueType>> CreateIssueType([FromBody] IssueType issueType)
|
||||
{
|
||||
if (issueType == null)
|
||||
@@ -64,6 +66,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpPatch("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public async Task<IActionResult> UpdateIssueType(int id, IssueType issueType)
|
||||
{
|
||||
var databaseIssueType = await _context.IssueTypes.FindAsync(id);
|
||||
@@ -86,6 +89,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public async Task<IActionResult> DeleteIssueType(int id)
|
||||
{
|
||||
var issueType = await _context.IssueTypes.FindAsync(id);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using KTUSAPS.Data.Model;
|
||||
using KTUSAPS.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -23,6 +24,7 @@ namespace KTUSAPS.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[Authorize("admin")]
|
||||
public async Task<ActionResult<IEnumerable<Issue>>> GetIssues()
|
||||
{
|
||||
return await dataContext.Issues.ToListAsync();
|
||||
@@ -31,6 +33,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<Issue>> CreateIssueAsync([FromBody] Issue issueToCreate)
|
||||
{
|
||||
if (issueToCreate == null)
|
||||
@@ -41,9 +44,11 @@ namespace KTUSAPS.Controllers
|
||||
return BadRequest("No typeId has been specified");
|
||||
if (issueToCreate.Problem != null && issueToCreate.Feedback != null && issueToCreate.IssueType != null)
|
||||
return BadRequest("Do not privide navigation property values.");
|
||||
// TODO: Enable next line and make thoes two fields come from user identity
|
||||
//if (issueToCreate.UserID != default || issueToCreate.Email != default)
|
||||
// return BadRequest("Do not provide indentity values.");
|
||||
if (issueToCreate.UserID != default || issueToCreate.Email != default)
|
||||
return BadRequest("Do not provide indentity values.");
|
||||
|
||||
issueToCreate.UserID = User.GetUserId();
|
||||
issueToCreate.Email = User.GetEmail();
|
||||
|
||||
var createdValue = await dataContext.AddAsync(issueToCreate);
|
||||
await dataContext.SaveChangesAsync();
|
||||
@@ -54,6 +59,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public ActionResult<Issue> GetIssue(int id)
|
||||
{
|
||||
var issue = dataContext.Issues.AsQueryable().Where(i => i.Id == id).FirstOrDefault();
|
||||
@@ -65,6 +71,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpPatch("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public async Task<ActionResult<Issue>> UpdateIssueAsync(int id, [FromBody] Issue issue)
|
||||
{
|
||||
var databaseIssue = dataContext.Issues.AsQueryable().Where(i => i.Id == id).FirstOrDefault();
|
||||
@@ -83,6 +90,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public async Task<IActionResult> DeleteIssueAsync(int id)
|
||||
{
|
||||
var issue = dataContext.Issues.AsQueryable().Where(i => i.Id == id).FirstOrDefault();
|
||||
|
@@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using KTUSAPS.Data;
|
||||
using KTUSAPS.Data.Model;
|
||||
using KTUSAPS.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace KTUSAPS.Controllers
|
||||
{
|
||||
@@ -32,6 +33,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Authorize("admin")]
|
||||
public async Task<ActionResult<PublishedFeedback>> PostPublishedFeedback(PublishedFeedback publishedFeedback)
|
||||
{
|
||||
if (publishedFeedback == null)
|
||||
@@ -63,6 +65,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpPatch("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public async Task<ActionResult<PublishedFeedback>> UpdatePublishedFeedback(int id, PublishedFeedback publishedFeedback)
|
||||
{
|
||||
var databasePublishedFeedback = await _context.PublishedFeedbacks.FindAsync(id);
|
||||
@@ -88,6 +91,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public async Task<IActionResult> DeletePublishedFeedback(int id)
|
||||
{
|
||||
var publishedFeedback = await _context.PublishedFeedbacks.FindAsync(id);
|
||||
|
@@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using KTUSAPS.Data;
|
||||
using KTUSAPS.Data.Model;
|
||||
using KTUSAPS.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace KTUSAPS.Controllers
|
||||
{
|
||||
@@ -32,6 +33,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[Authorize("admin")]
|
||||
public async Task<ActionResult<PublishedProblem>> CreatePublishedProblem([FromBody] PublishedProblem publishedProblem)
|
||||
{
|
||||
if (publishedProblem == null)
|
||||
@@ -63,6 +65,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpPatch("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public async Task<ActionResult<PublishedProblem>> UpdatePublishedProblem(int id, PublishedProblem publishedProblem)
|
||||
{
|
||||
var databasePublishedProblem = await _context.PublishedProblems.FindAsync(id);
|
||||
@@ -90,6 +93,7 @@ namespace KTUSAPS.Controllers
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize("admin")]
|
||||
public async Task<IActionResult> DeletePublishedProblem(int id)
|
||||
{
|
||||
var publishedProblem = await _context.PublishedProblems.FindAsync(id);
|
||||
@@ -121,17 +125,18 @@ namespace KTUSAPS.Controllers
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult<Vote>> Vote(int id, Vote vote)
|
||||
[Authorize]
|
||||
public async Task<ActionResult<Vote>> Vote(int id)
|
||||
{
|
||||
var publishedProblem = await _context.PublishedProblems.FindAsync(id);
|
||||
if (publishedProblem == null)
|
||||
return NotFound();
|
||||
|
||||
// TODO: Get user id from auth claims
|
||||
if (vote.UserId == default)
|
||||
return BadRequest("Please provide user id");
|
||||
|
||||
vote.Problem = publishedProblem;
|
||||
var vote = new Vote()
|
||||
{
|
||||
Problem = publishedProblem,
|
||||
UserId = User.GetUserId(),
|
||||
};
|
||||
|
||||
_context.Votes.Add(vote);
|
||||
await _context.SaveChangesAsync();
|
||||
|
Reference in New Issue
Block a user