A lot
This commit is contained in:
@@ -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