Repository navigation
Expand file tree
/
Copy pathCategoryController.cs
More file actions
73 lines (63 loc) · 2.08 KB
/
Copy pathCategoryController.cs
File metadata and controls
73 lines (63 loc) · 2.08 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
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 CategoryController : ControllerBase
{
private readonly ICategoryProvider _categoryProvider;
public CategoryController(ICategoryProvider categoryProvider)
{
_categoryProvider = categoryProvider;
}
[HttpGet("{postId:int}")]
public async Task<ICollection<Category>> GetPostCategories(int postId)
{
return await _categoryProvider.GetPostCategories(postId);
}
[HttpGet("byId/{categoryId:int}")]
public async Task<Category> GetCategory(int categoryId)
{
return await _categoryProvider.GetCategory(categoryId);
}
[HttpGet]
public async Task<List<CategoryItem>> GetCategories()
{
return await _categoryProvider.Categories();
}
[HttpGet("{term}")]
public async Task<List<CategoryItem>> SearchCategories(string term = "*")
{
return await _categoryProvider.SearchCategories(term);
}
[Authorize]
[HttpPost("{postId:int}/{tag}")]
public async Task<ActionResult<bool>> AddPostCategory(int postId, string tag)
{
return await _categoryProvider.AddPostCategory(postId, tag);
}
[Authorize]
[HttpPut]
public async Task<ActionResult<bool>> SaveCategory(Category category)
{
return await _categoryProvider.SaveCategory(category);
}
[Authorize]
[HttpPut("{postId:int}")]
public async Task<ActionResult<bool>> SavePostCategories(int postId, List<Category> categories)
{
return await _categoryProvider.SavePostCategories(postId, categories);
}
[Authorize]
[HttpDelete("{categoryId:int}")]
public async Task<ActionResult<bool>> RemoveCategory(int categoryId)
{
return await _categoryProvider.RemoveCategory(categoryId);
}
}
}