aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Controllers
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-11-12 20:09:41 +0800
committer杨宇千 <crupest@outlook.com>2019-11-12 20:09:41 +0800
commit299481eecc8c1b7bc40770d58c85ff1fddeddb96 (patch)
tree9ed402bdfdf633a5d49116e7ce03abb36454856a /Timeline/Controllers
parentcc59e67f948d206a8bc466ed116d1bb870d3fb7b (diff)
downloadtimeline-299481eecc8c1b7bc40770d58c85ff1fddeddb96.tar.gz
timeline-299481eecc8c1b7bc40770d58c85ff1fddeddb96.tar.bz2
timeline-299481eecc8c1b7bc40770d58c85ff1fddeddb96.zip
Complete personal timeline controller unit tests.
Diffstat (limited to 'Timeline/Controllers')
-rw-r--r--Timeline/Controllers/PersonalTimelineController.cs25
1 files changed, 18 insertions, 7 deletions
diff --git a/Timeline/Controllers/PersonalTimelineController.cs b/Timeline/Controllers/PersonalTimelineController.cs
index f41e354b..f0f4e4c2 100644
--- a/Timeline/Controllers/PersonalTimelineController.cs
+++ b/Timeline/Controllers/PersonalTimelineController.cs
@@ -21,9 +21,11 @@ namespace Timeline
{
public static class Timeline // ccc = 004
{
- public const int PostsGetForbid = 10040101;
- public const int PostsCreateForbid = 10040102;
- public const int MemberAddNotExist = 10040201;
+ public const int PostListGetForbid = 10040101;
+ public const int PostOperationCreateForbid = 10040102;
+ public const int PostOperationDeleteForbid = 10040103;
+ public const int PostOperationDeleteNotExist = 10040201;
+ public const int MemberAddNotExist = 10040301;
}
}
}
@@ -79,7 +81,7 @@ namespace Timeline.Controllers
if (!IsAdmin() && !await _service.HasReadPermission(username, GetAuthUsername()))
{
return StatusCode(StatusCodes.Status403Forbidden,
- new CommonResponse(ErrorCodes.Http.Timeline.PostsGetForbid, MessagePostsGetForbid));
+ new CommonResponse(ErrorCodes.Http.Timeline.PostListGetForbid, MessagePostListGetForbid));
}
return await _service.GetPosts(username);
@@ -93,7 +95,7 @@ namespace Timeline.Controllers
if (!IsAdmin() && !await _service.IsMemberOf(username, GetAuthUsername()!))
{
return StatusCode(StatusCodes.Status403Forbidden,
- new CommonResponse(ErrorCodes.Http.Timeline.PostsCreateForbid, MessagePostsCreateForbid));
+ new CommonResponse(ErrorCodes.Http.Timeline.PostOperationCreateForbid, MessagePostOperationCreateForbid));
}
var res = await _service.CreatePost(username, User.Identity.Name!, body.Content, body.Time);
@@ -109,9 +111,18 @@ namespace Timeline.Controllers
if (!IsAdmin() && !await _service.HasPostModifyPermission(username, postId, GetAuthUsername()!))
{
return StatusCode(StatusCodes.Status403Forbidden,
- new CommonResponse(ErrorCodes.Http.Timeline.PostsCreateForbid, MessagePostsCreateForbid));
+ new CommonResponse(ErrorCodes.Http.Timeline.PostOperationDeleteForbid, MessagePostOperationCreateForbid));
+ }
+ try
+ {
+ await _service.DeletePost(username, postId);
+ }
+ catch (TimelinePostNotExistException)
+ {
+ return BadRequest(new CommonResponse(
+ ErrorCodes.Http.Timeline.PostOperationDeleteNotExist,
+ MessagePostOperationDeleteNotExist));
}
- await _service.DeletePost(username, postId);
return Ok();
}