aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-02-03 17:50:17 +0800
committercrupest <crupest@outlook.com>2020-02-03 17:50:17 +0800
commit4b2569368073bbd556bbe71bd51807de91f814cb (patch)
tree9f9747d30d15abf8389527039db542c961135b1f
parent10985f0a26010988d26777d5a6d985b4fbc0a776 (diff)
downloadtimeline-4b2569368073bbd556bbe71bd51807de91f814cb.tar.gz
timeline-4b2569368073bbd556bbe71bd51807de91f814cb.tar.bz2
timeline-4b2569368073bbd556bbe71bd51807de91f814cb.zip
Add TimelineController.
-rw-r--r--Timeline.ErrorCodes/ErrorCodes.cs6
-rw-r--r--Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs2
-rw-r--r--Timeline/Controllers/PersonalTimelineController.cs2
-rw-r--r--Timeline/Controllers/TimelineController.cs19
-rw-r--r--Timeline/Filters/Timeline.cs2
-rw-r--r--Timeline/Models/Http/ErrorResponse.cs26
-rw-r--r--Timeline/Models/Http/TimelineController.cs8
-rw-r--r--Timeline/Resources/Messages.Designer.cs27
-rw-r--r--Timeline/Resources/Messages.resx15
9 files changed, 70 insertions, 37 deletions
diff --git a/Timeline.ErrorCodes/ErrorCodes.cs b/Timeline.ErrorCodes/ErrorCodes.cs
index ea74cf0e..e07fbd94 100644
--- a/Timeline.ErrorCodes/ErrorCodes.cs
+++ b/Timeline.ErrorCodes/ErrorCodes.cs
@@ -56,9 +56,11 @@
public const int BadFormat_BadSize = 1_103_00_03;
}
- public static class TimelineController
+ public static class TimelineCommon
{
- public const int MemberPut_NotExist = 1_104_01_01;
+ public const int NameConflict = 1_104_01_01;
+ public const int NotExist = 1_104_02_01;
+ public const int MemberPut_NotExist = 1_104_03_01;
}
}
}
diff --git a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
index cc170a98..7d0a68e8 100644
--- a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
+++ b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs
@@ -165,7 +165,7 @@ namespace Timeline.Tests.IntegratedTests
{
var res = await client.PutAsync("/users/user1/timeline/members/usernotexist", null);
res.Should().HaveStatusCode(400)
- .And.HaveCommonBody(ErrorCodes.TimelineController.MemberPut_NotExist);
+ .And.HaveCommonBody(ErrorCodes.TimelineCommon.MemberPut_NotExist);
}
await AssertEmptyMembers();
{
diff --git a/Timeline/Controllers/PersonalTimelineController.cs b/Timeline/Controllers/PersonalTimelineController.cs
index 8cf098bf..b6c213d9 100644
--- a/Timeline/Controllers/PersonalTimelineController.cs
+++ b/Timeline/Controllers/PersonalTimelineController.cs
@@ -104,7 +104,7 @@ namespace Timeline.Controllers
}
catch (UserNotExistException)
{
- return BadRequest(ErrorResponse.TimelineController.MemberPut_NotExist());
+ return BadRequest(ErrorResponse.TimelineCommon.MemberPut_NotExist());
}
}
diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs
index be271de7..d46189b8 100644
--- a/Timeline/Controllers/TimelineController.cs
+++ b/Timeline/Controllers/TimelineController.cs
@@ -102,7 +102,7 @@ namespace Timeline.Controllers
}
catch (UserNotExistException)
{
- return BadRequest(ErrorResponse.TimelineController.MemberPut_NotExist());
+ return BadRequest(ErrorResponse.TimelineCommon.MemberPut_NotExist());
}
}
@@ -126,6 +126,21 @@ namespace Timeline.Controllers
}
}
- // TODO: Create API .
+ [HttpPost("timelines")]
+ [Authorize]
+ public async Task<ActionResult<TimelineInfo>> TimelineCreate([FromRoute] TimelineCreateRequest body)
+ {
+ var userId = this.GetUserId();
+
+ try
+ {
+ var timelineInfo = await _service.CreateTimeline(body.Name, userId);
+ return Ok(timelineInfo);
+ }
+ catch (ConflictException)
+ {
+ return BadRequest(ErrorResponse.TimelineCommon.NameConflict());
+ }
+ }
}
}
diff --git a/Timeline/Filters/Timeline.cs b/Timeline/Filters/Timeline.cs
index ed78e645..e133c9d6 100644
--- a/Timeline/Filters/Timeline.cs
+++ b/Timeline/Filters/Timeline.cs
@@ -17,7 +17,7 @@ namespace Timeline.Filters
}
else
{
- throw new System.NotImplementedException();
+ context.Result = new NotFoundObjectResult(ErrorResponse.TimelineCommon.NotExist());
}
}
}
diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs
index a20b5386..0d23fe59 100644
--- a/Timeline/Models/Http/ErrorResponse.cs
+++ b/Timeline/Models/Http/ErrorResponse.cs
@@ -242,17 +242,37 @@ namespace Timeline.Models.Http
}
- public static class TimelineController
+ public static class TimelineCommon
{
+ public static CommonResponse NameConflict(params object?[] formatArgs)
+ {
+ return new CommonResponse(ErrorCodes.TimelineCommon.NameConflict, string.Format(TimelineCommon_NameConflict, formatArgs));
+ }
+
+ public static CommonResponse CustomMessage_NameConflict(string message, params object?[] formatArgs)
+ {
+ return new CommonResponse(ErrorCodes.TimelineCommon.NameConflict, string.Format(message, formatArgs));
+ }
+
+ public static CommonResponse NotExist(params object?[] formatArgs)
+ {
+ return new CommonResponse(ErrorCodes.TimelineCommon.NotExist, string.Format(TimelineCommon_NotExist, formatArgs));
+ }
+
+ public static CommonResponse CustomMessage_NotExist(string message, params object?[] formatArgs)
+ {
+ return new CommonResponse(ErrorCodes.TimelineCommon.NotExist, string.Format(message, formatArgs));
+ }
+
public static CommonResponse MemberPut_NotExist(params object?[] formatArgs)
{
- return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(TimelineController_MemberPut_NotExist, formatArgs));
+ return new CommonResponse(ErrorCodes.TimelineCommon.MemberPut_NotExist, string.Format(TimelineCommon_MemberPut_NotExist, formatArgs));
}
public static CommonResponse CustomMessage_MemberPut_NotExist(string message, params object?[] formatArgs)
{
- return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(message, formatArgs));
+ return new CommonResponse(ErrorCodes.TimelineCommon.MemberPut_NotExist, string.Format(message, formatArgs));
}
}
diff --git a/Timeline/Models/Http/TimelineController.cs b/Timeline/Models/Http/TimelineController.cs
index f9a4d3e5..6d461bb9 100644
--- a/Timeline/Models/Http/TimelineController.cs
+++ b/Timeline/Models/Http/TimelineController.cs
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
+using Timeline.Models.Validation;
namespace Timeline.Models.Http
{
@@ -11,6 +12,13 @@ namespace Timeline.Models.Http
public DateTime? Time { get; set; }
}
+ public class TimelineCreateRequest
+ {
+ [Required]
+ [TimelineName]
+ public string Name { get; set; } = default!;
+ }
+
public class TimelinePatchRequest
{
public string? Description { get; set; }
diff --git a/Timeline/Resources/Messages.Designer.cs b/Timeline/Resources/Messages.Designer.cs
index 332c8817..eeb44f10 100644
--- a/Timeline/Resources/Messages.Designer.cs
+++ b/Timeline/Resources/Messages.Designer.cs
@@ -151,38 +151,29 @@ namespace Timeline.Resources {
}
/// <summary>
- /// Looks up a localized string similar to The {0}-st username to do operation {1} on is of bad format..
- /// </summary>
- internal static string TimelineController_ChangeMember_UsernameBadFormat {
- get {
- return ResourceManager.GetString("TimelineController_ChangeMember_UsernameBadFormat", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The {0}-st user to do operation {1} on does not exist..
+ /// Looks up a localized string similar to The user to set as member does not exist..
/// </summary>
- internal static string TimelineController_ChangeMember_UserNotExist {
+ internal static string TimelineCommon_MemberPut_NotExist {
get {
- return ResourceManager.GetString("TimelineController_ChangeMember_UserNotExist", resourceCulture);
+ return ResourceManager.GetString("TimelineCommon_MemberPut_NotExist", resourceCulture);
}
}
/// <summary>
- /// Looks up a localized string similar to The user to set as member does not exist..
+ /// Looks up a localized string similar to A timeline with given name already exists..
/// </summary>
- internal static string TimelineController_MemberPut_NotExist {
+ internal static string TimelineCommon_NameConflict {
get {
- return ResourceManager.GetString("TimelineController_MemberPut_NotExist", resourceCulture);
+ return ResourceManager.GetString("TimelineCommon_NameConflict", resourceCulture);
}
}
/// <summary>
- /// Looks up a localized string similar to The post to delete does not exist..
+ /// Looks up a localized string similar to The timeline with given name does not exist..
/// </summary>
- internal static string TimelineController_PostOperationDelete_NotExist {
+ internal static string TimelineCommon_NotExist {
get {
- return ResourceManager.GetString("TimelineController_PostOperationDelete_NotExist", resourceCulture);
+ return ResourceManager.GetString("TimelineCommon_NotExist", resourceCulture);
}
}
diff --git a/Timeline/Resources/Messages.resx b/Timeline/Resources/Messages.resx
index cb6c3891..66a84d5f 100644
--- a/Timeline/Resources/Messages.resx
+++ b/Timeline/Resources/Messages.resx
@@ -147,17 +147,14 @@
<data name="Common_InvalidModel" xml:space="preserve">
<value>Model is of bad format.</value>
</data>
- <data name="TimelineController_ChangeMember_UsernameBadFormat" xml:space="preserve">
- <value>The {0}-st username to do operation {1} on is of bad format.</value>
- </data>
- <data name="TimelineController_ChangeMember_UserNotExist" xml:space="preserve">
- <value>The {0}-st user to do operation {1} on does not exist.</value>
- </data>
- <data name="TimelineController_MemberPut_NotExist" xml:space="preserve">
+ <data name="TimelineCommon_MemberPut_NotExist" xml:space="preserve">
<value>The user to set as member does not exist.</value>
</data>
- <data name="TimelineController_PostOperationDelete_NotExist" xml:space="preserve">
- <value>The post to delete does not exist.</value>
+ <data name="TimelineCommon_NameConflict" xml:space="preserve">
+ <value>A timeline with given name already exists.</value>
+ </data>
+ <data name="TimelineCommon_NotExist" xml:space="preserve">
+ <value>The timeline with given name does not exist.</value>
</data>
<data name="TokenController_Create_BadCredential" xml:space="preserve">
<value>Username or password is invalid.</value>