diff --git a/ScrumTaskboard/Controllers/CategoriesController.cs b/ScrumTaskboard/Controllers/CategoriesController.cs new file mode 100644 index 0000000..7c637ba --- /dev/null +++ b/ScrumTaskboard/Controllers/CategoriesController.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace ScrumTaskboard.Controllers +{ + [Route("[controller]")] + [ApiController] + public class CategoriesController : ControllerBase + { + private readonly TaskContext _context; + + public CategoriesController(TaskContext context) + { + _context = context; + } + + // GET: api/category + [HttpGet] + public async Task>> GetCategory() + { + return await _context.Categories.ToListAsync(); + } + + // GET: api/category/1 + [HttpGet("{id}")] + public async Task> GetCategory(int id) + { + var category = await _context.Categories.FindAsync(id); + + if (category == null) + { + return NotFound(); + } + + return category; + } + + // PUT: api/category/1 + [HttpPut("{id}")] + public async Task PutCategory(int id, ScrumCategory category) + { + // Die ID der Kategorie darf nicht geändert werden + if (id != category.id) + { + return BadRequest(); + } + + // Speichere die geänderten Kategorie im Context + _context.Entry(category).State = EntityState.Modified; + + try + { + // Übernehme die Änderungen in die Datenbank + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + // Wenn die Kategorie nicht existiert, gib Statuscode 404 zurück + if (!CategoryExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/category + [HttpPost] + public async Task> PostCategory(ScrumCategory category) + { + _context.Categories.Add(category); + await _context.SaveChangesAsync(); + + // Die neue Userstory wurde erstellt und kann über die GetUserstory Methode abgerufen werden. + return CreatedAtAction("GetCategory", new { id = category.id }, category); + } + + // DELETE: api/category/1 + [HttpDelete("{id}")] + public async Task> DeleteCategory(int id) + { + var category = await _context.Categories.FindAsync(id); + if (category == null) + { + return NotFound(); + } + + // Entferne die Kateorie aus dem Context + _context.Categories.Remove(category); + // Speichere die Änderungen in der Datenbank + await _context.SaveChangesAsync(); + + return category; + } + + /// + /// Prüft, ob eine Kategorie mit der angegebenen ID bereits existiert. + /// + private bool CategoryExists(int id) + { + return _context.Categories.Any(e => e.id == id); + } + } +} \ No newline at end of file diff --git a/ScrumTaskboard/Controllers/ProjectsController.cs b/ScrumTaskboard/Controllers/ProjectsController.cs new file mode 100644 index 0000000..dcf6100 --- /dev/null +++ b/ScrumTaskboard/Controllers/ProjectsController.cs @@ -0,0 +1,113 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace ScrumTaskboard.Controllers +{ + [Route("[controller]")] + [ApiController] + public class ProjectsController : ControllerBase + { + private readonly TaskContext _context; + + public ProjectsController(TaskContext context) + { + _context = context; + } + + // GET: api/projects + [HttpGet] + public async Task>> GetProject() + { + return await _context.Projects.ToListAsync(); + } + + // GET: api/projects/5 + [HttpGet("{id}")] + public async Task> GetProjects(int id) + { + var Project = await _context.Projects.FindAsync(id); + + if (Project == null) + { + return NotFound(); + } + + return Project; + } + + // PUT: api/Project/5 + [HttpPut("{id}")] + public async Task PutProject(int id, ScrumProject projects) + { + // Die ID des Projects darf nicht geändert werden + if (id != projects.id) + { + return BadRequest(); + } + + // Speichere den geänderten Project im Context + _context.Entry(projects).State = EntityState.Modified; + + try + { + // Übernehme die Änderungen in die Datenbank + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + // Wenn der Project nicht existiert, gib Statuscode 404 zurück + if (!ProjectExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/Project + [HttpPost] + public async Task> PostProject(ScrumProject projects) + { + _context.Projects.Add(projects); + await _context.SaveChangesAsync(); + + // Der neue Project wurde erstellt und kann über die GetProject Methode abgerufen werden. + return CreatedAtAction("GetProject", new { id = projects.id }, projects); + } + + // DELETE: api/Project/5 + [HttpDelete("{id}")] + public async Task> DeleteProject(int id) + { + var scrumProject = await _context.Projects.FindAsync(id); + if (scrumProject == null) + { + return NotFound(); + } + + // Entferne den Project aus dem Context + _context.Projects.Remove(scrumProject); + // Speichere die Änderungen in der Datenbank + await _context.SaveChangesAsync(); + + return scrumProject; + } + + /// + /// Prüft, ob ein Project mit der angegebenen ID bereits existiert. + /// + private bool ProjectExists(int id) + { + return _context.Projects.Any(e => e.id == id); + } + } +} \ No newline at end of file diff --git a/ScrumTaskboard/Controllers/SprintsController.cs b/ScrumTaskboard/Controllers/SprintsController.cs new file mode 100644 index 0000000..c5856e1 --- /dev/null +++ b/ScrumTaskboard/Controllers/SprintsController.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace ScrumTaskboard.Controllers +{ + [Route("[controller]")] + [ApiController] + public class SprintsController : ControllerBase + { + private readonly TaskContext _context; + + public SprintsController(TaskContext context) + { + _context = context; + } + + // GET: api/sprint + [HttpGet] + public async Task>> GetSprint() + { + return await _context.Sprints.ToListAsync(); + } + + // GET: api/sprint/5 + [HttpGet("{id}")] + public async Task> GetSprint(int id) + { + var Sprint = await _context.Sprints.FindAsync(id); + + if (Sprint == null) + { + return NotFound(); + } + + return Sprint; + } + + // PUT: api/sprint/5 + [HttpPut("{id}")] + public async Task PutSprint(int id, ScrumSprint sprint) + { + // Die ID des Sprints darf nicht geändert werden + if (id != sprint.id) + { + return BadRequest(); + } + + // Speichere den geänderten Sprint im Context + _context.Entry(sprint).State = EntityState.Modified; + + try + { + // Übernehme die Änderungen in die Datenbank + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + // Wenn der Sprint nicht existiert, gib Statuscode 404 zurück + if (!SprintExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/Sprint + [HttpPost] + public async Task> PostSprint(ScrumSprint sprint) + { + _context.Sprints.Add(sprint); + await _context.SaveChangesAsync(); + + // Der neue Sprint wurde erstellt und kann über die GetSprint Methode abgerufen werden. + return CreatedAtAction("GetSprint", new { id = sprint.id }, sprint); + } + + // DELETE: api/Sprint/5 + [HttpDelete("{id}")] + public async Task> DeleteSprint(int id) + { + var scrumSprint = await _context.Sprints.FindAsync(id); + if (scrumSprint == null) + { + return NotFound(); + } + + // Entferne den Sprint aus dem Context + _context.Sprints.Remove(scrumSprint); + // Speichere die Änderungen in der Datenbank + await _context.SaveChangesAsync(); + + return scrumSprint; + } + + /// + /// Prüft, ob ein Sprint mit der angegebenen ID bereits existiert. + /// + private bool SprintExists(int id) + { + return _context.Sprints.Any(e => e.id == id); + } + } +} diff --git a/ScrumTaskboard/Controllers/StatusController.cs b/ScrumTaskboard/Controllers/StatusController.cs new file mode 100644 index 0000000..30e98d0 --- /dev/null +++ b/ScrumTaskboard/Controllers/StatusController.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace ScrumTaskboard.Controllers +{ + [Route("[controller]")] + [ApiController] + public class StatusController : ControllerBase + { + private readonly TaskContext _context; + + public StatusController(TaskContext context) + { + _context = context; + } + + // GET: api/status + [HttpGet] + public async Task>> GetStatus() + { + return await _context.Status.ToListAsync(); + } + + // GET: api/status/1 + [HttpGet("{id}")] + public async Task> GetStatus(int id) + { + var userstory = await _context.Status.FindAsync(id); + + if (userstory == null) + { + return NotFound(); + } + + return userstory; + } + + // PUT: api/status/1 + [HttpPut("{id}")] + public async Task PutStatus(int id, ScrumStatus userstory) + { + // Die ID des Status darf nicht geändert werden + if (id != userstory.id) + { + return BadRequest(); + } + + // Speichere deb geänderten Status im Context + _context.Entry(userstory).State = EntityState.Modified; + + try + { + // Übernehme die Änderungen in die Datenbank + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + // Wenn der Status nicht existiert, gib Statuscode 404 zurück + if (!StatusExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/status + [HttpPost] + public async Task> PostTask(ScrumStatus userstory) + { + _context.Status.Add(userstory); + await _context.SaveChangesAsync(); + + // Der neue Status wurde erstellt und kann über die GetStatus Methode abgerufen werden. + return CreatedAtAction("GetStatus", new { id = userstory.id }, userstory); + } + + // DELETE: api/status/1 + [HttpDelete("{id}")] + public async Task> DeleteStatus(int id) + { + var userstory = await _context.Status.FindAsync(id); + if (userstory == null) + { + return NotFound(); + } + + // Entferne den Status aus dem Context + _context.Status.Remove(userstory); + // Speichere die Änderungen in der Datenbank + await _context.SaveChangesAsync(); + + return userstory; + } + + /// + /// Prüft, ob ein Status mit der angegebenen ID bereits existiert. + /// + private bool StatusExists(int id) + { + return _context.Status.Any(e => e.id == id); + } + } +} \ No newline at end of file diff --git a/ScrumTaskboard/Controllers/UsersController.cs b/ScrumTaskboard/Controllers/UsersController.cs new file mode 100644 index 0000000..d8895f1 --- /dev/null +++ b/ScrumTaskboard/Controllers/UsersController.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace ScrumTaskboard.Controllers +{ + [Route("[controller]")] + [ApiController] + public class UsersController : ControllerBase + { + private readonly TaskContext _context; + + public UsersController(TaskContext context) + { + _context = context; + } + + // GET: api/sprint + [HttpGet] + public async Task>> GetUser() + { + return await _context.Users.ToListAsync(); + } + + // GET: api/sprint/5 + [HttpGet("{id}")] + public async Task> GetUser(int id) + { + var User = await _context.Users.FindAsync(id); + + if (User == null) + { + return NotFound(); + } + + return User; + } + + // PUT: api/sprint/5 + [HttpPut("{id}")] + public async Task PutUser(int id, ScrumUser sprint) + { + // Die ID des Users darf nicht geändert werden + if (id != sprint.id) + { + return BadRequest(); + } + + // Speichere den geänderten User im Context + _context.Entry(sprint).State = EntityState.Modified; + + try + { + // Übernehme die Änderungen in die Datenbank + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + // Wenn der User nicht existiert, gib Statuscode 404 zurück + if (!UserExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/User + [HttpPost] + public async Task> PostUser(ScrumUser sprint) + { + _context.Users.Add(sprint); + await _context.SaveChangesAsync(); + + // Der neue User wurde erstellt und kann über die GetUser Methode abgerufen werden. + return CreatedAtAction("GetUser", new { id = sprint.id }, sprint); + } + + // DELETE: api/User/5 + [HttpDelete("{id}")] + public async Task> DeleteUser(int id) + { + var scrumUser = await _context.Users.FindAsync(id); + if (scrumUser == null) + { + return NotFound(); + } + + // Entferne den User aus dem Context + _context.Users.Remove(scrumUser); + // Speichere die Änderungen in der Datenbank + await _context.SaveChangesAsync(); + + return scrumUser; + } + + /// + /// Prüft, ob ein User mit der angegebenen ID bereits existiert. + /// + private bool UserExists(int id) + { + return _context.Users.Any(e => e.id == id); + } + } +} \ No newline at end of file diff --git a/ScrumTaskboard/Controllers/UserstoriesController.cs b/ScrumTaskboard/Controllers/UserstoriesController.cs new file mode 100644 index 0000000..9fcf9dc --- /dev/null +++ b/ScrumTaskboard/Controllers/UserstoriesController.cs @@ -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>> GetUserstory() + { + return await _context.Userstories.ToListAsync(); + } + + // GET: api/userstories/1 + [HttpGet("{id}")] + public async Task> 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 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> 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> 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; + } + + /// + /// Prüft, ob eine Userstory mit der angegebenen ID bereits existiert. + /// + private bool UserstoryExists(int id) + { + return _context.Userstories.Any(e => e.id == id); + } + } +} \ No newline at end of file diff --git a/ScrumTaskboard/ScrumTaskboard.csproj b/ScrumTaskboard/ScrumTaskboard.csproj index 436c762..510a70d 100644 --- a/ScrumTaskboard/ScrumTaskboard.csproj +++ b/ScrumTaskboard/ScrumTaskboard.csproj @@ -1,20 +1,21 @@ - - - - netcoreapp3.1 - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + netcoreapp3.1 + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/ScrumTaskboard/Startup.cs b/ScrumTaskboard/Startup.cs index bca8624..d94da98 100644 --- a/ScrumTaskboard/Startup.cs +++ b/ScrumTaskboard/Startup.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Serialization; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -26,6 +27,7 @@ namespace ScrumTaskboard // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + { services.AddCors(o => o.AddPolicy("AllowAll", builder => { builder.AllowAnyOrigin() @@ -35,7 +37,11 @@ namespace ScrumTaskboard services.AddScoped(serviceProvider => new TaskContext( new DbContextOptionsBuilder() .UseNpgsql(GetConnectionString()) - .Options)); + services.AddMvc().AddJsonOptions(o => + { + o.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); + o.JsonSerializerOptions.IgnoreNullValues = true; + }); services.AddControllers(); } @@ -65,36 +71,5 @@ namespace ScrumTaskboard endpoints.MapControllers(); }); } - - /// - /// Creates DB Connection String based on ENV vars and default vars. - /// - /// - public string GetConnectionString() - { - string dbHost; - string dbPort; - string dbName; - string dbUser; - string dbPassword; - - dbHost = Environment.GetEnvironmentVariable("DATABASE_HOST"); - dbPort = Environment.GetEnvironmentVariable("DATABASE_PORT"); - dbName = Environment.GetEnvironmentVariable("DATABASE_NAME"); - dbUser = Environment.GetEnvironmentVariable("DATABASE_USER"); - dbPassword = Environment.GetEnvironmentVariable("DATABASE_PASSWORD"); - - if(dbHost == null || dbPort == null || dbName == null || dbUser == null || dbPassword == null) - { - dbHost = "nig.gl"; - dbPort = "8543"; - dbName = "taskboard"; - dbUser = "scrum"; - dbPassword = "c6gXud7YvBWp2sgxSgy4wRN"; - } - - - return $"Host={dbHost}; Port={dbPort}; Username={dbUser}; Database={dbName}; Password={dbPassword}"; - } } } diff --git a/ScrumTaskboard/TaskContext.cs b/ScrumTaskboard/TaskContext.cs index 1d89481..1bf0247 100644 --- a/ScrumTaskboard/TaskContext.cs +++ b/ScrumTaskboard/TaskContext.cs @@ -1,11 +1,18 @@ using Microsoft.EntityFrameworkCore; using System; - +using System.Runtime.Serialization; + namespace ScrumTaskboard { public class TaskContext : DbContext { public DbSet Tasks { get; set; } + public DbSet Userstories { get; set; } + public DbSet Categories { get; set; } + public DbSet Sprints { get; set; } + public DbSet Status { get; set; } + public DbSet Projects { get; set; } + public DbSet Users { get; set; } public TaskContext() { } @@ -23,5 +30,67 @@ namespace ScrumTaskboard public int sprint { get; set; } public int project { get; set; } public int userstory { get; set; } + public ScrumPrio priority { get; set; } + } + + public class ScrumUserstory + { + public int id { get; set; } + public string title { get; set; } + public string content { get; set; } + public ScrumPrio priority { get; set; } + public int status { get; set; } + public int category { get; set; } + public int createdby { get; set; } + public int project { get; set; } + } + + public class ScrumCategory + { + public int id { get; set; } + public string title { get; set; } + public string description { get; set; } + public string color { get; set; } + public int project { get; set; } + } + + public class ScrumSprint + { + public int id { get; set; } + public string title { get; set; } + public string description { get; set; } + public DateTime startDate { get; set; } + public DateTime endDate { get; set; } + public int project { get; set; } + } + + public class ScrumStatus + { + public int id { get; set; } + public string title { get; set; } + public string description { get; set; } + } + + public class ScrumProject + { + public int id { get; set; } + public string title { get; set; } + public bool isprivate { get; set; } + } + + public class ScrumUser + { + public int id { get; set; } + public string name { get; set; } + } + + public enum ScrumPrio + { + [EnumMember(Value = "low")] + low, + [EnumMember(Value = "medium")] + medium, + [EnumMember(Value = "high")] + high } }