Merge branch 'master' into feature/api-explorer
This commit is contained in:
commit
405bb20769
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ScrumTaskboard;
|
||||
|
||||
namespace ScrumTaskboard.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class UserstoriesController : ControllerBase
|
||||
{
|
||||
private readonly TaskContext _context;
|
||||
|
||||
public UserstoriesController(TaskContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/userstories
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<ScrumUserstory>>> GetUserstory()
|
||||
{
|
||||
return await _context.Userstories.ToListAsync();
|
||||
}
|
||||
|
||||
// GET: api/userstories/1
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<ScrumUserstory>> GetUserstory(int id)
|
||||
{
|
||||
var userstory = await _context.Userstories.FindAsync(id);
|
||||
|
||||
if (userstory == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return userstory;
|
||||
}
|
||||
|
||||
// PUT: api/userstories/1
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutUserstory(int id, ScrumUserstory userstory)
|
||||
{
|
||||
// Die ID der Userstory darf nicht geändert werden
|
||||
if (id != userstory.id)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
// Speichere die geänderten Userstory im Context
|
||||
_context.Entry(userstory).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
// Übernehme die Änderungen in die Datenbank
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
// Wenn die Userstory nicht existiert, gib Statuscode 404 zurück
|
||||
if (!UserstoryExists(id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// POST: api/userstories
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ScrumUserstory>> PostTask(ScrumUserstory userstory)
|
||||
{
|
||||
_context.Userstories.Add(userstory);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Die neue Userstory wurde erstellt und kann über die GetUserstory Methode abgerufen werden.
|
||||
return CreatedAtAction("GetUserstory", new { id = userstory.id }, userstory);
|
||||
}
|
||||
|
||||
// DELETE: api/userstories/1
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult<ScrumUserstory>> DeleteUserstory(int id)
|
||||
{
|
||||
var userstory = await _context.Userstories.FindAsync(id);
|
||||
if (userstory == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// Entferne die Userstory aus dem Context
|
||||
_context.Userstories.Remove(userstory);
|
||||
// Speichere die Änderungen in der Datenbank
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return userstory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prüft, ob eine Userstory mit der angegebenen ID bereits existiert.
|
||||
/// </summary>
|
||||
private bool UserstoryExists(int id)
|
||||
{
|
||||
return _context.Userstories.Any(e => e.id == id);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0-preview1.19506.1" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.3" />
|
||||
<PackageReference Include="NSwag.AspNetCore" Version="13.6.0" />
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace ScrumTaskboard
|
|||
public class TaskContext : DbContext
|
||||
{
|
||||
public DbSet<ScrumTask> Tasks { get; set; }
|
||||
public DbSet<ScrumUserstory> Userstories { get; set; }
|
||||
|
||||
public TaskContext() { }
|
||||
|
||||
|
@ -29,4 +30,16 @@ namespace ScrumTaskboard
|
|||
public int project { get; set; }
|
||||
public int userstory { get; set; }
|
||||
}
|
||||
|
||||
public class ScrumUserstory
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string title { get; set; }
|
||||
public string content { get; set; }
|
||||
public int priority { get; set; }
|
||||
public int status { get; set; }
|
||||
public int category { get; set; }
|
||||
public int createdby { get; set; }
|
||||
public int project { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue