aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Controllers
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-08-05 18:58:56 +0800
committer杨宇千 <crupest@outlook.com>2019-08-05 18:58:56 +0800
commitdc1ab11cea249f4ca967f86b115147a63f7c93a5 (patch)
treeb5f26eabcfa547e76dd7e70ffe0763f3fadf0ad5 /Timeline/Controllers
parent5f5458518df0475fa36af754cae52eb31eb92fa3 (diff)
downloadtimeline-dc1ab11cea249f4ca967f86b115147a63f7c93a5.tar.gz
timeline-dc1ab11cea249f4ca967f86b115147a63f7c93a5.tar.bz2
timeline-dc1ab11cea249f4ca967f86b115147a63f7c93a5.zip
3 things.
1. Exchange Models and Entities namespace. 2. Fix the bug that input with missing field leads to 500. 3. Write unit tests.
Diffstat (limited to 'Timeline/Controllers')
-rw-r--r--Timeline/Controllers/TokenController.cs18
-rw-r--r--Timeline/Controllers/UserController.cs5
-rw-r--r--Timeline/Controllers/UserTestController.cs1
3 files changed, 7 insertions, 17 deletions
diff --git a/Timeline/Controllers/TokenController.cs b/Timeline/Controllers/TokenController.cs
index 549e227b..57407558 100644
--- a/Timeline/Controllers/TokenController.cs
+++ b/Timeline/Controllers/TokenController.cs
@@ -5,13 +5,14 @@ using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
-using Timeline.Entities.Http;
+using Timeline.Models.Http;
using Timeline.Services;
using static Timeline.Helpers.MyLogHelper;
namespace Timeline.Controllers
{
[Route("token")]
+ [ApiController]
public class TokenController : Controller
{
private static class LoggingEventIds
@@ -60,22 +61,9 @@ namespace Timeline.Controllers
Pair("Expire Offset (in days)", request.ExpireOffset)));
}
- TimeSpan? expireOffset = null;
- if (request.ExpireOffset != null)
- {
- if (request.ExpireOffset.Value <= 0.0)
- {
- const string message = "Expire time is not bigger than 0.";
- var code = ErrorCodes.Create_BadExpireOffset;
- LogFailure(message, code);
- return BadRequest(new CommonResponse(code, message));
- }
- expireOffset = TimeSpan.FromDays(request.ExpireOffset.Value);
- }
-
try
{
- var expiredTime = expireOffset == null ? null : (DateTime?)(_clock.GetCurrentTime() + expireOffset.Value);
+ var expiredTime = request.ExpireOffset == null ? null : (DateTime?)(_clock.GetCurrentTime().AddDays(request.ExpireOffset.Value));
var result = await _userService.CreateToken(request.Username, request.Password, expiredTime);
_logger.LogInformation(LoggingEventIds.CreateSucceeded, FormatLogMessage("Attemp to login succeeded.",
Pair("Username", request.Username),
diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs
index 2099690c..042a8107 100644
--- a/Timeline/Controllers/UserController.cs
+++ b/Timeline/Controllers/UserController.cs
@@ -4,13 +4,14 @@ using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Timeline.Authenticate;
-using Timeline.Entities;
-using Timeline.Entities.Http;
+using Timeline.Models;
+using Timeline.Models.Http;
using Timeline.Services;
using static Timeline.Helpers.MyLogHelper;
namespace Timeline.Controllers
{
+ [ApiController]
public class UserController : Controller
{
private static class ErrorCodes
diff --git a/Timeline/Controllers/UserTestController.cs b/Timeline/Controllers/UserTestController.cs
index 21686b81..a81f42a8 100644
--- a/Timeline/Controllers/UserTestController.cs
+++ b/Timeline/Controllers/UserTestController.cs
@@ -5,6 +5,7 @@ using Timeline.Authenticate;
namespace Timeline.Controllers
{
[Route("Test/User")]
+ [ApiController]
public class UserTestController : Controller
{
[HttpGet("[action]")]