mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 19:00:07 +01:00
usuwanie
This commit is contained in:
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Update.Internal;
|
||||
using QuotifyBE.Data;
|
||||
using QuotifyBE.DTOs;
|
||||
using QuotifyBE.Entities;
|
||||
@@ -72,13 +73,14 @@ public class QuotesController : ControllerBase
|
||||
|
||||
// GET /api/v1/quotes/{id}
|
||||
/// <summary>
|
||||
/// Get specified quote summary
|
||||
/// [AUTH] Get specified quote summary
|
||||
/// </summary>
|
||||
/// <param name="id">The quote id in question</param>
|
||||
/// <returns>A quote: id, quote content and author, imageUrl and categories if successful, otherwise: error message</returns>
|
||||
/// <response code="200">Returned on valid request</response>
|
||||
/// <response code="404">Returned when quote id is invalid or simply doesn't exist</response>
|
||||
[HttpGet("{id}")]
|
||||
[Authorize]
|
||||
[ProducesResponseType(typeof(QuoteShortDTO), 200)]
|
||||
[ProducesResponseType(typeof(ErrorDTO), 404)]
|
||||
public async Task<IActionResult> GetQuoteById(int id)
|
||||
@@ -115,6 +117,7 @@ public class QuotesController : ControllerBase
|
||||
public async Task<IActionResult> CreateQuote([FromBody] CreateQuoteDTO request)
|
||||
{
|
||||
// Get user ID from claims
|
||||
|
||||
var userIdClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
if (userIdClaim == null || !int.TryParse(userIdClaim, out int userId))
|
||||
// https://stackoverflow.com/a/47708867
|
||||
@@ -217,4 +220,20 @@ public class QuotesController : ControllerBase
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(204)]
|
||||
[ProducesResponseType(typeof(ErrorDTO), 404)]
|
||||
//[Authorize]
|
||||
public async Task<IActionResult> DeleteQuote(int id)
|
||||
{
|
||||
var quote = await _db.Quotes
|
||||
.FirstOrDefaultAsync(q => q.Id == id);
|
||||
if(quote==null) return NotFound(new { status = "error", error_msg = "Quote not found" });
|
||||
_db.Quotes.Remove(quote);
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user