Revize 0ea30313
Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)
Backend/Backend/Controllers/AnnotationController.cs | ||
---|---|---|
221 | 221 |
} |
222 | 222 |
|
223 | 223 |
} |
224 |
|
|
225 |
[HttpPut("/annotation/{annotationId}/done")] |
|
226 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
|
227 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
|
228 |
public ActionResult MarkAsDone([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] MarkAnnotationDoneRequest request) |
|
229 |
{ |
|
230 |
if (clientInfo.LoggedUser == null) |
|
231 |
{ |
|
232 |
logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations"); |
|
233 |
return Problem(); |
|
234 |
} |
|
235 |
|
|
236 |
try |
|
237 |
{ |
|
238 |
annotationService.MarkAnnotationAsDone(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request.Done); |
|
239 |
return Ok(); |
|
240 |
} |
|
241 |
catch (InvalidOperationException e) |
|
242 |
{ |
|
243 |
throw new BadRequestException(e.Message); |
|
244 |
} |
|
245 |
catch (UnauthorizedAccessException) |
|
246 |
{ |
|
247 |
return Forbid(); |
|
248 |
} |
|
249 |
|
|
250 |
} |
|
224 | 251 |
} |
225 | 252 |
} |
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs | ||
---|---|---|
927 | 927 |
|
928 | 928 |
context.SaveChanges(); |
929 | 929 |
} |
930 |
|
|
931 |
public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done) |
|
932 |
{ |
|
933 |
Annotation annotation = null; |
|
934 |
try |
|
935 |
{ |
|
936 |
annotation = context.Annotations |
|
937 |
.Where(a => a.Id == annotationId) |
|
938 |
.Include(a => a.User) |
|
939 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
940 |
.First(); |
|
941 |
|
|
942 |
} |
|
943 |
catch (Exception ex) |
|
944 |
{ |
|
945 |
throw new InvalidOperationException("Could not find annotation"); |
|
946 |
} |
|
947 |
|
|
948 |
|
|
949 |
if (userRole < ERole.ADMINISTRATOR) |
|
950 |
{ |
|
951 |
if (annotation.User.Id != userId) |
|
952 |
{ |
|
953 |
throw new UnauthorizedAccessException($"User {userId} does not have assigned annotation {annotationId}"); |
|
954 |
} |
|
955 |
} |
|
956 |
|
|
957 |
annotation.State = done ? EState.DONE : EState.IN_PROGRESS; |
|
958 |
context.SaveChanges(); |
|
959 |
} |
|
930 | 960 |
} |
931 | 961 |
} |
Backend/Core/Services/AnnotationService/IAnnotationService.cs | ||
---|---|---|
17 | 17 |
public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole); |
18 | 18 |
public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request); |
19 | 19 |
public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment); |
20 |
|
|
21 |
|
|
20 |
public void MarkAnnotationAsDone(Guid annotationId, Guid userId, ERole userRole, bool done); |
|
22 | 21 |
} |
23 | 22 |
} |
Backend/Models/Annotations/MarkAnnotationDoneRequest.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace Models.Annotations |
|
8 |
{ |
|
9 |
public class MarkAnnotationDoneRequest |
|
10 |
{ |
|
11 |
public bool Done { get; set; } |
|
12 |
} |
|
13 |
} |
Také k dispozici: Unified diff
Added endpoint for marking annotations as done