From 55e3679d5467b48104ea0fbce7af3c15de029dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Tracewicz?= Date: Tue, 10 Sep 2024 09:52:50 +0200 Subject: [PATCH] Closes #60 Add Logs Remove the redirect for debuging --- backend/src/api/Controllers/TodoController.cs | 15 ++++++++++----- scripts/apply_migrations.ps1 | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/src/api/Controllers/TodoController.cs b/backend/src/api/Controllers/TodoController.cs index ee522a4..35f9bad 100644 --- a/backend/src/api/Controllers/TodoController.cs +++ b/backend/src/api/Controllers/TodoController.cs @@ -1,5 +1,4 @@ -using api.Data.DTO; -using api.Services; +using api.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -11,17 +10,23 @@ namespace api.Controllers; public class TodoController : ControllerBase { private readonly ITodoService _service; + private readonly ILogger _logger; - public TodoController(ITodoService service) => _service = service; + public TodoController(ITodoService service, ILogger logger){ + _service = service; + _logger = logger; + } [HttpGet("lists")] public IActionResult List() { - return Request.UserId() switch + var userId = Request.UserId(); + _logger.LogInformation("User: {user} requested his lists", userId); + return userId switch { null => Unauthorized(), var user => Ok(_service.GetLists(user)), }; } -} +} \ No newline at end of file diff --git a/scripts/apply_migrations.ps1 b/scripts/apply_migrations.ps1 index 201925c..05aa6c2 100755 --- a/scripts/apply_migrations.ps1 +++ b/scripts/apply_migrations.ps1 @@ -13,7 +13,7 @@ docker compose up db -d 2>&1 > $null Write-Output "Generateing migration script" Set-Location ../backend/src/api mkdir migration_scripts 2>&1 > $null -dotnet ef migrations script --idempotent -o ./migration_scripts/migration.sql 2>&1 > $null +dotnet ef migrations script --idempotent -o ./migration_scripts/migration.sql Write-Output "Applying.." $passwd = "PGPASSWORD=" + $Env:POSTGRES_PASSWORD