Copy blog code to new API micro service repo
This commit is contained in:
commit
b23e96493c
24 changed files with 763 additions and 0 deletions
53
src/Robware.Api.Blog/Controllers/BlogController.cs
Normal file
53
src/Robware.Api.Blog/Controllers/BlogController.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Robware.Blog;
|
||||
|
||||
namespace Robware.Api.Blog.Controllers {
|
||||
[ApiController]
|
||||
public class BlogController : ControllerBase {
|
||||
private readonly ILogger<BlogController> _logger;
|
||||
private readonly IBlogRepository _blogRepository;
|
||||
|
||||
public BlogController(ILogger<BlogController> logger, IBlogRepository blogRepository) {
|
||||
_logger = logger;
|
||||
_blogRepository = blogRepository;
|
||||
}
|
||||
|
||||
[HttpGet(nameof(Get) + "/{url}")]
|
||||
public async Task<BlogPost> Get(string url) {
|
||||
_logger.Log(LogLevel.Information, $"{nameof(Get)}: {nameof(url)}={url}");
|
||||
|
||||
if (int.TryParse(url, out int id)) {
|
||||
return await _blogRepository.GetPostByIdAsync(id);
|
||||
}
|
||||
|
||||
return await _blogRepository.GetPostByUrlAsync(url);
|
||||
}
|
||||
|
||||
//[HttpGet]
|
||||
//Task<BlogPost> GetPostByUrl();
|
||||
|
||||
//[HttpGet]
|
||||
//Task<IEnumerable<BlogPost>> GetLatestPosts(int limit, int offset = 0);
|
||||
|
||||
//[HttpGet]
|
||||
//Task<BlogPost> GetLatestPost();
|
||||
|
||||
//[HttpGet]
|
||||
//Task<int> GetCount();
|
||||
|
||||
//[HttpGet]
|
||||
//Task<BlogPost> GetPostById(int id);
|
||||
|
||||
//[HttpPost]
|
||||
//Task<BlogPost> SavePost(BlogPost post);
|
||||
|
||||
//[HttpGet]
|
||||
//Task<IEnumerable<BlogPost>> GetAllPosts();
|
||||
|
||||
//[HttpGet]
|
||||
//Task DeletePost(int id);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue