half the crud development done

This commit is contained in:
2026-02-05 18:32:37 +01:00
parent c4c04a7231
commit 20e3e022d6
2 changed files with 8 additions and 1 deletions

View File

@ -13,5 +13,12 @@ namespace VideoGameCharacterApi.Controllers
[HttpGet]
public async Task<ActionResult<List<Character>>> GetCharacters()
=> Ok(await service.GetCharactersAsync());
[HttpGet("{id}")]
public async Task<ActionResult<Character>> GetCharacter(int id)
{
var character = await service.GetCharacterByIdAsync(id);
return character is null ? NotFound("Character with given id was not found") : Ok(character);
}
}
}

View File

@ -9,7 +9,7 @@ namespace VideoGameCharacterApi.Services
new Character { Id = 1, Name = "Mario", Game = "Super Mario Bros.", Role = "hero" },
new Character { Id = 2, Name = "Link", Game = "The Legend of Zelda", Role = "hero" },
new Character { Id = 3, Name = "Bowser", Game = "Super Mario Bros.", Role = "villain" },
new Character { Id = 3, Name = "Zelda", Game = "The Legend of Zelda", Role = "princess" },
new Character { Id = 4, Name = "Zelda", Game = "The Legend of Zelda", Role = "princess" },
};