aboutsummaryrefslogtreecommitdiff
path: root/BackEnd
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-11 17:15:05 +0800
committercrupest <crupest@outlook.com>2022-04-11 17:15:05 +0800
commit0483ac417aac15a1d6192f959b8995f109a18bd5 (patch)
treeeea779ab6b4478d376e0cd97c8f7c324a8215a32 /BackEnd
parent94262e0ab8913dc0059073341af4caa14adcd399 (diff)
downloadtimeline-0483ac417aac15a1d6192f959b8995f109a18bd5.tar.gz
timeline-0483ac417aac15a1d6192f959b8995f109a18bd5.tar.bz2
timeline-0483ac417aac15a1d6192f959b8995f109a18bd5.zip
...
Diffstat (limited to 'BackEnd')
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs59
-rw-r--r--BackEnd/Timeline/Controllers/TimelineBookmark1Controller.cs17
2 files changed, 69 insertions, 7 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs
index fcf69364..bb1d0ac7 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests2/TimelineBookmarkTest.cs
@@ -27,10 +27,10 @@ namespace Timeline.Tests.IntegratedTests2
}
[Fact]
- public async Task CreateAndGet()
+ public async Task CreateGetList()
{
using var client = CreateClientAsUser();
- var a = await client.TestJsonSendAsync<TimelineBookmark>(HttpMethod.Post, "users/user/bookmarks", new HttpTimelineBookmarkCreateRequest
+ var a = await client.TestJsonSendAsync<TimelineBookmark>(HttpMethod.Post, "v2/users/user/bookmarks", new HttpTimelineBookmarkCreateRequest
{
TimelineOwner = "user",
TimelineName = "hello"
@@ -40,10 +40,63 @@ namespace Timeline.Tests.IntegratedTests2
a.TimelineName.Should().Be("hello");
a.Position.Should().Be(1);
- var b = await client.TestJsonSendAsync<TimelineBookmark>(HttpMethod.Get, "users/user/bookmarks/1");
+ var b = await client.TestJsonSendAsync<TimelineBookmark>(HttpMethod.Get, "v2/users/user/bookmarks/1");
b.TimelineName.Should().Be("hello");
b.TimelineOwner.Should().Be("user");
b.Position.Should().Be(1);
+
+ var c = await client.TestJsonSendAsync<Page<TimelineBookmark>>(HttpMethod.Get, "v2/users/user/bookmarks");
+ c.TotalCount.Should().Be(1);
+ c.Items.Should().ContainSingle();
+ c.Items[0].TimelineOwner.Should().Be("user");
+ c.Items[0].TimelineName.Should().Be("hello");
+ c.Items[0].Position.Should().Be(1);
+ }
+
+ [Fact]
+ public async Task CreateUserNotExist()
+ {
+ using var client = CreateClientAsUser();
+ await client.TestJsonSendAsync(HttpMethod.Post, "v2/users/notexist/bookmarks", new HttpTimelineBookmarkCreateRequest
+ {
+ TimelineOwner = "user",
+ TimelineName = "hello"
+ }, expectedStatusCode: HttpStatusCode.NotFound);
+ }
+
+ [Fact]
+ public async Task CreateTimelineNotExist()
+ {
+ using var client = CreateClientAsUser();
+ await client.TestJsonSendAsync(HttpMethod.Post, "v2/users/user/bookmarks", new HttpTimelineBookmarkCreateRequest
+ {
+ TimelineOwner = "user",
+ TimelineName = "notexist"
+ }, expectedStatusCode: HttpStatusCode.UnprocessableEntity);
+
+ await client.TestJsonSendAsync(HttpMethod.Post, "v2/users/user/bookmarks", new HttpTimelineBookmarkCreateRequest
+ {
+ TimelineOwner = "notexist",
+ TimelineName = "notexist"
+ }, expectedStatusCode: HttpStatusCode.UnprocessableEntity);
+ }
+
+ [Fact]
+ public async Task CreateAlreadyExist()
+ {
+ using var client = CreateClientAsUser();
+
+ await client.TestJsonSendAsync<TimelineBookmark>(HttpMethod.Post, "v2/users/user/bookmarks", new HttpTimelineBookmarkCreateRequest
+ {
+ TimelineOwner = "user",
+ TimelineName = "hello"
+ }, expectedStatusCode: HttpStatusCode.Created);
+
+ await client.TestJsonSendAsync(HttpMethod.Post, "v2/users/user/bookmarks", new HttpTimelineBookmarkCreateRequest
+ {
+ TimelineOwner = "user",
+ TimelineName = "hello"
+ }, expectedStatusCode: HttpStatusCode.UnprocessableEntity);
}
}
}
diff --git a/BackEnd/Timeline/Controllers/TimelineBookmark1Controller.cs b/BackEnd/Timeline/Controllers/TimelineBookmark1Controller.cs
index 73d2078f..3990a1e6 100644
--- a/BackEnd/Timeline/Controllers/TimelineBookmark1Controller.cs
+++ b/BackEnd/Timeline/Controllers/TimelineBookmark1Controller.cs
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Timeline.Models;
using Timeline.Models.Http;
+using Timeline.Services;
using Timeline.Services.Api;
using Timeline.Services.Timeline;
using Timeline.Services.User;
@@ -11,14 +12,14 @@ using Timeline.Services.User;
namespace Timeline.Controllers
{
[ApiController]
- [Route("users/{username}/bookmarks")]
- public class TimelineBookmark1Controller : MyControllerBase
+ [Route("v2/users/{username}/bookmarks")]
+ public class TimelineBookmarkV2Controller : MyControllerBase
{
private readonly IUserService _userService;
private readonly ITimelineService _timelineService;
private readonly ITimelineBookmarkService1 _timelineBookmarkService;
- public TimelineBookmark1Controller(IUserService userService, ITimelineService timelineService, ITimelineBookmarkService1 timelineBookmarkService)
+ public TimelineBookmarkV2Controller(IUserService userService, ITimelineService timelineService, ITimelineBookmarkService1 timelineBookmarkService)
{
_userService = userService;
_timelineService = timelineService;
@@ -68,7 +69,15 @@ namespace Timeline.Controllers
{
return Forbid();
}
- var timelineId = await _timelineService.GetTimelineIdAsync(body.TimelineOwner, body.TimelineName);
+ long timelineId;
+ try
+ {
+ timelineId = await _timelineService.GetTimelineIdAsync(body.TimelineOwner, body.TimelineName);
+ }
+ catch (EntityNotExistException)
+ {
+ return UnprocessableEntity();
+ }
var bookmark = await _timelineBookmarkService.AddBookmarkAsync(userId, timelineId, body.Position);
return CreatedAtAction("Get", new { username, index = bookmark.Position }, bookmark);
}