Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
sventhiel committed Aug 10, 2023
1 parent ec9bdfe commit 85263bb
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 280 deletions.
2 changes: 1 addition & 1 deletion Authentication/BasicAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace Manchu.Authentication
{
public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
private ConnectionString _connectionString;
private List<Admin> _admins;
private ConnectionString _connectionString;

public BasicAuthenticationHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
Expand Down
6 changes: 3 additions & 3 deletions Configurations/JwtConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{
public class JwtConfiguration
{
public string? IssuerSigningKey { get; set; }
public bool RequireExpirationTime { get; set; }
public bool ValidateAudience { get; set; }
public bool ValidateIssuer { get; set; }
public bool ValidateLifetime { get; set; }
public string? ValidAudience { get; set; }
public string? ValidIssuer { get; set; }
public string? IssuerSigningKey { get; set; }
public bool RequireExpirationTime { get; set; }
public bool ValidateLifetime { get; set; }
public int ValidLifetime { get; set; }
}
}
10 changes: 5 additions & 5 deletions Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public AccountController(IConfiguration configuration)
_admins = configuration.GetSection("Admins").Get<List<Admin>>();
}

public IActionResult AccessDenied()
{
return View();
}

// GET: /<controller>/
public IActionResult Index()
{
Expand Down Expand Up @@ -57,10 +62,5 @@ public async Task<IActionResult> Logout()

return RedirectToAction("Index");
}

public IActionResult AccessDenied()
{
return View();
}
}
}
74 changes: 67 additions & 7 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,99 @@ namespace Manchu.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly ConnectionString _connectionString;
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger, ConnectionString connectionString)
{
_logger = logger;
_connectionString = connectionString;
}

[HttpPost]
public Guid CreateVisit(Guid code)
{
var patientService = new PatientService(_connectionString);
var visitService = new VisitService(_connectionString);

if (patientService.FindById(code) != null)
return visitService.Create(code);

return Guid.Empty;
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}

public IActionResult Index(Guid code)
{
var patientServive = new PatientService(_connectionString);

if (patientServive.FindByCode(code) == null)
if (patientServive.FindById(code) == null)
return RedirectToAction("Info");

return View(model: code);
}

public IActionResult Privacy()
public IActionResult Info()
{
return View();
}

public IActionResult Info()
[HttpPost]
public bool PauseVisit(Guid id)
{
var visitService = new VisitService(_connectionString);

var visit = visitService.FindById(id);

if (visit != null)
{
visit.Breaks++;
return visitService.Update(visit);
}

return false;
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
[HttpPost]
public bool StopVisit(Guid id)
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
var visitService = new VisitService(_connectionString);

var visit = visitService.FindById(id);

if (visit != null)
{
visit.End = DateTimeOffset.UtcNow;
return visitService.Update(visit);
}

return false;
}

[HttpPost]
public bool UpdateVisit(Guid id, int position)
{
var visitService = new VisitService(_connectionString);

var visit = visitService.FindById(id);

if (visit != null)
{
visit.Position = position;
return visitService.Update(visit);
}

return false;
}
}
}
17 changes: 11 additions & 6 deletions Controllers/ImageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using QRCoder;
using System;
using System.Drawing;

namespace Manchu.Controllers
Expand Down Expand Up @@ -34,7 +35,7 @@ public IActionResult Create(bool numberAsWatermark)
}

[HttpPost("qrcodes/{id}")]
public IActionResult Create(int id, bool numberAsWatermark)
public IActionResult Create(Guid id, bool numberAsWatermark)
{
var patientService = new PatientService(_connectionString);

Expand All @@ -58,18 +59,22 @@ public IActionResult Create(int id, bool numberAsWatermark)
{
var url = $"{Request.Scheme}://{Request.Host.Value}/Home/Index";
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode($"{url}?code={patient.Code}", QRCodeGenerator.ECCLevel.Q);
QRCodeData qrCodeData = qrGenerator.CreateQrCode($"{url}?code={patient.Id}", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);

if (numberAsWatermark)
{
img.AddImageWatermark(qrCode.GetGraphic(25, Color.Black, Color.Transparent, true), iwmOps)
.ScaleByWidth(500)
.AddTextWatermark($"{patient.Number}", twmOps)
.SaveAs($"./wwwroot/media/codes/{patient.Code}.png");

img.AddImageWatermark(qrCode.GetGraphic(25, Color.Black, Color.Transparent, true), iwmOps)
.SaveAs($"./wwwroot/media/codes/{patient.Id}.png");
}
else
{
img.AddImageWatermark(qrCode.GetGraphic(25, Color.Black, Color.Transparent, true), iwmOps)
.ScaleByWidth(500)
.SaveAs($"./wwwroot/media/codes/{patient.Code}.png");
.SaveAs($"./wwwroot/media/codes/{patient.Id}.png");
}
}

return Ok("getan!");
Expand Down
60 changes: 53 additions & 7 deletions Controllers/PatientController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Manchu.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

Expand All @@ -18,6 +20,15 @@ public PatientController(ConnectionString connectionString)
_connectionString = connectionString;
}

[HttpDelete("patients/{id}")]
public IActionResult DeleteById(Guid id)
{
var patientService = new PatientService(_connectionString);
var result = patientService.Delete(id);

return Ok($"The patient with id={id} has been deleted successfully.");
}

[HttpGet("patients")]
public IActionResult Get()
{
Expand All @@ -28,29 +39,47 @@ public IActionResult Get()
}

[HttpGet("patients/{id}")]
public IActionResult GetById(int id)
public IActionResult GetById(Guid id)
{
var patientService = new PatientService(_connectionString);
var patient = patientService.FindById(id);

return Ok(ReadPatientModel.Convert(patient));
}

[HttpPost("patients")]
public IActionResult Post(CreatePatientModel model)
[HttpPost("patients/bulk/{startNumber}/{amount}")]
public IActionResult Post(int startNumber, int amount)
{
var patientService = new PatientService(_connectionString);

List<int> created = new List<int>();

for (int i = startNumber; i < startNumber + amount; i++)
{
var id = patientService.Create(null, i);

if (id.HasValue)
created.Add(id.Value);
}

return Ok($"The patient(s) with numbers(s) ({string.Join(",", created)}) has/have been created successfully.");
}

[HttpPost("patients/{id}")]
public IActionResult PostWithModel(Guid id, int? number)
{
var patientService = new PatientService(_connectionString);

var id = patientService.Create(model.Code, model.Number);
var result = patientService.Create(id, number);

if (id == null)
if (result == null)
return BadRequest("Oops, there was an issue.");

return Ok($"The patient with id={id} has been created successfully.");
}

[HttpPut("patients/{id}/number")]
public IActionResult Put(int id, int number)
[HttpPut("patients/{id}/{number}")]
public IActionResult PutNumberById(Guid id, int number)
{
var patientService = new PatientService(_connectionString);

Expand All @@ -64,5 +93,22 @@ public IActionResult Put(int id, int number)

return Ok($"The patient with id={id} has been updated successfully.");
}

[HttpPut("patients/number")]
public IActionResult PutNumbers()
{
var patientService = new PatientService(_connectionString);
var patients = patientService.FindAll().OrderBy(p => p.Id);

var count = 0;

foreach (var patient in patients)
{
patient.Number = ++count;
patientService.Update(patient);
}

return Ok($"The number of the patients have been updated successfully.");
}
}
}
Loading

0 comments on commit 85263bb

Please sign in to comment.