From 640dda2aa3cba0693f1c275ae52b7407e2cba5d8 Mon Sep 17 00:00:00 2001 From: jfhr Date: Tue, 26 May 2020 14:50:26 +0200 Subject: [PATCH] Projekt-Vorlage mit Tasks Controller --- .gitignore | 268 ++++++++++++++++++ ScrumTaskboard/Controllers/TasksController.cs | 115 ++++++++ ScrumTaskboard/Program.cs | 26 ++ ScrumTaskboard/Properties/launchSettings.json | 30 ++ ScrumTaskboard/ScrumTaskboard.csproj | 20 ++ ScrumTaskboard/Startup.cs | 62 ++++ ScrumTaskboard/TaskContext.cs | 41 +++ ScrumTaskboard/appsettings.Development.json | 9 + ScrumTaskboard/appsettings.json | 10 + backend.sln | 25 ++ 10 files changed, 606 insertions(+) create mode 100644 .gitignore create mode 100644 ScrumTaskboard/Controllers/TasksController.cs create mode 100644 ScrumTaskboard/Program.cs create mode 100644 ScrumTaskboard/Properties/launchSettings.json create mode 100644 ScrumTaskboard/ScrumTaskboard.csproj create mode 100644 ScrumTaskboard/Startup.cs create mode 100644 ScrumTaskboard/TaskContext.cs create mode 100644 ScrumTaskboard/appsettings.Development.json create mode 100644 ScrumTaskboard/appsettings.json create mode 100644 backend.sln diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f537fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,268 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ \ No newline at end of file diff --git a/ScrumTaskboard/Controllers/TasksController.cs b/ScrumTaskboard/Controllers/TasksController.cs new file mode 100644 index 0000000..e5f3e68 --- /dev/null +++ b/ScrumTaskboard/Controllers/TasksController.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 TasksController : ControllerBase + { + private readonly TaskContext _context; + + public TasksController(TaskContext context) + { + _context = context; + } + + // GET: api/Tasks + [HttpGet] + public async Task>> GetTasks() + { + return await _context.Tasks.ToListAsync(); + } + + // GET: api/Tasks/5 + [HttpGet("{id}")] + public async Task> GetTask(int id) + { + var task = await _context.Tasks.FindAsync(id); + + if (task == null) + { + return NotFound(); + } + + return task; + } + + // PUT: api/Tasks/5 + [HttpPut("{id}")] + public async Task PutTask(int id, ScrumTask task) + { + // Die ID des Tasks darf nicht geändert werden + if (id != task.Id) + { + return BadRequest(); + } + + // Speichere den geänderten Task im Context + _context.Entry(task).State = EntityState.Modified; + + try + { + // Übernehme die Änderungen in die Datenbank + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + // Wenn der Task nicht existiert, gib Statuscode 404 zurück + if (!TaskExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/Tasks + [HttpPost] + public async Task> PostTask(ScrumTask task) + { + _context.Tasks.Add(task); + await _context.SaveChangesAsync(); + + // Der neue Task wurde erstellt und kann über die GetTask Methode abgerufen werden. + return CreatedAtAction("GetTask", new { id = task.Id }, task); + } + + // DELETE: api/Tasks/5 + [HttpDelete("{id}")] + public async Task> DeleteTask(int id) + { + var scrumTask = await _context.Tasks.FindAsync(id); + if (scrumTask == null) + { + return NotFound(); + } + + // Entferne den Task aus dem Context + _context.Tasks.Remove(scrumTask); + // Speichere die Änderungen in der Datenbank + await _context.SaveChangesAsync(); + + return scrumTask; + } + + /// + /// Prüft, ob ein Task mit der angegebenen ID bereits existiert. + /// + private bool TaskExists(int id) + { + return _context.Tasks.Any(e => e.Id == id); + } + } +} diff --git a/ScrumTaskboard/Program.cs b/ScrumTaskboard/Program.cs new file mode 100644 index 0000000..611403f --- /dev/null +++ b/ScrumTaskboard/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace ScrumTaskboard +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/ScrumTaskboard/Properties/launchSettings.json b/ScrumTaskboard/Properties/launchSettings.json new file mode 100644 index 0000000..b0f5985 --- /dev/null +++ b/ScrumTaskboard/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:51447", + "sslPort": 44334 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "ScrumTaskboard": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "tasks", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/ScrumTaskboard/ScrumTaskboard.csproj b/ScrumTaskboard/ScrumTaskboard.csproj new file mode 100644 index 0000000..436c762 --- /dev/null +++ b/ScrumTaskboard/ScrumTaskboard.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp3.1 + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/ScrumTaskboard/Startup.cs b/ScrumTaskboard/Startup.cs new file mode 100644 index 0000000..52e6e0f --- /dev/null +++ b/ScrumTaskboard/Startup.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace ScrumTaskboard +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddScoped(serviceProvider => new TaskContext( + new DbContextOptionsBuilder() + .UseNpgsql("Host=nig.gl; Port=8543; Username=scrum; Database=taskboard; Password=c6gXud7YvBWp2sgxSgy4wRN") + .Options)); + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + using (var serviceScope = app.ApplicationServices.GetService().CreateScope()) + { + var context = serviceScope.ServiceProvider.GetRequiredService(); + context.Database.EnsureCreated(); + } + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/ScrumTaskboard/TaskContext.cs b/ScrumTaskboard/TaskContext.cs new file mode 100644 index 0000000..a6d74e7 --- /dev/null +++ b/ScrumTaskboard/TaskContext.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore; +using System; + +namespace ScrumTaskboard +{ + public class TaskContext : DbContext + { + public DbSet Tasks { get; set; } + + public TaskContext() { } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseNpgsql("Host=nig.gl; Port=8543; Username=scrum; Database=taskboard; Password=c6gXud7YvBWp2sgxSgy4wRN"); + } + + public TaskContext(DbContextOptions options) : base(options) { } + } + + public class ScrumTask + { + public int Id { get; set; } + + public string Titel { get; set; } + + public string Inhalt { get; set; } + + + + + public int Status { get; set; } + public int Kategorie { get; set; } + public int Bearbeiter { get; set; } + + public int ZugeordneterSprint { get; set; } + public int Projekt { get; set; } + + + public int Userstory { get; set; } + } +} diff --git a/ScrumTaskboard/appsettings.Development.json b/ScrumTaskboard/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/ScrumTaskboard/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/ScrumTaskboard/appsettings.json b/ScrumTaskboard/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/ScrumTaskboard/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/backend.sln b/backend.sln new file mode 100644 index 0000000..e9d9960 --- /dev/null +++ b/backend.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScrumTaskboard", "ScrumTaskboard\ScrumTaskboard.csproj", "{89C3626D-3B68-4870-A495-41634F2C9B9F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {89C3626D-3B68-4870-A495-41634F2C9B9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89C3626D-3B68-4870-A495-41634F2C9B9F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89C3626D-3B68-4870-A495-41634F2C9B9F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89C3626D-3B68-4870-A495-41634F2C9B9F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {52295A4B-00F7-4981-A892-C3CA70EAB6EF} + EndGlobalSection +EndGlobal