diff --git a/web/Backend/Backend.csproj b/web/Backend/Backend.csproj index 60bf9ea..2fc9318 100644 --- a/web/Backend/Backend.csproj +++ b/web/Backend/Backend.csproj @@ -10,4 +10,8 @@ + + + + diff --git a/web/Backend/Controllers/IssueController.cs b/web/Backend/Controllers/IssueController.cs new file mode 100644 index 0000000..8524b51 --- /dev/null +++ b/web/Backend/Controllers/IssueController.cs @@ -0,0 +1,46 @@ +using Backend.Models; +using Backend.Repositories; +using Microsoft.AspNetCore.Mvc; + +namespace Backend.Controllers; + +[ApiController] +[Route("[controller]")] +public class IssueController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + private IIssueRepository _issueRepository; + + public IssueController( + ILogger logger, + IIssueRepository issueRepository) + { + _issueRepository = issueRepository; + _logger = logger; + } + + [HttpGet()] + public IActionResult Get(int id) + { + return Ok(_issueRepository.GetIssues()); + } + + [HttpGet("{id:int}")] + public IActionResult GetById(int id) + { + var result = _issueRepository.GetIssueById(id); + return (result != null) ? Ok(result) : NotFound(); + } + + [HttpGet("{project}")] + public IActionResult GetByProject(string project) + { + Issue[]? result = _issueRepository.GetIssuesByProject(project); + return (result != null) ? Ok(result) : NotFound(new {Title = "ERROR"}); + } +} diff --git a/web/Backend/Controllers/WeatherForecastController.cs b/web/Backend/Controllers/WeatherForecastController.cs index 81be1c4..3845814 100644 --- a/web/Backend/Controllers/WeatherForecastController.cs +++ b/web/Backend/Controllers/WeatherForecastController.cs @@ -1,3 +1,4 @@ +using Backend.Models; using Microsoft.AspNetCore.Mvc; namespace Backend.Controllers; diff --git a/web/Backend/Models/Issue.cs b/web/Backend/Models/Issue.cs new file mode 100644 index 0000000..79ef3a6 --- /dev/null +++ b/web/Backend/Models/Issue.cs @@ -0,0 +1,12 @@ +namespace Backend.Models; + +public class Issue +{ + public DateTimeOffset Created { get; set; } = DateTimeOffset.Now; + public DateTimeOffset Updated { get; set; } = DateTimeOffset.Now; + public string Title { get; set; } = ""; + public string Project { get; set; } = "UNKOWN"; + public string? Text { get; set; } + public int IssueId { get; set; } + public int? ParentId { get; set; } +} diff --git a/web/Backend/WeatherForecast.cs b/web/Backend/Models/WeatherForecast.cs similarity index 89% rename from web/Backend/WeatherForecast.cs rename to web/Backend/Models/WeatherForecast.cs index fdb8cd8..7da593e 100644 --- a/web/Backend/WeatherForecast.cs +++ b/web/Backend/Models/WeatherForecast.cs @@ -1,4 +1,4 @@ -namespace Backend; +namespace Backend.Models; public class WeatherForecast { diff --git a/web/Backend/Program.cs b/web/Backend/Program.cs index 48863a6..55b01bd 100644 --- a/web/Backend/Program.cs +++ b/web/Backend/Program.cs @@ -1,3 +1,6 @@ +using Backend.Repositories; +using Backend.Services; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -7,6 +10,9 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/web/Backend/Repositories/IIssueRepository.cs b/web/Backend/Repositories/IIssueRepository.cs new file mode 100644 index 0000000..b13b672 --- /dev/null +++ b/web/Backend/Repositories/IIssueRepository.cs @@ -0,0 +1,10 @@ +namespace Backend.Repositories; + +using Backend.Models; + +public interface IIssueRepository +{ + Issue? GetIssueById(int Id); + Issue[] GetIssues(); + Issue[]? GetIssuesByProject(string Project); +} \ No newline at end of file diff --git a/web/Backend/Repositories/IssueRepository.cs b/web/Backend/Repositories/IssueRepository.cs new file mode 100644 index 0000000..5a98d92 --- /dev/null +++ b/web/Backend/Repositories/IssueRepository.cs @@ -0,0 +1,58 @@ +using Backend.Models; + +namespace Backend.Repositories; + +public class IssueRepository : IIssueRepository +{ + private static Issue[] issues = { + new Issue(){ + IssueId = 1, + Title = "Handle Issues with API", + Project = "PRJ", + Text = "

API should handle issues.

" + }, + new Issue(){ + IssueId = 2, + Title = "Handle Issues with API GET", + Project = "PRJ", + Text = "

GET should handle issues.

", + ParentId = 1 + }, + new Issue(){ + IssueId = 3, + Title = "Handle Issues with API POST", + Project = "PRJ", + Text = "

POST should handle issues.

", + ParentId = 1 + }, + new Issue(){ + IssueId = 4, + Title = "This is a Test Issue", + Project = "TEST", + Text = "

This is a Test Issue

", + ParentId = 1 + }, + }; + + public IssueRepository() + { + + } + + public Issue[] GetIssues() + { + return issues; + } + + public Issue? GetIssueById(int Id) + { + Issue issue = issues.Where(p => p.IssueId == Id).First(); + return issue; + } + + public Issue[]? GetIssuesByProject(string Project) + { + Issue[] FoundIssues = issues.Where(p => p.Project.ToLower() == Project.ToLower()).ToArray(); + return FoundIssues; + } +} \ No newline at end of file diff --git a/web/Backend/Services/ITestService.cs b/web/Backend/Services/ITestService.cs new file mode 100644 index 0000000..2ffe7da --- /dev/null +++ b/web/Backend/Services/ITestService.cs @@ -0,0 +1,6 @@ +using Backend.Services; + +public interface ITestService +{ + void Test(); +} \ No newline at end of file diff --git a/web/Backend/Services/TestService.cs b/web/Backend/Services/TestService.cs new file mode 100644 index 0000000..4d4fd4f --- /dev/null +++ b/web/Backend/Services/TestService.cs @@ -0,0 +1,14 @@ +namespace Backend.Services; + +public class TestService : ITestService +{ + public TestService() + { + + } + + public void Test() + { + + } +} \ No newline at end of file