Repository navigation
Expand file tree
/
Copy pathPostController.cs
More file actions
80 lines (69 loc) · 1.94 KB
/
Copy pathPostController.cs
File metadata and controls
80 lines (69 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Blogifier.Core.Providers;
using Blogifier.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Blogifier.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PostController : ControllerBase
{
private readonly IPostProvider _postProvider;
public PostController(IPostProvider postProvider)
{
_postProvider = postProvider;
}
[HttpGet("list/{filter}/{postType}")]
public async Task<ActionResult<List<Post>>> GetPosts(PublishedStatus filter, PostType postType)
{
return await _postProvider.GetPosts(filter, postType);
}
[HttpGet("list/search/{term}")]
public async Task<ActionResult<List<Post>>> SearchPosts(string term)
{
return await _postProvider.SearchPosts(term);
}
[HttpGet("byslug/{slug}")]
public async Task<ActionResult<Post>> GetPostBySlug(string slug)
{
return await _postProvider.GetPostBySlug(slug);
}
[HttpGet("getslug/{title}")]
public async Task<ActionResult<string>> GetSlug(string title)
{
return await _postProvider.GetSlugFromTitle(title);
}
[Authorize]
[HttpPost("add")]
public async Task<ActionResult<bool>> AddPost(Post post)
{
return await _postProvider.Add(post);
}
[Authorize]
[HttpPut("update")]
public async Task<ActionResult<bool>> UpdatePost(Post post)
{
return await _postProvider.Update(post);
}
[Authorize]
[HttpPut("publish/{id:int}")]
public async Task<ActionResult<bool>> PublishPost(int id, [FromBody] bool publish)
{
return await _postProvider.Publish(id, publish);
}
[Authorize]
[HttpPut("featured/{id:int}")]
public async Task<ActionResult<bool>> FeaturedPost(int id, [FromBody] bool featured)
{
return await _postProvider.Featured(id, featured);
}
[Authorize]
[HttpDelete("{id:int}")]
public async Task<ActionResult<bool>> RemovePost(int id)
{
return await _postProvider.Remove(id);
}
}
}