1
|
using Core.Services.DocumentService;
|
2
|
using Microsoft.AspNetCore.Mvc;
|
3
|
using RestAPI.Utils;
|
4
|
using System.Net;
|
5
|
using Serilog;
|
6
|
using ILogger = Serilog.ILogger;
|
7
|
using Models.Documents;
|
8
|
using RestAPI.Exceptions;
|
9
|
using RestAPI.Authentication;
|
10
|
using Core.Services.TagService;
|
11
|
using Models.Tags;
|
12
|
|
13
|
namespace RestAPI.Controllers;
|
14
|
|
15
|
|
16
|
|
17
|
public class TagController : Common.CommonControllerBase
|
18
|
{
|
19
|
private readonly ITagService tagService;
|
20
|
private readonly ILogger logger;
|
21
|
|
22
|
|
23
|
public TagController(ITagService tagService, ILogger logger)
|
24
|
{
|
25
|
this.tagService = tagService;
|
26
|
this.logger = logger;
|
27
|
}
|
28
|
|
29
|
[HttpGet("/tags")]
|
30
|
[Authorize]
|
31
|
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(TagTreeResponse))]
|
32
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
33
|
public ActionResult<DocumentListResponse> GetTagTree([FromServices] ClientInfo clientInfo)
|
34
|
{
|
35
|
if (clientInfo.LoggedUser == null)
|
36
|
{
|
37
|
logger.Warning("ClientInfo has null LoggerUser in controller /tags");
|
38
|
return Problem();
|
39
|
}
|
40
|
|
41
|
return Ok(tagService.GetTagTree());
|
42
|
}
|
43
|
|
44
|
[HttpPost("/categories")]
|
45
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
46
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
47
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
48
|
public ActionResult CreateCategory([FromBody] CreateCategoryRequest request)
|
49
|
{
|
50
|
try
|
51
|
{
|
52
|
tagService.CreateCategory(request);
|
53
|
}
|
54
|
catch (InvalidOperationException e)
|
55
|
{
|
56
|
throw new BadRequestException(e.Message);
|
57
|
}
|
58
|
|
59
|
return Ok();
|
60
|
}
|
61
|
|
62
|
[HttpDelete("/category/{categoryId}")]
|
63
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
64
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
65
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
66
|
public ActionResult DeleteCategory(Guid categoryId)
|
67
|
{
|
68
|
try
|
69
|
{
|
70
|
tagService.DeleteCategory(categoryId);
|
71
|
}
|
72
|
catch (InvalidOperationException e)
|
73
|
{
|
74
|
throw new BadRequestException(e.Message);
|
75
|
}
|
76
|
|
77
|
return Ok();
|
78
|
}
|
79
|
|
80
|
[HttpPut("/category/{categoryId}")]
|
81
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
82
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
83
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
84
|
public ActionResult UpdateCategory([FromBody] ModifyCategoryRequest request, Guid categoryId)
|
85
|
{
|
86
|
try
|
87
|
{
|
88
|
tagService.UpdateCategory(request, categoryId);
|
89
|
}
|
90
|
catch (InvalidOperationException e)
|
91
|
{
|
92
|
throw new BadRequestException(e.Message);
|
93
|
}
|
94
|
|
95
|
return Ok();
|
96
|
}
|
97
|
|
98
|
[HttpPost("/tags")]
|
99
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
100
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
101
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
102
|
public ActionResult CreateTag([FromBody] CreateTagRequest request)
|
103
|
{
|
104
|
try
|
105
|
{
|
106
|
tagService.CreateTag(request);
|
107
|
}
|
108
|
catch (InvalidOperationException e)
|
109
|
{
|
110
|
throw new BadRequestException(e.Message);
|
111
|
}
|
112
|
|
113
|
return Ok();
|
114
|
}
|
115
|
|
116
|
[HttpDelete("/tag/{tagId}")]
|
117
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
118
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
119
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
120
|
public ActionResult DeleteTag(Guid tagId)
|
121
|
{
|
122
|
try
|
123
|
{
|
124
|
tagService.DeleteTag(tagId);
|
125
|
}
|
126
|
catch (InvalidOperationException e)
|
127
|
{
|
128
|
throw new BadRequestException(e.Message);
|
129
|
}
|
130
|
|
131
|
return Ok();
|
132
|
}
|
133
|
|
134
|
[HttpPut("/tag/{tagId}")]
|
135
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
136
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
137
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
138
|
public ActionResult UpdateTag([FromBody] ModifyTagRequest request, Guid tagId)
|
139
|
{
|
140
|
try
|
141
|
{
|
142
|
tagService.UpdateTag(request, tagId);
|
143
|
}
|
144
|
catch (InvalidOperationException e)
|
145
|
{
|
146
|
throw new BadRequestException(e.Message);
|
147
|
}
|
148
|
|
149
|
return Ok();
|
150
|
}
|
151
|
|
152
|
[HttpPost("/subtags")]
|
153
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
154
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
155
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
156
|
public ActionResult CreateSubTag([FromBody] CreateSubTagRequest request)
|
157
|
{
|
158
|
try
|
159
|
{
|
160
|
tagService.CreateSubTag(request);
|
161
|
}
|
162
|
catch (InvalidOperationException e)
|
163
|
{
|
164
|
throw new BadRequestException(e.Message);
|
165
|
}
|
166
|
|
167
|
return Ok();
|
168
|
}
|
169
|
|
170
|
[HttpDelete("/subtag/{subtagId}")]
|
171
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
172
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
173
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
174
|
public ActionResult DeleteSubTag(Guid subtagId)
|
175
|
{
|
176
|
try
|
177
|
{
|
178
|
tagService.DeleteSubTag(subtagId);
|
179
|
}
|
180
|
catch (InvalidOperationException e)
|
181
|
{
|
182
|
throw new BadRequestException(e.Message);
|
183
|
}
|
184
|
|
185
|
return Ok();
|
186
|
}
|
187
|
|
188
|
[HttpPut("/subtag/{subtagId}")]
|
189
|
[Authorize(Models.Enums.ERole.ADMINISTRATOR)]
|
190
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
191
|
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
192
|
public ActionResult UpdateSubTag([FromBody] ModifySubTagRequest request, Guid subtagId)
|
193
|
{
|
194
|
try
|
195
|
{
|
196
|
tagService.UpdateSubTag(request, subtagId);
|
197
|
}
|
198
|
catch (InvalidOperationException e)
|
199
|
{
|
200
|
throw new BadRequestException(e.Message);
|
201
|
}
|
202
|
|
203
|
return Ok();
|
204
|
}
|
205
|
}
|
206
|
|