aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'BackEnd/Timeline/Controllers')
-rw-r--r--BackEnd/Timeline/Controllers/TimelineController.cs48
-rw-r--r--BackEnd/Timeline/Controllers/TokenController.cs16
-rw-r--r--BackEnd/Timeline/Controllers/UserController.cs18
3 files changed, 44 insertions, 38 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelineController.cs b/BackEnd/Timeline/Controllers/TimelineController.cs
index 45060b5d..27b4b7a7 100644
--- a/BackEnd/Timeline/Controllers/TimelineController.cs
+++ b/BackEnd/Timeline/Controllers/TimelineController.cs
@@ -29,17 +29,19 @@ namespace Timeline.Controllers
private readonly IUserService _userService;
private readonly ITimelineService _service;
+ private readonly ITimelinePostService _postService;
private readonly IMapper _mapper;
/// <summary>
///
/// </summary>
- public TimelineController(ILogger<TimelineController> logger, IUserService userService, ITimelineService service, IMapper mapper)
+ public TimelineController(ILogger<TimelineController> logger, IUserService userService, ITimelineService service, ITimelinePostService timelinePostService, IMapper mapper)
{
_logger = logger;
_userService = userService;
_service = service;
+ _postService = timelinePostService;
_mapper = mapper;
}
@@ -55,7 +57,7 @@ namespace Timeline.Controllers
[HttpGet("timelines")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
- public async Task<ActionResult<List<TimelineInfo>>> TimelineList([FromQuery][Username] string? relate, [FromQuery][RegularExpression("(own)|(join)")] string? relateType, [FromQuery] string? visibility)
+ public async Task<ActionResult<List<HttpTimeline>>> TimelineList([FromQuery][Username] string? relate, [FromQuery][RegularExpression("(own)|(join)")] string? relateType, [FromQuery] string? visibility)
{
List<TimelineVisibility>? visibilityFilter = null;
if (visibility != null)
@@ -107,7 +109,7 @@ namespace Timeline.Controllers
}
var timelines = await _service.GetTimelines(relationship, visibilityFilter);
- var result = _mapper.Map<List<TimelineInfo>>(timelines);
+ var result = _mapper.Map<List<HttpTimeline>>(timelines);
return result;
}
@@ -123,7 +125,7 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status304NotModified)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
- public async Task<ActionResult<TimelineInfo>> TimelineGet([FromRoute][GeneralTimelineName] string name, [FromQuery] string? checkUniqueId, [FromQuery(Name = "ifModifiedSince")] DateTime? queryIfModifiedSince, [FromHeader(Name = "If-Modified-Since")] DateTime? headerIfModifiedSince)
+ public async Task<ActionResult<HttpTimeline>> TimelineGet([FromRoute][GeneralTimelineName] string name, [FromQuery] string? checkUniqueId, [FromQuery(Name = "ifModifiedSince")] DateTime? queryIfModifiedSince, [FromHeader(Name = "If-Modified-Since")] DateTime? headerIfModifiedSince)
{
DateTime? ifModifiedSince = null;
if (queryIfModifiedSince.HasValue)
@@ -164,7 +166,7 @@ namespace Timeline.Controllers
else
{
var timeline = await _service.GetTimeline(name);
- var result = _mapper.Map<TimelineInfo>(timeline);
+ var result = _mapper.Map<HttpTimeline>(timeline);
return result;
}
}
@@ -180,16 +182,16 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
- public async Task<ActionResult<List<TimelinePostInfo>>> PostListGet([FromRoute][GeneralTimelineName] string name, [FromQuery] DateTime? modifiedSince, [FromQuery] bool? includeDeleted)
+ public async Task<ActionResult<List<HttpTimelinePost>>> PostListGet([FromRoute][GeneralTimelineName] string name, [FromQuery] DateTime? modifiedSince, [FromQuery] bool? includeDeleted)
{
if (!UserHasAllTimelineManagementPermission && !await _service.HasReadPermission(name, this.GetOptionalUserId()))
{
return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid());
}
- List<TimelinePost> posts = await _service.GetPosts(name, modifiedSince, includeDeleted ?? false);
+ List<TimelinePostInfo> posts = await _postService.GetPosts(name, modifiedSince, includeDeleted ?? false);
- var result = _mapper.Map<List<TimelinePostInfo>>(posts);
+ var result = _mapper.Map<List<HttpTimelinePost>>(posts);
return result;
}
@@ -217,9 +219,9 @@ namespace Timeline.Controllers
try
{
- return await DataCacheHelper.GenerateActionResult(this, () => _service.GetPostDataETag(name, id), async () =>
+ return await DataCacheHelper.GenerateActionResult(this, () => _postService.GetPostDataETag(name, id), async () =>
{
- var data = await _service.GetPostData(name, id);
+ var data = await _postService.GetPostData(name, id);
return data;
});
}
@@ -245,7 +247,7 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
- public async Task<ActionResult<TimelinePostInfo>> PostPost([FromRoute][GeneralTimelineName] string name, [FromBody] TimelinePostCreateRequest body)
+ public async Task<ActionResult<HttpTimelinePost>> PostPost([FromRoute][GeneralTimelineName] string name, [FromBody] HttpTimelinePostCreateRequest body)
{
var id = this.GetUserId();
if (!UserHasAllTimelineManagementPermission && !await _service.IsMemberOf(name, id))
@@ -255,7 +257,7 @@ namespace Timeline.Controllers
var content = body.Content;
- TimelinePost post;
+ TimelinePostInfo post;
if (content.Type == TimelinePostContentTypes.Text)
{
@@ -264,7 +266,7 @@ namespace Timeline.Controllers
{
return BadRequest(ErrorResponse.Common.CustomMessage_InvalidModel(Resources.Messages.TimelineController_TextContentTextRequired));
}
- post = await _service.CreateTextPost(name, id, text, body.Time);
+ post = await _postService.CreateTextPost(name, id, text, body.Time);
}
else if (content.Type == TimelinePostContentTypes.Image)
{
@@ -285,7 +287,7 @@ namespace Timeline.Controllers
try
{
- post = await _service.CreateImagePost(name, id, data, body.Time);
+ post = await _postService.CreateImagePost(name, id, data, body.Time);
}
catch (ImageException)
{
@@ -297,7 +299,7 @@ namespace Timeline.Controllers
return BadRequest(ErrorResponse.Common.CustomMessage_InvalidModel(Resources.Messages.TimelineController_ContentUnknownType));
}
- var result = _mapper.Map<TimelinePostInfo>(post);
+ var result = _mapper.Map<HttpTimelinePost>(post);
return result;
}
@@ -315,13 +317,13 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<ActionResult<CommonDeleteResponse>> PostDelete([FromRoute][GeneralTimelineName] string name, [FromRoute] long id)
{
- if (!UserHasAllTimelineManagementPermission && !await _service.HasPostModifyPermission(name, id, this.GetUserId()))
+ if (!UserHasAllTimelineManagementPermission && !await _postService.HasPostModifyPermission(name, id, this.GetUserId()))
{
return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid());
}
try
{
- await _service.DeletePost(name, id);
+ await _postService.DeletePost(name, id);
return CommonDeleteResponse.Delete();
}
catch (TimelinePostNotExistException)
@@ -342,7 +344,7 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
- public async Task<ActionResult<TimelineInfo>> TimelinePatch([FromRoute][GeneralTimelineName] string name, [FromBody] TimelinePatchRequest body)
+ public async Task<ActionResult<HttpTimeline>> TimelinePatch([FromRoute][GeneralTimelineName] string name, [FromBody] HttpTimelinePatchRequest body)
{
if (!UserHasAllTimelineManagementPermission && !(await _service.HasManagePermission(name, this.GetUserId())))
{
@@ -350,7 +352,7 @@ namespace Timeline.Controllers
}
await _service.ChangeProperty(name, _mapper.Map<TimelineChangePropertyRequest>(body));
var timeline = await _service.GetTimeline(name);
- var result = _mapper.Map<TimelineInfo>(timeline);
+ var result = _mapper.Map<HttpTimeline>(timeline);
return result;
}
@@ -421,14 +423,14 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
- public async Task<ActionResult<TimelineInfo>> TimelineCreate([FromBody] TimelineCreateRequest body)
+ public async Task<ActionResult<HttpTimeline>> TimelineCreate([FromBody] TimelineCreateRequest body)
{
var userId = this.GetUserId();
try
{
var timeline = await _service.CreateTimeline(body.Name, userId);
- var result = _mapper.Map<TimelineInfo>(timeline);
+ var result = _mapper.Map<HttpTimeline>(timeline);
return result;
}
catch (EntityAlreadyExistException e) when (e.EntityName == EntityNames.Timeline)
@@ -472,7 +474,7 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
- public async Task<ActionResult<TimelineInfo>> TimelineOpChangeName([FromBody] TimelineChangeNameRequest body)
+ public async Task<ActionResult<HttpTimeline>> TimelineOpChangeName([FromBody] HttpTimelineChangeNameRequest body)
{
if (!UserHasAllTimelineManagementPermission && !(await _service.HasManagePermission(body.OldName, this.GetUserId())))
{
@@ -482,7 +484,7 @@ namespace Timeline.Controllers
try
{
var timeline = await _service.ChangeTimelineName(body.OldName, body.NewName);
- return Ok(_mapper.Map<TimelineInfo>(timeline));
+ return Ok(_mapper.Map<HttpTimeline>(timeline));
}
catch (EntityAlreadyExistException)
{
diff --git a/BackEnd/Timeline/Controllers/TokenController.cs b/BackEnd/Timeline/Controllers/TokenController.cs
index 8f2ca600..c801b8cc 100644
--- a/BackEnd/Timeline/Controllers/TokenController.cs
+++ b/BackEnd/Timeline/Controllers/TokenController.cs
@@ -22,6 +22,7 @@ namespace Timeline.Controllers
[ProducesErrorResponseType(typeof(CommonResponse))]
public class TokenController : Controller
{
+ private readonly IUserCredentialService _userCredentialService;
private readonly IUserTokenManager _userTokenManager;
private readonly ILogger<TokenController> _logger;
private readonly IClock _clock;
@@ -29,8 +30,9 @@ namespace Timeline.Controllers
private readonly IMapper _mapper;
/// <summary></summary>
- public TokenController(IUserTokenManager userTokenManager, ILogger<TokenController> logger, IClock clock, IMapper mapper)
+ public TokenController(IUserCredentialService userCredentialService, IUserTokenManager userTokenManager, ILogger<TokenController> logger, IClock clock, IMapper mapper)
{
+ _userCredentialService = userCredentialService;
_userTokenManager = userTokenManager;
_logger = logger;
_clock = clock;
@@ -45,7 +47,7 @@ namespace Timeline.Controllers
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
- public async Task<ActionResult<CreateTokenResponse>> Create([FromBody] CreateTokenRequest request)
+ public async Task<ActionResult<HttpCreateTokenResponse>> Create([FromBody] HttpCreateTokenRequest request)
{
void LogFailure(string reason, Exception? e = null)
{
@@ -69,10 +71,10 @@ namespace Timeline.Controllers
("Username", request.Username),
("Expire At", expireTime?.ToString(CultureInfo.CurrentCulture.DateTimeFormat) ?? "default")
));
- return Ok(new CreateTokenResponse
+ return Ok(new HttpCreateTokenResponse
{
Token = result.Token,
- User = _mapper.Map<UserInfo>(result.User)
+ User = _mapper.Map<HttpUser>(result.User)
});
}
catch (UserNotExistException e)
@@ -95,7 +97,7 @@ namespace Timeline.Controllers
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
- public async Task<ActionResult<VerifyTokenResponse>> Verify([FromBody] VerifyTokenRequest request)
+ public async Task<ActionResult<HttpVerifyTokenResponse>> Verify([FromBody] HttpVerifyTokenRequest request)
{
void LogFailure(string reason, Exception? e = null, params (string, object?)[] otherProperties)
{
@@ -111,9 +113,9 @@ namespace Timeline.Controllers
var result = await _userTokenManager.VerifyToken(request.Token);
_logger.LogInformation(Log.Format(LogVerifySuccess,
("Username", result.Username), ("Token", request.Token)));
- return Ok(new VerifyTokenResponse
+ return Ok(new HttpVerifyTokenResponse
{
- User = _mapper.Map<UserInfo>(result)
+ User = _mapper.Map<HttpUser>(result)
});
}
catch (UserTokenTimeExpireException e)
diff --git a/BackEnd/Timeline/Controllers/UserController.cs b/BackEnd/Timeline/Controllers/UserController.cs
index 8edae139..3727da36 100644
--- a/BackEnd/Timeline/Controllers/UserController.cs
+++ b/BackEnd/Timeline/Controllers/UserController.cs
@@ -26,21 +26,23 @@ namespace Timeline.Controllers
{
private readonly ILogger<UserController> _logger;
private readonly IUserService _userService;
+ private readonly IUserCredentialService _userCredentialService;
private readonly IUserPermissionService _userPermissionService;
private readonly IUserDeleteService _userDeleteService;
private readonly IMapper _mapper;
/// <summary></summary>
- public UserController(ILogger<UserController> logger, IUserService userService, IUserPermissionService userPermissionService, IUserDeleteService userDeleteService, IMapper mapper)
+ public UserController(ILogger<UserController> logger, IUserService userService, IUserCredentialService userCredentialService, IUserPermissionService userPermissionService, IUserDeleteService userDeleteService, IMapper mapper)
{
_logger = logger;
_userService = userService;
+ _userCredentialService = userCredentialService;
_userPermissionService = userPermissionService;
_userDeleteService = userDeleteService;
_mapper = mapper;
}
- private UserInfo ConvertToUserInfo(User user) => _mapper.Map<UserInfo>(user);
+ private HttpUser ConvertToUserInfo(UserInfo user) => _mapper.Map<HttpUser>(user);
private bool UserHasUserManagementPermission => this.UserHasPermission(UserPermission.UserManagement);
@@ -50,7 +52,7 @@ namespace Timeline.Controllers
/// <returns>All user list.</returns>
[HttpGet("users")]
[ProducesResponseType(StatusCodes.Status200OK)]
- public async Task<ActionResult<UserInfo[]>> List()
+ public async Task<ActionResult<HttpUser[]>> List()
{
var users = await _userService.GetUsers();
var result = users.Select(u => ConvertToUserInfo(u)).ToArray();
@@ -65,7 +67,7 @@ namespace Timeline.Controllers
[HttpGet("users/{username}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
- public async Task<ActionResult<UserInfo>> Get([FromRoute][Username] string username)
+ public async Task<ActionResult<HttpUser>> Get([FromRoute][Username] string username)
{
try
{
@@ -92,7 +94,7 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
- public async Task<ActionResult<UserInfo>> Patch([FromBody] UserPatchRequest body, [FromRoute][Username] string username)
+ public async Task<ActionResult<HttpUser>> Patch([FromBody] HttpUserPatchRequest body, [FromRoute][Username] string username)
{
if (UserHasUserManagementPermission)
{
@@ -166,7 +168,7 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
- public async Task<ActionResult<UserInfo>> CreateUser([FromBody] CreateUserRequest body)
+ public async Task<ActionResult<HttpUser>> CreateUser([FromBody] HttpCreateUserRequest body)
{
try
{
@@ -186,11 +188,11 @@ namespace Timeline.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
- public async Task<ActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
+ public async Task<ActionResult> ChangePassword([FromBody] HttpChangePasswordRequest request)
{
try
{
- await _userService.ChangePassword(this.GetUserId(), request.OldPassword, request.NewPassword);
+ await _userCredentialService.ChangePassword(this.GetUserId(), request.OldPassword, request.NewPassword);
return Ok();
}
catch (BadPasswordException e)