website/Website/Data/BlogApi.cs

22 lines
1.1 KiB
C#

using System.Threading.Tasks;
using Website.Models;
using System.Collections.Generic;
using System.Net.Http;
namespace Website.Data
{
public class BlogApi : ApiClient, IBlogApi {
public BlogApi(HttpClient client) : base(client) {
}
public async Task<BlogPost> GetPostByUrlAsync(string url) => await Get<BlogPost>("get/" + url);
public async Task<IEnumerable<BlogPost>> GetLatestPostsAsync(int count = 0, int offset = 0) => await Get<IEnumerable<BlogPost>>("getlatestposts", new{count, offset});
public async Task<BlogPost> GetLatestPostAsync() => await Get<BlogPost>("getlatestpost");
public async Task<int> GetCountAsync() => await Get<int>("getcount");
public async Task<BlogPost> GetPostByIdAsync(int id) => await Get<BlogPost>("get/" + id);
public async Task<BlogPost> SavePost(BlogPostSubmission post) => await Post<BlogPost>("savepost", post);
public async Task<IEnumerable<BlogPost>> GetAllPostsAsync() => await Get<IEnumerable<BlogPost>>("getallposts");
public async Task DeletePostAsync(int id) => await Post<object>("deletepost", id);
public async Task PublishPostAsync(int id) => await Post<object>("publishpost", id);
}
}