Created
June 8, 2021 19:29
-
-
Save Chriz76/796ae650b31a067b6a1f34f7b36ee943 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Mvc; | |
using PostService.Data; | |
using PostService.Entities; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
namespace PostService.Controllers | |
{ | |
[Route("api/[controller]")] | |
[ApiController] | |
public class PostsController : ControllerBase | |
{ | |
private readonly DataAccess _dataAccess; | |
public PostsController(DataAccess dataAccess) | |
{ | |
_dataAccess = dataAccess; | |
} | |
[HttpGet] | |
public async Task<ActionResult<IEnumerable<Post>>> GetLatestPosts(string category, int count) | |
{ | |
return await _dataAccess.ReadLatestPosts(category, count); | |
} | |
[HttpPost] | |
public async Task<ActionResult<Post>> PostPost(Post post) | |
{ | |
await _dataAccess.CreatePost(post); | |
return NoContent(); | |
} | |
[HttpGet("InitDatabase")] | |
public void InitDatabase([FromQuery] int countUsers, [FromQuery] int countCategories) | |
{ | |
_dataAccess.InitDatabase(countUsers, countCategories); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment