aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline
diff options
context:
space:
mode:
Diffstat (limited to 'BackEnd/Timeline')
-rw-r--r--BackEnd/Timeline/Controllers/TimelineController.cs32
-rw-r--r--BackEnd/Timeline/Controllers/TokenController.cs12
-rw-r--r--BackEnd/Timeline/Controllers/UserController.cs12
-rw-r--r--BackEnd/Timeline/Models/Http/Timeline.cs45
-rw-r--r--BackEnd/Timeline/Models/Http/TimelineController.cs21
-rw-r--r--BackEnd/Timeline/Models/Http/TokenController.cs20
-rw-r--r--BackEnd/Timeline/Models/Http/User.cs (renamed from BackEnd/Timeline/Models/Http/UserInfo.cs)26
-rw-r--r--BackEnd/Timeline/Models/Http/UserController.cs18
-rw-r--r--BackEnd/Timeline/Models/TimelineInfo.cs (renamed from BackEnd/Timeline/Models/Timeline.cs)52
-rw-r--r--BackEnd/Timeline/Models/User.cs21
-rw-r--r--BackEnd/Timeline/Models/UserInfo.cs48
-rw-r--r--BackEnd/Timeline/Services/HighlightTimelineService.cs7
-rw-r--r--BackEnd/Timeline/Services/TimelinePostService.cs24
-rw-r--r--BackEnd/Timeline/Services/TimelineService.cs54
-rw-r--r--BackEnd/Timeline/Services/UserCredentialService.cs2
-rw-r--r--BackEnd/Timeline/Services/UserService.cs45
-rw-r--r--BackEnd/Timeline/Services/UserTokenManager.cs6
17 files changed, 252 insertions, 193 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelineController.cs b/BackEnd/Timeline/Controllers/TimelineController.cs
index 0ffadc50..27b4b7a7 100644
--- a/BackEnd/Timeline/Controllers/TimelineController.cs
+++ b/BackEnd/Timeline/Controllers/TimelineController.cs
@@ -57,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)
@@ -109,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;
}
@@ -125,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)
@@ -166,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;
}
}
@@ -182,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 _postService.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;
}
@@ -247,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))
@@ -257,7 +257,7 @@ namespace Timeline.Controllers
var content = body.Content;
- TimelinePost post;
+ TimelinePostInfo post;
if (content.Type == TimelinePostContentTypes.Text)
{
@@ -299,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;
}
@@ -344,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())))
{
@@ -352,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;
}
@@ -423,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)
@@ -474,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())))
{
@@ -484,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 41ec21e6..c801b8cc 100644
--- a/BackEnd/Timeline/Controllers/TokenController.cs
+++ b/BackEnd/Timeline/Controllers/TokenController.cs
@@ -47,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)
{
@@ -71,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)
@@ -97,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)
{
@@ -113,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 626a116f..3727da36 100644
--- a/BackEnd/Timeline/Controllers/UserController.cs
+++ b/BackEnd/Timeline/Controllers/UserController.cs
@@ -42,7 +42,7 @@ namespace Timeline.Controllers
_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);
@@ -52,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();
@@ -67,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
{
@@ -94,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)
{
@@ -168,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
{
@@ -188,7 +188,7 @@ 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
{
diff --git a/BackEnd/Timeline/Models/Http/Timeline.cs b/BackEnd/Timeline/Models/Http/Timeline.cs
index a81b33f5..8e3831e1 100644
--- a/BackEnd/Timeline/Models/Http/Timeline.cs
+++ b/BackEnd/Timeline/Models/Http/Timeline.cs
@@ -11,7 +11,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Info of post content.
/// </summary>
- public class TimelinePostContentInfo
+ public class HttpTimelinePostContent
{
/// <summary>
/// Type of the post content.
@@ -34,7 +34,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Info of a post.
/// </summary>
- public class TimelinePostInfo
+ public class HttpTimelinePost
{
/// <summary>
/// Post id.
@@ -43,7 +43,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Content of the post. May be null if post is deleted.
/// </summary>
- public TimelinePostContentInfo? Content { get; set; }
+ public HttpTimelinePostContent? Content { get; set; }
/// <summary>
/// True if post is deleted.
/// </summary>
@@ -55,7 +55,7 @@ namespace Timeline.Models.Http
/// <summary>
/// The author. May be null if the user has been deleted.
/// </summary>
- public UserInfo? Author { get; set; } = default!;
+ public HttpUser? Author { get; set; } = default!;
/// <summary>
/// Last updated time.
/// </summary>
@@ -65,7 +65,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Info of a timeline.
/// </summary>
- public class TimelineInfo
+ public class HttpTimeline
{
/// <summary>
/// Unique id.
@@ -90,7 +90,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Owner of the timeline.
/// </summary>
- public UserInfo Owner { get; set; } = default!;
+ public HttpUser Owner { get; set; } = default!;
/// <summary>
/// Visibility of the timeline.
/// </summary>
@@ -99,7 +99,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Members of timeline.
/// </summary>
- public List<UserInfo> Members { get; set; } = default!;
+ public List<HttpUser> Members { get; set; } = default!;
#pragma warning restore CA2227 // Collection properties should be read only
/// <summary>
/// Create time of timeline.
@@ -114,14 +114,14 @@ namespace Timeline.Models.Http
/// <summary>
/// Related links.
/// </summary>
- public TimelineInfoLinks _links { get; set; } = default!;
+ public HttpTimelineLinks _links { get; set; } = default!;
#pragma warning restore CA1707 // Identifiers should not contain underscores
}
/// <summary>
/// Related links for timeline.
/// </summary>
- public class TimelineInfoLinks
+ public class HttpTimelineLinks
{
/// <summary>
/// Self.
@@ -133,23 +133,23 @@ namespace Timeline.Models.Http
public string Posts { get; set; } = default!;
}
- public class TimelineInfoLinksValueResolver : IValueResolver<Timeline, TimelineInfo, TimelineInfoLinks>
+ public class HttpTimelineLinksValueResolver : IValueResolver<TimelineInfo, HttpTimeline, HttpTimelineLinks>
{
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;
- public TimelineInfoLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
+ public HttpTimelineLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
{
_actionContextAccessor = actionContextAccessor;
_urlHelperFactory = urlHelperFactory;
}
- public TimelineInfoLinks Resolve(Timeline source, TimelineInfo destination, TimelineInfoLinks destMember, ResolutionContext context)
+ public HttpTimelineLinks Resolve(TimelineInfo source, HttpTimeline destination, HttpTimelineLinks destMember, ResolutionContext context)
{
var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
- return new TimelineInfoLinks
+ return new HttpTimelineLinks
{
Self = urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { source.Name }),
Posts = urlHelper.ActionLink(nameof(TimelineController.PostListGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { source.Name })
@@ -157,18 +157,18 @@ namespace Timeline.Models.Http
}
}
- public class TimelinePostContentResolver : IValueResolver<TimelinePost, TimelinePostInfo, TimelinePostContentInfo?>
+ public class HttpTimelinePostContentResolver : IValueResolver<TimelinePostInfo, HttpTimelinePost, HttpTimelinePostContent?>
{
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;
- public TimelinePostContentResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
+ public HttpTimelinePostContentResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
{
_actionContextAccessor = actionContextAccessor;
_urlHelperFactory = urlHelperFactory;
}
- public TimelinePostContentInfo? Resolve(TimelinePost source, TimelinePostInfo destination, TimelinePostContentInfo? destMember, ResolutionContext context)
+ public HttpTimelinePostContent? Resolve(TimelinePostInfo source, HttpTimelinePost destination, HttpTimelinePostContent? destMember, ResolutionContext context)
{
var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
@@ -182,7 +182,7 @@ namespace Timeline.Models.Http
if (sourceContent is TextTimelinePostContent textContent)
{
- return new TimelinePostContentInfo
+ return new HttpTimelinePostContent
{
Type = TimelinePostContentTypes.Text,
Text = textContent.Text
@@ -190,7 +190,7 @@ namespace Timeline.Models.Http
}
else if (sourceContent is ImageTimelinePostContent imageContent)
{
- return new TimelinePostContentInfo
+ return new HttpTimelinePostContent
{
Type = TimelinePostContentTypes.Image,
Url = urlHelper.ActionLink(
@@ -207,13 +207,12 @@ namespace Timeline.Models.Http
}
}
- public class TimelineInfoAutoMapperProfile : Profile
+ public class HttpTimelineAutoMapperProfile : Profile
{
- public TimelineInfoAutoMapperProfile()
+ public HttpTimelineAutoMapperProfile()
{
- CreateMap<Timeline, TimelineInfo>().ForMember(u => u._links, opt => opt.MapFrom<TimelineInfoLinksValueResolver>());
- CreateMap<TimelinePost, TimelinePostInfo>().ForMember(p => p.Content, opt => opt.MapFrom<TimelinePostContentResolver>());
- CreateMap<TimelinePatchRequest, TimelineChangePropertyRequest>();
+ CreateMap<TimelineInfo, HttpTimeline>().ForMember(u => u._links, opt => opt.MapFrom<HttpTimelineLinksValueResolver>());
+ CreateMap<TimelinePostInfo, HttpTimelinePost>().ForMember(p => p.Content, opt => opt.MapFrom<HttpTimelinePostContentResolver>());
}
}
}
diff --git a/BackEnd/Timeline/Models/Http/TimelineController.cs b/BackEnd/Timeline/Models/Http/TimelineController.cs
index 7bd141ed..42a926fd 100644
--- a/BackEnd/Timeline/Models/Http/TimelineController.cs
+++ b/BackEnd/Timeline/Models/Http/TimelineController.cs
@@ -1,4 +1,5 @@
-using System;
+using AutoMapper;
+using System;
using System.ComponentModel.DataAnnotations;
using Timeline.Models.Validation;
@@ -7,7 +8,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Content of post create request.
/// </summary>
- public class TimelinePostCreateRequestContent
+ public class HttpTimelinePostCreateRequestContent
{
/// <summary>
/// Type of post content.
@@ -24,13 +25,13 @@ namespace Timeline.Models.Http
public string? Data { get; set; }
}
- public class TimelinePostCreateRequest
+ public class HttpTimelinePostCreateRequest
{
/// <summary>
/// Content of the new post.
/// </summary>
[Required]
- public TimelinePostCreateRequestContent Content { get; set; } = default!;
+ public HttpTimelinePostCreateRequestContent Content { get; set; } = default!;
/// <summary>
/// Time of the post. If not set, current time will be used.
@@ -54,7 +55,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Patch timeline request model.
/// </summary>
- public class TimelinePatchRequest
+ public class HttpTimelinePatchRequest
{
/// <summary>
/// New title. Null for not change.
@@ -75,7 +76,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Change timeline name request model.
/// </summary>
- public class TimelineChangeNameRequest
+ public class HttpTimelineChangeNameRequest
{
/// <summary>
/// Old name of timeline.
@@ -90,4 +91,12 @@ namespace Timeline.Models.Http
[TimelineName]
public string NewName { get; set; } = default!;
}
+
+ public class HttpTimelineControllerAutoMapperProfile : Profile
+ {
+ public HttpTimelineControllerAutoMapperProfile()
+ {
+ CreateMap<HttpTimelinePatchRequest, TimelineChangePropertyRequest>();
+ }
+ }
}
diff --git a/BackEnd/Timeline/Models/Http/TokenController.cs b/BackEnd/Timeline/Models/Http/TokenController.cs
index a42c44e5..a5cbba14 100644
--- a/BackEnd/Timeline/Models/Http/TokenController.cs
+++ b/BackEnd/Timeline/Models/Http/TokenController.cs
@@ -4,9 +4,9 @@ using Timeline.Controllers;
namespace Timeline.Models.Http
{
/// <summary>
- /// Request model for <see cref="TokenController.Create(CreateTokenRequest)"/>.
+ /// Request model for <see cref="TokenController.Create(HttpCreateTokenRequest)"/>.
/// </summary>
- public class CreateTokenRequest
+ public class HttpCreateTokenRequest
{
/// <summary>
/// The username.
@@ -24,9 +24,9 @@ namespace Timeline.Models.Http
}
/// <summary>
- /// Response model for <see cref="TokenController.Create(CreateTokenRequest)"/>.
+ /// Response model for <see cref="TokenController.Create(HttpCreateTokenRequest)"/>.
/// </summary>
- public class CreateTokenResponse
+ public class HttpCreateTokenResponse
{
/// <summary>
/// The token created.
@@ -35,13 +35,13 @@ namespace Timeline.Models.Http
/// <summary>
/// The user owning the token.
/// </summary>
- public UserInfo User { get; set; } = default!;
+ public HttpUser User { get; set; } = default!;
}
/// <summary>
- /// Request model for <see cref="TokenController.Verify(VerifyTokenRequest)"/>.
+ /// Request model for <see cref="TokenController.Verify(HttpVerifyTokenRequest)"/>.
/// </summary>
- public class VerifyTokenRequest
+ public class HttpVerifyTokenRequest
{
/// <summary>
/// The token to verify.
@@ -50,13 +50,13 @@ namespace Timeline.Models.Http
}
/// <summary>
- /// Response model for <see cref="TokenController.Verify(VerifyTokenRequest)"/>.
+ /// Response model for <see cref="TokenController.Verify(HttpVerifyTokenRequest)"/>.
/// </summary>
- public class VerifyTokenResponse
+ public class HttpVerifyTokenResponse
{
/// <summary>
/// The user owning the token.
/// </summary>
- public UserInfo User { get; set; } = default!;
+ public HttpUser User { get; set; } = default!;
}
}
diff --git a/BackEnd/Timeline/Models/Http/UserInfo.cs b/BackEnd/Timeline/Models/Http/User.cs
index 0f865172..bdb40b9f 100644
--- a/BackEnd/Timeline/Models/Http/UserInfo.cs
+++ b/BackEnd/Timeline/Models/Http/User.cs
@@ -11,7 +11,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Info of a user.
/// </summary>
- public class UserInfo
+ public class HttpUser
{
/// <summary>
/// Unique id.
@@ -35,14 +35,14 @@ namespace Timeline.Models.Http
/// <summary>
/// Related links.
/// </summary>
- public UserInfoLinks _links { get; set; } = default!;
+ public HttpUserLinks _links { get; set; } = default!;
#pragma warning restore CA1707 // Identifiers should not contain underscores
}
/// <summary>
/// Related links for user.
/// </summary>
- public class UserInfoLinks
+ public class HttpUserLinks
{
/// <summary>
/// Self.
@@ -58,7 +58,7 @@ namespace Timeline.Models.Http
public string Timeline { get; set; } = default!;
}
- public class UserPermissionsValueConverter : ITypeConverter<UserPermissions, List<string>>
+ public class HttpUserPermissionsValueConverter : ITypeConverter<UserPermissions, List<string>>
{
public List<string> Convert(UserPermissions source, List<string> destination, ResolutionContext context)
{
@@ -66,23 +66,23 @@ namespace Timeline.Models.Http
}
}
- public class UserInfoLinksValueResolver : IValueResolver<User, UserInfo, UserInfoLinks>
+ public class HttpUserLinksValueResolver : IValueResolver<UserInfo, HttpUser, HttpUserLinks>
{
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;
- public UserInfoLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
+ public HttpUserLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
{
_actionContextAccessor = actionContextAccessor;
_urlHelperFactory = urlHelperFactory;
}
- public UserInfoLinks Resolve(User source, UserInfo destination, UserInfoLinks destMember, ResolutionContext context)
+ public HttpUserLinks Resolve(UserInfo source, HttpUser destination, HttpUserLinks destMember, ResolutionContext context)
{
var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
- var result = new UserInfoLinks
+ var result = new HttpUserLinks
{
Self = urlHelper.ActionLink(nameof(UserController.Get), nameof(UserController)[0..^nameof(Controller).Length], new { destination.Username }),
Avatar = urlHelper.ActionLink(nameof(UserAvatarController.Get), nameof(UserAvatarController)[0..^nameof(Controller).Length], new { destination.Username }),
@@ -92,14 +92,14 @@ namespace Timeline.Models.Http
}
}
- public class UserInfoAutoMapperProfile : Profile
+ public class HttpUserAutoMapperProfile : Profile
{
- public UserInfoAutoMapperProfile()
+ public HttpUserAutoMapperProfile()
{
CreateMap<UserPermissions, List<string>>()
- .ConvertUsing<UserPermissionsValueConverter>();
- CreateMap<User, UserInfo>()
- .ForMember(u => u._links, opt => opt.MapFrom<UserInfoLinksValueResolver>());
+ .ConvertUsing<HttpUserPermissionsValueConverter>();
+ CreateMap<UserInfo, HttpUser>()
+ .ForMember(u => u._links, opt => opt.MapFrom<HttpUserLinksValueResolver>());
}
}
}
diff --git a/BackEnd/Timeline/Models/Http/UserController.cs b/BackEnd/Timeline/Models/Http/UserController.cs
index 92a63874..1b4d09ec 100644
--- a/BackEnd/Timeline/Models/Http/UserController.cs
+++ b/BackEnd/Timeline/Models/Http/UserController.cs
@@ -7,9 +7,9 @@ using Timeline.Services;
namespace Timeline.Models.Http
{
/// <summary>
- /// Request model for <see cref="UserController.Patch(UserPatchRequest, string)"/>.
+ /// Request model for <see cref="UserController.Patch(HttpUserPatchRequest, string)"/>.
/// </summary>
- public class UserPatchRequest
+ public class HttpUserPatchRequest
{
/// <summary>
/// New username. Null if not change. Need to be administrator.
@@ -31,9 +31,9 @@ namespace Timeline.Models.Http
}
/// <summary>
- /// Request model for <see cref="UserController.CreateUser(CreateUserRequest)"/>.
+ /// Request model for <see cref="UserController.CreateUser(HttpCreateUserRequest)"/>.
/// </summary>
- public class CreateUserRequest
+ public class HttpCreateUserRequest
{
/// <summary>
/// Username of the new user.
@@ -49,9 +49,9 @@ namespace Timeline.Models.Http
}
/// <summary>
- /// Request model for <see cref="UserController.ChangePassword(ChangePasswordRequest)"/>.
+ /// Request model for <see cref="UserController.ChangePassword(HttpChangePasswordRequest)"/>.
/// </summary>
- public class ChangePasswordRequest
+ public class HttpChangePasswordRequest
{
/// <summary>
/// Old password.
@@ -66,11 +66,11 @@ namespace Timeline.Models.Http
public string NewPassword { get; set; } = default!;
}
- public class UserControllerAutoMapperProfile : Profile
+ public class HttpUserControllerModelAutoMapperProfile : Profile
{
- public UserControllerAutoMapperProfile()
+ public HttpUserControllerModelAutoMapperProfile()
{
- CreateMap<UserPatchRequest, ModifyUserParams>();
+ CreateMap<HttpUserPatchRequest, ModifyUserParams>();
}
}
}
diff --git a/BackEnd/Timeline/Models/Timeline.cs b/BackEnd/Timeline/Models/TimelineInfo.cs
index a5987577..440f6b81 100644
--- a/BackEnd/Timeline/Models/Timeline.cs
+++ b/BackEnd/Timeline/Models/TimelineInfo.cs
@@ -50,9 +50,14 @@ namespace Timeline.Models
public string DataTag { get; set; }
}
- public class TimelinePost
+ public record TimelinePostInfo
{
- public TimelinePost(long id, ITimelinePostContent? content, DateTime time, User? author, DateTime lastUpdated, string timelineName)
+ public TimelinePostInfo()
+ {
+
+ }
+
+ public TimelinePostInfo(long id, ITimelinePostContent? content, DateTime time, UserInfo? author, DateTime lastUpdated, string timelineName)
{
Id = id;
Content = content;
@@ -66,24 +71,51 @@ namespace Timeline.Models
public ITimelinePostContent? Content { get; set; }
public bool Deleted => Content == null;
public DateTime Time { get; set; }
- public User? Author { get; set; }
+ public UserInfo? Author { get; set; }
public DateTime LastUpdated { get; set; }
- public string TimelineName { get; set; }
+ public string TimelineName { get; set; } = default!;
}
-#pragma warning disable CA1724 // Type names should not match namespaces
- public class Timeline
-#pragma warning restore CA1724 // Type names should not match namespaces
+ public record TimelineInfo
{
- public string UniqueID { get; set; } = default!;
+ public TimelineInfo()
+ {
+
+ }
+
+ public TimelineInfo(
+ string uniqueId,
+ string name,
+ DateTime nameLastModified,
+ string title,
+ string description,
+ UserInfo owner,
+ TimelineVisibility visibility,
+ List<UserInfo> members,
+ DateTime createTime,
+ DateTime lastModified)
+ {
+ UniqueId = uniqueId;
+ Name = name;
+ NameLastModified = nameLastModified;
+ Title = title;
+ Description = description;
+ Owner = owner;
+ Visibility = visibility;
+ Members = members;
+ CreateTime = createTime;
+ LastModified = lastModified;
+ }
+
+ public string UniqueId { get; set; } = default!;
public string Name { get; set; } = default!;
public DateTime NameLastModified { get; set; } = default!;
public string Title { get; set; } = default!;
public string Description { get; set; } = default!;
- public User Owner { get; set; } = default!;
+ public UserInfo Owner { get; set; } = default!;
public TimelineVisibility Visibility { get; set; }
#pragma warning disable CA2227 // Collection properties should be read only
- public List<User> Members { get; set; } = default!;
+ public List<UserInfo> Members { get; set; } = default!;
#pragma warning restore CA2227 // Collection properties should be read only
public DateTime CreateTime { get; set; } = default!;
public DateTime LastModified { get; set; } = default!;
diff --git a/BackEnd/Timeline/Models/User.cs b/BackEnd/Timeline/Models/User.cs
deleted file mode 100644
index ae2afe85..00000000
--- a/BackEnd/Timeline/Models/User.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using Timeline.Services;
-
-namespace Timeline.Models
-{
- public record User
- {
- public long Id { get; set; }
- public string UniqueId { get; set; } = default!;
-
- public string Username { get; set; } = default!;
- public string Nickname { get; set; } = default!;
-
- public UserPermissions Permissions { get; set; } = default!;
-
- public DateTime UsernameChangeTime { get; set; }
- public DateTime CreateTime { get; set; }
- public DateTime LastModified { get; set; }
- public long Version { get; set; }
- }
-}
diff --git a/BackEnd/Timeline/Models/UserInfo.cs b/BackEnd/Timeline/Models/UserInfo.cs
new file mode 100644
index 00000000..058cc590
--- /dev/null
+++ b/BackEnd/Timeline/Models/UserInfo.cs
@@ -0,0 +1,48 @@
+using System;
+using Timeline.Services;
+
+namespace Timeline.Models
+{
+ public record UserInfo
+ {
+ public UserInfo()
+ {
+
+ }
+
+ public UserInfo(
+ long id,
+ string uniqueId,
+ string username,
+ string nickname,
+ UserPermissions permissions,
+ DateTime usernameChangeTime,
+ DateTime createTime,
+ DateTime lastModified,
+ long version)
+ {
+ Id = id;
+ UniqueId = uniqueId;
+ Username = username;
+ Nickname = nickname;
+ Permissions = permissions;
+ UsernameChangeTime = usernameChangeTime;
+ CreateTime = createTime;
+ LastModified = lastModified;
+ Version = version;
+ }
+
+ public long Id { get; set; }
+ public string UniqueId { get; set; } = default!;
+
+ public string Username { get; set; } = default!;
+ public string Nickname { get; set; } = default!;
+
+ public UserPermissions Permissions { get; set; } = default!;
+
+ public DateTime UsernameChangeTime { get; set; }
+ public DateTime CreateTime { get; set; }
+ public DateTime LastModified { get; set; }
+ public long Version { get; set; }
+ }
+}
diff --git a/BackEnd/Timeline/Services/HighlightTimelineService.cs b/BackEnd/Timeline/Services/HighlightTimelineService.cs
index 88ad4a4b..619bc33e 100644
--- a/BackEnd/Timeline/Services/HighlightTimelineService.cs
+++ b/BackEnd/Timeline/Services/HighlightTimelineService.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Timeline.Entities;
+using Timeline.Models;
using Timeline.Services.Exceptions;
namespace Timeline.Services
@@ -14,7 +15,7 @@ namespace Timeline.Services
/// Get all highlight timelines.
/// </summary>
/// <returns>A list of all highlight timelines.</returns>
- Task<List<Models.Timeline>> GetHighlightTimelines();
+ Task<List<TimelineInfo>> GetHighlightTimelines();
/// <summary>
/// Add a timeline to highlight list.
@@ -73,11 +74,11 @@ namespace Timeline.Services
await _database.SaveChangesAsync();
}
- public async Task<List<Models.Timeline>> GetHighlightTimelines()
+ public async Task<List<TimelineInfo>> GetHighlightTimelines()
{
var entities = await _database.HighlightTimelines.Select(t => new { t.Id }).ToListAsync();
- var result = new List<Models.Timeline>();
+ var result = new List<TimelineInfo>();
foreach (var entity in entities)
{
diff --git a/BackEnd/Timeline/Services/TimelinePostService.cs b/BackEnd/Timeline/Services/TimelinePostService.cs
index a1176a68..35513a36 100644
--- a/BackEnd/Timeline/Services/TimelinePostService.cs
+++ b/BackEnd/Timeline/Services/TimelinePostService.cs
@@ -39,7 +39,7 @@ namespace Timeline.Services
/// Thrown when timeline with name <paramref name="timelineName"/> does not exist.
/// If it is a personal timeline, then inner exception is <see cref="UserNotExistException"/>.
/// </exception>
- Task<List<TimelinePost>> GetPosts(string timelineName, DateTime? modifiedSince = null, bool includeDeleted = false);
+ Task<List<TimelinePostInfo>> GetPosts(string timelineName, DateTime? modifiedSince = null, bool includeDeleted = false);
/// <summary>
/// Get the etag of data of a post.
@@ -90,7 +90,7 @@ namespace Timeline.Services
/// If it is a personal timeline, then inner exception is <see cref="UserNotExistException"/>.
/// </exception>
/// <exception cref="UserNotExistException">Thrown if user of <paramref name="authorId"/> does not exist.</exception>
- Task<TimelinePost> CreateTextPost(string timelineName, long authorId, string text, DateTime? time);
+ Task<TimelinePostInfo> CreateTextPost(string timelineName, long authorId, string text, DateTime? time);
/// <summary>
/// Create a new image post in timeline.
@@ -108,7 +108,7 @@ namespace Timeline.Services
/// </exception>
/// <exception cref="UserNotExistException">Thrown if user of <paramref name="authorId"/> does not exist.</exception>
/// <exception cref="ImageException">Thrown if data is not a image. Validated by <see cref="ImageValidator"/>.</exception>
- Task<TimelinePost> CreateImagePost(string timelineName, long authorId, byte[] imageData, DateTime? time);
+ Task<TimelinePostInfo> CreateImagePost(string timelineName, long authorId, byte[] imageData, DateTime? time);
/// <summary>
/// Delete a post.
@@ -179,9 +179,9 @@ namespace Timeline.Services
_clock = clock;
}
- private async Task<TimelinePost> MapTimelinePostFromEntity(TimelinePostEntity entity, string timelineName)
+ private async Task<TimelinePostInfo> MapTimelinePostFromEntity(TimelinePostEntity entity, string timelineName)
{
- User? author = entity.AuthorId.HasValue ? await _userService.GetUser(entity.AuthorId.Value) : null;
+ UserInfo? author = entity.AuthorId.HasValue ? await _userService.GetUser(entity.AuthorId.Value) : null;
ITimelinePostContent? content = null;
@@ -197,7 +197,7 @@ namespace Timeline.Services
};
}
- return new TimelinePost(
+ return new TimelinePostInfo(
id: entity.LocalId,
author: author,
content: content,
@@ -207,7 +207,7 @@ namespace Timeline.Services
);
}
- public async Task<List<TimelinePost>> GetPosts(string timelineName, DateTime? modifiedSince = null, bool includeDeleted = false)
+ public async Task<List<TimelinePostInfo>> GetPosts(string timelineName, DateTime? modifiedSince = null, bool includeDeleted = false)
{
modifiedSince = modifiedSince?.MyToUtc();
@@ -231,7 +231,7 @@ namespace Timeline.Services
var postEntities = await query.ToListAsync();
- var posts = new List<TimelinePost>();
+ var posts = new List<TimelinePostInfo>();
foreach (var entity in postEntities)
{
posts.Add(await MapTimelinePostFromEntity(entity, timelineName));
@@ -309,7 +309,7 @@ namespace Timeline.Services
};
}
- public async Task<TimelinePost> CreateTextPost(string timelineName, long authorId, string text, DateTime? time)
+ public async Task<TimelinePostInfo> CreateTextPost(string timelineName, long authorId, string text, DateTime? time)
{
time = time?.MyToUtc();
@@ -342,7 +342,7 @@ namespace Timeline.Services
await _database.SaveChangesAsync();
- return new TimelinePost(
+ return new TimelinePostInfo(
id: postEntity.LocalId,
content: new TextTimelinePostContent(text),
time: finalTime,
@@ -352,7 +352,7 @@ namespace Timeline.Services
);
}
- public async Task<TimelinePost> CreateImagePost(string timelineName, long authorId, byte[] data, DateTime? time)
+ public async Task<TimelinePostInfo> CreateImagePost(string timelineName, long authorId, byte[] data, DateTime? time)
{
time = time?.MyToUtc();
@@ -391,7 +391,7 @@ namespace Timeline.Services
_database.TimelinePosts.Add(postEntity);
await _database.SaveChangesAsync();
- return new TimelinePost(
+ return new TimelinePostInfo(
id: postEntity.LocalId,
content: new ImageTimelinePostContent(tag),
time: finalTime,
diff --git a/BackEnd/Timeline/Services/TimelineService.cs b/BackEnd/Timeline/Services/TimelineService.cs
index b8ec354a..b65b3cf4 100644
--- a/BackEnd/Timeline/Services/TimelineService.cs
+++ b/BackEnd/Timeline/Services/TimelineService.cs
@@ -90,7 +90,7 @@ namespace Timeline.Services
/// Thrown when timeline with name <paramref name="timelineName"/> does not exist.
/// If it is a personal timeline, then inner exception is <see cref="UserNotExistException"/>.
/// </exception>
- Task<Models.Timeline> GetTimeline(string timelineName);
+ Task<TimelineInfo> GetTimeline(string timelineName);
/// <summary>
/// Get timeline by id.
@@ -98,7 +98,7 @@ namespace Timeline.Services
/// <param name="id">Id of timeline.</param>
/// <returns>The timeline.</returns>
/// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
- Task<Models.Timeline> GetTimelineById(long id);
+ Task<TimelineInfo> GetTimelineById(long id);
/// <summary>
/// Set the properties of a timeline.
@@ -113,8 +113,6 @@ namespace Timeline.Services
/// </exception>
Task ChangeProperty(string timelineName, TimelineChangePropertyRequest newProperties);
-
-
/// <summary>
/// Change member of timeline.
/// </summary>
@@ -174,7 +172,6 @@ namespace Timeline.Services
/// </remarks>
Task<bool> HasReadPermission(string timelineName, long? visitorId);
-
/// <summary>
/// Verify whether a user is member of a timeline.
/// </summary>
@@ -202,7 +199,7 @@ namespace Timeline.Services
/// <remarks>
/// If user with related user id does not exist, empty list will be returned.
/// </remarks>
- Task<List<Models.Timeline>> GetTimelines(TimelineUserRelationship? relate = null, List<TimelineVisibility>? visibility = null);
+ Task<List<TimelineInfo>> GetTimelines(TimelineUserRelationship? relate = null, List<TimelineVisibility>? visibility = null);
/// <summary>
/// Create a timeline.
@@ -214,7 +211,7 @@ namespace Timeline.Services
/// <exception cref="ArgumentException">Thrown when timeline name is invalid.</exception>
/// <exception cref="EntityAlreadyExistException">Thrown when the timeline already exists.</exception>
/// <exception cref="UserNotExistException">Thrown when the owner user does not exist.</exception>
- Task<Models.Timeline> CreateTimeline(string timelineName, long ownerId);
+ Task<TimelineInfo> CreateTimeline(string timelineName, long ownerId);
/// <summary>
/// Delete a timeline.
@@ -238,7 +235,7 @@ namespace Timeline.Services
/// <remarks>
/// You can only change name of general timeline.
/// </remarks>
- Task<Models.Timeline> ChangeTimelineName(string oldTimelineName, string newTimelineName);
+ Task<TimelineInfo> ChangeTimelineName(string oldTimelineName, string newTimelineName);
}
public class TimelineService : BasicTimelineService, ITimelineService
@@ -270,11 +267,11 @@ namespace Timeline.Services
}
/// Remember to include Members when query.
- private async Task<Models.Timeline> MapTimelineFromEntity(TimelineEntity entity)
+ private async Task<TimelineInfo> MapTimelineFromEntity(TimelineEntity entity)
{
var owner = await _userService.GetUser(entity.OwnerId);
- var members = new List<User>();
+ var members = new List<UserInfo>();
foreach (var memberEntity in entity.Members)
{
members.Add(await _userService.GetUser(memberEntity.UserId));
@@ -282,19 +279,18 @@ namespace Timeline.Services
var name = entity.Name ?? ("@" + owner.Username);
- return new Models.Timeline
- {
- UniqueID = entity.UniqueId,
- Name = name,
- NameLastModified = entity.NameLastModified,
- Title = string.IsNullOrEmpty(entity.Title) ? name : entity.Title,
- Description = entity.Description ?? "",
- Owner = owner,
- Visibility = entity.Visibility,
- Members = members,
- CreateTime = entity.CreateTime,
- LastModified = entity.LastModified
- };
+ return new TimelineInfo(
+ entity.UniqueId,
+ name,
+ entity.NameLastModified,
+ string.IsNullOrEmpty(entity.Title) ? name : entity.Title,
+ entity.Description ?? "",
+ owner,
+ entity.Visibility,
+ members,
+ entity.CreateTime,
+ entity.LastModified
+ );
}
public async Task<DateTime> GetTimelineLastModifiedTime(string timelineName)
@@ -321,7 +317,7 @@ namespace Timeline.Services
return timelineEntity.UniqueId;
}
- public async Task<Models.Timeline> GetTimeline(string timelineName)
+ public async Task<TimelineInfo> GetTimeline(string timelineName)
{
if (timelineName == null)
throw new ArgumentNullException(nameof(timelineName));
@@ -333,7 +329,7 @@ namespace Timeline.Services
return await MapTimelineFromEntity(timelineEntity);
}
- public async Task<Models.Timeline> GetTimelineById(long id)
+ public async Task<TimelineInfo> GetTimelineById(long id)
{
var timelineEntity = await _database.Timelines.Where(t => t.Id == id).Include(t => t.Members).SingleOrDefaultAsync();
@@ -522,7 +518,7 @@ namespace Timeline.Services
return await _database.TimelineMembers.AnyAsync(m => m.TimelineId == timelineId && m.UserId == userId);
}
- public async Task<List<Models.Timeline>> GetTimelines(TimelineUserRelationship? relate = null, List<TimelineVisibility>? visibility = null)
+ public async Task<List<TimelineInfo>> GetTimelines(TimelineUserRelationship? relate = null, List<TimelineVisibility>? visibility = null)
{
List<TimelineEntity> entities;
@@ -556,7 +552,7 @@ namespace Timeline.Services
}
}
- var result = new List<Models.Timeline>();
+ var result = new List<TimelineInfo>();
foreach (var entity in entities)
{
@@ -566,7 +562,7 @@ namespace Timeline.Services
return result;
}
- public async Task<Models.Timeline> CreateTimeline(string name, long owner)
+ public async Task<TimelineInfo> CreateTimeline(string name, long owner)
{
if (name == null)
throw new ArgumentNullException(nameof(name));
@@ -604,7 +600,7 @@ namespace Timeline.Services
await _database.SaveChangesAsync();
}
- public async Task<Models.Timeline> ChangeTimelineName(string oldTimelineName, string newTimelineName)
+ public async Task<TimelineInfo> ChangeTimelineName(string oldTimelineName, string newTimelineName)
{
if (oldTimelineName == null)
throw new ArgumentNullException(nameof(oldTimelineName));
diff --git a/BackEnd/Timeline/Services/UserCredentialService.cs b/BackEnd/Timeline/Services/UserCredentialService.cs
index e5c3581b..8aeef9ef 100644
--- a/BackEnd/Timeline/Services/UserCredentialService.cs
+++ b/BackEnd/Timeline/Services/UserCredentialService.cs
@@ -1,12 +1,10 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
-using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Timeline.Entities;
using Timeline.Helpers;
-using Timeline.Models;
using Timeline.Models.Validation;
using Timeline.Services.Exceptions;
diff --git a/BackEnd/Timeline/Services/UserService.cs b/BackEnd/Timeline/Services/UserService.cs
index 9395cc52..96068e44 100644
--- a/BackEnd/Timeline/Services/UserService.cs
+++ b/BackEnd/Timeline/Services/UserService.cs
@@ -32,13 +32,13 @@ namespace Timeline.Services
/// <param name="id">The id of the user.</param>
/// <returns>The user info.</returns>
/// <exception cref="UserNotExistException">Thrown when the user with given id does not exist.</exception>
- Task<User> GetUser(long id);
+ Task<UserInfo> GetUser(long id);
/// <summary>
/// List all users.
/// </summary>
/// <returns>The user info of users.</returns>
- Task<List<User>> GetUsers();
+ Task<List<UserInfo>> GetUsers();
/// <summary>
/// Create a user with given info.
@@ -49,7 +49,7 @@ namespace Timeline.Services
/// <exception cref="ArgumentNullException">Thrown when <paramref name="username"/> or <paramref name="password"/> is null.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="username"/> or <paramref name="password"/> is of bad format.</exception>
/// <exception cref="EntityAlreadyExistException">Thrown when a user with given username already exists.</exception>
- Task<User> CreateUser(string username, string password);
+ Task<UserInfo> CreateUser(string username, string password);
/// <summary>
/// Modify a user.
@@ -62,7 +62,7 @@ namespace Timeline.Services
/// <remarks>
/// Version will increase if password is changed.
/// </remarks>
- Task<User> ModifyUser(long id, ModifyUserParams? param);
+ Task<UserInfo> ModifyUser(long id, ModifyUserParams? param);
}
public class UserService : BasicUserService, IUserService
@@ -116,26 +116,23 @@ namespace Timeline.Services
throw new EntityAlreadyExistException(EntityNames.User, ExceptionUsernameConflict);
}
- private async Task<User> CreateUserFromEntity(UserEntity entity)
+ private async Task<UserInfo> CreateUserFromEntity(UserEntity entity)
{
var permission = await _userPermissionService.GetPermissionsOfUserAsync(entity.Id);
- return new User
- {
- UniqueId = entity.UniqueId,
- Username = entity.Username,
- Permissions = permission,
- Nickname = string.IsNullOrEmpty(entity.Nickname) ? entity.Username : entity.Nickname,
- Id = entity.Id,
- Version = entity.Version,
- CreateTime = entity.CreateTime,
- UsernameChangeTime = entity.UsernameChangeTime,
- LastModified = entity.LastModified
- };
+ return new UserInfo(
+ entity.Id,
+ entity.UniqueId,
+ entity.Username,
+ string.IsNullOrEmpty(entity.Nickname) ? entity.Username : entity.Nickname,
+ permission,
+ entity.UsernameChangeTime,
+ entity.CreateTime,
+ entity.LastModified,
+ entity.Version
+ );
}
-
-
- public async Task<User> GetUser(long id)
+ public async Task<UserInfo> GetUser(long id)
{
var user = await _databaseContext.Users.Where(u => u.Id == id).SingleOrDefaultAsync();
@@ -145,9 +142,9 @@ namespace Timeline.Services
return await CreateUserFromEntity(user);
}
- public async Task<List<User>> GetUsers()
+ public async Task<List<UserInfo>> GetUsers()
{
- List<User> result = new();
+ List<UserInfo> result = new();
foreach (var entity in await _databaseContext.Users.ToArrayAsync())
{
result.Add(await CreateUserFromEntity(entity));
@@ -155,7 +152,7 @@ namespace Timeline.Services
return result;
}
- public async Task<User> CreateUser(string username, string password)
+ public async Task<UserInfo> CreateUser(string username, string password)
{
if (username == null)
throw new ArgumentNullException(nameof(username));
@@ -183,7 +180,7 @@ namespace Timeline.Services
return await CreateUserFromEntity(newEntity);
}
- public async Task<User> ModifyUser(long id, ModifyUserParams? param)
+ public async Task<UserInfo> ModifyUser(long id, ModifyUserParams? param)
{
if (param != null)
{
diff --git a/BackEnd/Timeline/Services/UserTokenManager.cs b/BackEnd/Timeline/Services/UserTokenManager.cs
index 831329e6..b887b987 100644
--- a/BackEnd/Timeline/Services/UserTokenManager.cs
+++ b/BackEnd/Timeline/Services/UserTokenManager.cs
@@ -10,7 +10,7 @@ namespace Timeline.Services
public class UserTokenCreateResult
{
public string Token { get; set; } = default!;
- public User User { get; set; } = default!;
+ public UserInfo User { get; set; } = default!;
}
public interface IUserTokenManager
@@ -38,7 +38,7 @@ namespace Timeline.Services
/// <exception cref="UserTokenBadVersionException">Thrown when the token is of bad version.</exception>
/// <exception cref="UserTokenBadFormatException">Thrown when the token is of bad format.</exception>
/// <exception cref="UserNotExistException">Thrown when the user specified by the token does not exist. Usually the user had been deleted after the token was issued.</exception>
- public Task<User> VerifyToken(string token);
+ public Task<UserInfo> VerifyToken(string token);
}
public class UserTokenManager : IUserTokenManager
@@ -75,7 +75,7 @@ namespace Timeline.Services
}
- public async Task<User> VerifyToken(string token)
+ public async Task<UserInfo> VerifyToken(string token)
{
if (token == null)
throw new ArgumentNullException(nameof(token));