half the crud development done
This commit is contained in:
@ -13,5 +13,12 @@ namespace VideoGameCharacterApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<List<Character>>> GetCharacters()
|
public async Task<ActionResult<List<Character>>> GetCharacters()
|
||||||
=> Ok(await service.GetCharactersAsync());
|
=> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ namespace VideoGameCharacterApi.Services
|
|||||||
new Character { Id = 1, Name = "Mario", Game = "Super Mario Bros.", Role = "hero" },
|
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 = 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 = "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" },
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user