diff options
Diffstat (limited to 'BackEnd/Timeline/Models/Http')
-rw-r--r-- | BackEnd/Timeline/Models/Http/CommonResponse.cs (renamed from BackEnd/Timeline/Models/Http/Common.cs) | 10 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Http/ErrorResponse.cs | 10 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Http/Timeline.cs | 137 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Http/TimelineController.cs | 3 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Http/User.cs | 73 |
5 files changed, 81 insertions, 152 deletions
diff --git a/BackEnd/Timeline/Models/Http/Common.cs b/BackEnd/Timeline/Models/Http/CommonResponse.cs index 2101a1bb..3d0ed509 100644 --- a/BackEnd/Timeline/Models/Http/Common.cs +++ b/BackEnd/Timeline/Models/Http/CommonResponse.cs @@ -60,6 +60,11 @@ namespace Timeline.Models.Http }
+ internal static CommonPutResponse Create(bool create)
+ {
+ return new CommonPutResponse(0, MessagePutCreate, create);
+ }
+
internal static CommonPutResponse Create()
{
return new CommonPutResponse(0, MessagePutCreate, true);
@@ -107,6 +112,11 @@ namespace Timeline.Models.Http }
+ internal static CommonDeleteResponse Create(bool delete)
+ {
+ return new CommonDeleteResponse(0, MessageDeleteDelete, delete);
+ }
+
internal static CommonDeleteResponse Delete()
{
return new CommonDeleteResponse(0, MessageDeleteDelete, true);
diff --git a/BackEnd/Timeline/Models/Http/ErrorResponse.cs b/BackEnd/Timeline/Models/Http/ErrorResponse.cs index 10755fd1..1bc46680 100644 --- a/BackEnd/Timeline/Models/Http/ErrorResponse.cs +++ b/BackEnd/Timeline/Models/Http/ErrorResponse.cs @@ -234,16 +234,6 @@ namespace Timeline.Models.Http return new CommonResponse(ErrorCodes.TimelineController.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));
- }
-
- public static CommonResponse CustomMessage_MemberPut_NotExist(string message, params object?[] formatArgs)
- {
- return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(message, formatArgs));
- }
-
public static CommonResponse QueryRelateNotExist(params object?[] formatArgs)
{
return new CommonResponse(ErrorCodes.TimelineController.QueryRelateNotExist, string.Format(TimelineController_QueryRelateNotExist, formatArgs));
diff --git a/BackEnd/Timeline/Models/Http/Timeline.cs b/BackEnd/Timeline/Models/Http/Timeline.cs index 8e3831e1..06fa4e5a 100644 --- a/BackEnd/Timeline/Models/Http/Timeline.cs +++ b/BackEnd/Timeline/Models/Http/Timeline.cs @@ -1,10 +1,5 @@ -using AutoMapper;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Infrastructure;
-using Microsoft.AspNetCore.Mvc.Routing;
-using System;
+using System;
using System.Collections.Generic;
-using Timeline.Controllers;
namespace Timeline.Models.Http
{
@@ -13,6 +8,16 @@ namespace Timeline.Models.Http /// </summary>
public class HttpTimelinePostContent
{
+ public HttpTimelinePostContent() { }
+
+ public HttpTimelinePostContent(string type, string? text, string? url, string? eTag)
+ {
+ Type = type;
+ Text = text;
+ Url = url;
+ ETag = eTag;
+ }
+
/// <summary>
/// Type of the post content.
/// </summary>
@@ -36,6 +41,18 @@ namespace Timeline.Models.Http /// </summary>
public class HttpTimelinePost
{
+ public HttpTimelinePost() { }
+
+ public HttpTimelinePost(long id, HttpTimelinePostContent? content, bool deleted, DateTime time, HttpUser? author, DateTime lastUpdated)
+ {
+ Id = id;
+ Content = content;
+ Deleted = deleted;
+ Time = time;
+ Author = author;
+ LastUpdated = lastUpdated;
+ }
+
/// <summary>
/// Post id.
/// </summary>
@@ -67,6 +84,23 @@ namespace Timeline.Models.Http /// </summary>
public class HttpTimeline
{
+ public HttpTimeline() { }
+
+ public HttpTimeline(string uniqueId, string title, string name, DateTime nameLastModifed, string description, HttpUser owner, TimelineVisibility visibility, List<HttpUser> members, DateTime createTime, DateTime lastModified, HttpTimelineLinks links)
+ {
+ UniqueId = uniqueId;
+ Title = title;
+ Name = name;
+ NameLastModifed = nameLastModifed;
+ Description = description;
+ Owner = owner;
+ Visibility = visibility;
+ Members = members;
+ CreateTime = createTime;
+ LastModified = lastModified;
+ _links = links;
+ }
+
/// <summary>
/// Unique id.
/// </summary>
@@ -123,6 +157,14 @@ namespace Timeline.Models.Http /// </summary>
public class HttpTimelineLinks
{
+ public HttpTimelineLinks() { }
+
+ public HttpTimelineLinks(string self, string posts)
+ {
+ Self = self;
+ Posts = posts;
+ }
+
/// <summary>
/// Self.
/// </summary>
@@ -132,87 +174,4 @@ namespace Timeline.Models.Http /// </summary>
public string Posts { get; set; } = default!;
}
-
- public class HttpTimelineLinksValueResolver : IValueResolver<TimelineInfo, HttpTimeline, HttpTimelineLinks>
- {
- private readonly IActionContextAccessor _actionContextAccessor;
- private readonly IUrlHelperFactory _urlHelperFactory;
-
- public HttpTimelineLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
- {
- _actionContextAccessor = actionContextAccessor;
- _urlHelperFactory = urlHelperFactory;
- }
-
- public HttpTimelineLinks Resolve(TimelineInfo source, HttpTimeline destination, HttpTimelineLinks destMember, ResolutionContext context)
- {
- var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
- var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
-
- 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 })
- };
- }
- }
-
- public class HttpTimelinePostContentResolver : IValueResolver<TimelinePostInfo, HttpTimelinePost, HttpTimelinePostContent?>
- {
- private readonly IActionContextAccessor _actionContextAccessor;
- private readonly IUrlHelperFactory _urlHelperFactory;
-
- public HttpTimelinePostContentResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
- {
- _actionContextAccessor = actionContextAccessor;
- _urlHelperFactory = urlHelperFactory;
- }
-
- public HttpTimelinePostContent? Resolve(TimelinePostInfo source, HttpTimelinePost destination, HttpTimelinePostContent? destMember, ResolutionContext context)
- {
- var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
- var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
-
- var sourceContent = source.Content;
-
- if (sourceContent == null)
- {
- return null;
- }
-
- if (sourceContent is TextTimelinePostContent textContent)
- {
- return new HttpTimelinePostContent
- {
- Type = TimelinePostContentTypes.Text,
- Text = textContent.Text
- };
- }
- else if (sourceContent is ImageTimelinePostContent imageContent)
- {
- return new HttpTimelinePostContent
- {
- Type = TimelinePostContentTypes.Image,
- Url = urlHelper.ActionLink(
- action: nameof(TimelineController.PostDataGet),
- controller: nameof(TimelineController)[0..^nameof(Controller).Length],
- values: new { Name = source.TimelineName, Id = source.Id }),
- ETag = $"\"{imageContent.DataTag}\""
- };
- }
- else
- {
- throw new InvalidOperationException(Resources.Models.Http.Exception.UnknownPostContentType);
- }
- }
- }
-
- public class HttpTimelineAutoMapperProfile : Profile
- {
- public HttpTimelineAutoMapperProfile()
- {
- 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 42a926fd..f6039b35 100644 --- a/BackEnd/Timeline/Models/Http/TimelineController.cs +++ b/BackEnd/Timeline/Models/Http/TimelineController.cs @@ -2,6 +2,7 @@ using System;
using System.ComponentModel.DataAnnotations;
using Timeline.Models.Validation;
+using Timeline.Services;
namespace Timeline.Models.Http
{
@@ -96,7 +97,7 @@ namespace Timeline.Models.Http {
public HttpTimelineControllerAutoMapperProfile()
{
- CreateMap<HttpTimelinePatchRequest, TimelineChangePropertyRequest>();
+ CreateMap<HttpTimelinePatchRequest, TimelineChangePropertyParams>();
}
}
}
diff --git a/BackEnd/Timeline/Models/Http/User.cs b/BackEnd/Timeline/Models/Http/User.cs index bdb40b9f..994c08bf 100644 --- a/BackEnd/Timeline/Models/Http/User.cs +++ b/BackEnd/Timeline/Models/Http/User.cs @@ -1,10 +1,4 @@ -using AutoMapper;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Infrastructure;
-using Microsoft.AspNetCore.Mvc.Routing;
-using System.Collections.Generic;
-using Timeline.Controllers;
-using Timeline.Services;
+using System.Collections.Generic;
namespace Timeline.Models.Http
{
@@ -13,6 +7,17 @@ namespace Timeline.Models.Http /// </summary>
public class HttpUser
{
+ public HttpUser() { }
+
+ public HttpUser(string uniqueId, string username, string nickname, List<string> permissions, HttpUserLinks links)
+ {
+ UniqueId = uniqueId;
+ Username = username;
+ Nickname = nickname;
+ Permissions = permissions;
+ _links = links;
+ }
+
/// <summary>
/// Unique id.
/// </summary>
@@ -44,6 +49,15 @@ namespace Timeline.Models.Http /// </summary>
public class HttpUserLinks
{
+ public HttpUserLinks() { }
+
+ public HttpUserLinks(string self, string avatar, string timeline)
+ {
+ Self = self;
+ Avatar = avatar;
+ Timeline = timeline;
+ }
+
/// <summary>
/// Self.
/// </summary>
@@ -57,49 +71,4 @@ namespace Timeline.Models.Http /// </summary>
public string Timeline { get; set; } = default!;
}
-
- public class HttpUserPermissionsValueConverter : ITypeConverter<UserPermissions, List<string>>
- {
- public List<string> Convert(UserPermissions source, List<string> destination, ResolutionContext context)
- {
- return source.ToStringList();
- }
- }
-
- public class HttpUserLinksValueResolver : IValueResolver<UserInfo, HttpUser, HttpUserLinks>
- {
- private readonly IActionContextAccessor _actionContextAccessor;
- private readonly IUrlHelperFactory _urlHelperFactory;
-
- public HttpUserLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
- {
- _actionContextAccessor = actionContextAccessor;
- _urlHelperFactory = urlHelperFactory;
- }
-
- public HttpUserLinks Resolve(UserInfo source, HttpUser destination, HttpUserLinks destMember, ResolutionContext context)
- {
- var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
- var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
-
- 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 }),
- Timeline = urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { Name = "@" + destination.Username })
- };
- return result;
- }
- }
-
- public class HttpUserAutoMapperProfile : Profile
- {
- public HttpUserAutoMapperProfile()
- {
- CreateMap<UserPermissions, List<string>>()
- .ConvertUsing<HttpUserPermissionsValueConverter>();
- CreateMap<UserInfo, HttpUser>()
- .ForMember(u => u._links, opt => opt.MapFrom<HttpUserLinksValueResolver>());
- }
- }
}
|