Skip to content

Commit

Permalink
Fix existing endpoints, add an example API call handler
Browse files Browse the repository at this point in the history
  • Loading branch information
scogliera committed Dec 12, 2023
1 parent 111bfc2 commit 897a353
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions Controllers/TdaApiController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using TeacherDigitalAgency.Models;

namespace TeacherDigitalAgency.Controllers;

Expand All @@ -13,23 +14,48 @@ public TdaApiController(ILogger<TdaApiController> logger)
_logger = logger;
}

[HttpGet(Name = "api")]
public Dictionary<string, string> OnGet()
[HttpGet("/api")]
public ActionResult<Dictionary<string, string>> OnGet()
{
_logger.LogDebug("Base api endpoint called");
return new Dictionary<string, string>

var result = new Dictionary<string, string>
{
{ "secret", "The cake is a lie" }
};

return Ok(result);
}

[HttpPost(Name = "api")]
public Dictionary<string, string> OnPost()
[HttpPost("/api")]
public ActionResult<Dictionary<string, string>> OnPost()
{
_logger.LogDebug("Base api post endpoint called");
return new Dictionary<string, string>

var result = new Dictionary<string, string>
{
{ "secret", "The cake is a lie" }
};

return Ok(result);
}

[HttpPost("/prikladvseho/{vek:int}")]
public ActionResult<IEnumerable<string>> PrikladVseho([FromRoute] int vek, [FromBody] Lecturer lecturer)
{
var anotherLecturer = new Lecturer
{
FirstName = "Jozef",
LastName = "Novák",
TitleBefore = "Ing."
};

var informationList = new List<string>();

informationList.Add($"{lecturer.FirstName}{vek} let.");
informationList.Add($"Jeho ID je {lecturer.Uuid}");
informationList.Add($"{lecturer.FirstName} má kamaráda {anotherLecturer.FirstName} {anotherLecturer.LastName}");

return Ok(informationList);
}
}

0 comments on commit 897a353

Please sign in to comment.