Backend: Add start issues controller implementation
This commit is contained in:
parent
c84ef99efd
commit
9fb24dea73
@ -10,4 +10,8 @@
|
|||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Backend.DataAccess\Backend.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
46
web/Backend/Controllers/IssueController.cs
Normal file
46
web/Backend/Controllers/IssueController.cs
Normal file
@ -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<IssueController> _logger;
|
||||||
|
private IIssueRepository _issueRepository;
|
||||||
|
|
||||||
|
public IssueController(
|
||||||
|
ILogger<IssueController> 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"});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
using Backend.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Backend.Controllers;
|
namespace Backend.Controllers;
|
||||||
|
|||||||
12
web/Backend/Models/Issue.cs
Normal file
12
web/Backend/Models/Issue.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
namespace Backend;
|
namespace Backend.Models;
|
||||||
|
|
||||||
public class WeatherForecast
|
public class WeatherForecast
|
||||||
{
|
{
|
||||||
@ -1,3 +1,6 @@
|
|||||||
|
using Backend.Repositories;
|
||||||
|
using Backend.Services;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
@ -7,6 +10,9 @@ builder.Services.AddControllers();
|
|||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
builder.Services.AddTransient<IIssueRepository, IssueRepository>();
|
||||||
|
builder.Services.AddTransient<ITestService, TestService>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|||||||
10
web/Backend/Repositories/IIssueRepository.cs
Normal file
10
web/Backend/Repositories/IIssueRepository.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace Backend.Repositories;
|
||||||
|
|
||||||
|
using Backend.Models;
|
||||||
|
|
||||||
|
public interface IIssueRepository
|
||||||
|
{
|
||||||
|
Issue? GetIssueById(int Id);
|
||||||
|
Issue[] GetIssues();
|
||||||
|
Issue[]? GetIssuesByProject(string Project);
|
||||||
|
}
|
||||||
58
web/Backend/Repositories/IssueRepository.cs
Normal file
58
web/Backend/Repositories/IssueRepository.cs
Normal file
@ -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 = "<p>API should handle issues.</p>"
|
||||||
|
},
|
||||||
|
new Issue(){
|
||||||
|
IssueId = 2,
|
||||||
|
Title = "Handle Issues with API GET",
|
||||||
|
Project = "PRJ",
|
||||||
|
Text = "<p>GET should handle issues.</p>",
|
||||||
|
ParentId = 1
|
||||||
|
},
|
||||||
|
new Issue(){
|
||||||
|
IssueId = 3,
|
||||||
|
Title = "Handle Issues with API POST",
|
||||||
|
Project = "PRJ",
|
||||||
|
Text = "<p>POST should handle issues.</p>",
|
||||||
|
ParentId = 1
|
||||||
|
},
|
||||||
|
new Issue(){
|
||||||
|
IssueId = 4,
|
||||||
|
Title = "This is a Test Issue",
|
||||||
|
Project = "TEST",
|
||||||
|
Text = "<p>This is a Test Issue</p>",
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
6
web/Backend/Services/ITestService.cs
Normal file
6
web/Backend/Services/ITestService.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
using Backend.Services;
|
||||||
|
|
||||||
|
public interface ITestService
|
||||||
|
{
|
||||||
|
void Test();
|
||||||
|
}
|
||||||
14
web/Backend/Services/TestService.cs
Normal file
14
web/Backend/Services/TestService.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace Backend.Services;
|
||||||
|
|
||||||
|
public class TestService : ITestService
|
||||||
|
{
|
||||||
|
public TestService()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Test()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user