From 53b237832d3d967b531a8dc130ebbf2ede173741 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 11 Mar 2020 18:16:18 +0800 Subject: ... --- Timeline/Controllers/TimelineController.cs | 4 +-- Timeline/Filters/Timeline.cs | 2 +- Timeline/Models/Http/ErrorResponse.cs | 29 ++++++++++------- Timeline/Resources/Messages.Designer.cs | 51 ++++++++++++++++++------------ Timeline/Resources/Messages.resx | 21 ++++++------ Timeline/Services/TimelineService.cs | 14 ++++---- 6 files changed, 69 insertions(+), 52 deletions(-) (limited to 'Timeline') diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index d21603cd..0628937d 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -234,7 +234,7 @@ namespace Timeline.Controllers } catch (UserNotExistException) { - return BadRequest(ErrorResponse.TimelineCommon.MemberPut_NotExist()); + return BadRequest(ErrorResponse.TimelineController.MemberPut_NotExist()); } } @@ -272,7 +272,7 @@ namespace Timeline.Controllers } catch (ConflictException) { - return BadRequest(ErrorResponse.TimelineCommon.NameConflict()); + return BadRequest(ErrorResponse.TimelineController.NameConflict()); } } diff --git a/Timeline/Filters/Timeline.cs b/Timeline/Filters/Timeline.cs index e133c9d6..76e8d751 100644 --- a/Timeline/Filters/Timeline.cs +++ b/Timeline/Filters/Timeline.cs @@ -17,7 +17,7 @@ namespace Timeline.Filters } else { - context.Result = new NotFoundObjectResult(ErrorResponse.TimelineCommon.NotExist()); + context.Result = new NotFoundObjectResult(ErrorResponse.TimelineController.NotExist()); } } } diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs index 9f7e70e1..9c5a7cfe 100644 --- a/Timeline/Models/Http/ErrorResponse.cs +++ b/Timeline/Models/Http/ErrorResponse.cs @@ -242,44 +242,39 @@ namespace Timeline.Models.Http } - public static class TimelineCommon + public static class TimelineController { public static CommonResponse NameConflict(params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.NameConflict, string.Format(TimelineCommon_NameConflict, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.NameConflict, string.Format(TimelineController_NameConflict, formatArgs)); } public static CommonResponse CustomMessage_NameConflict(string message, params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.NameConflict, string.Format(message, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.NameConflict, string.Format(message, formatArgs)); } public static CommonResponse NotExist(params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.NotExist, string.Format(TimelineCommon_NotExist, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.NotExist, string.Format(TimelineController_NotExist, formatArgs)); } public static CommonResponse CustomMessage_NotExist(string message, params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.NotExist, string.Format(message, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.NotExist, string.Format(message, formatArgs)); } public static CommonResponse MemberPut_NotExist(params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineCommon.MemberPut_NotExist, string.Format(TimelineCommon_MemberPut_NotExist, 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.TimelineCommon.MemberPut_NotExist, string.Format(message, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(message, formatArgs)); } - } - - public static class TimelineController - { - public static CommonResponse QueryRelateNotExist(params object?[] formatArgs) { return new CommonResponse(ErrorCodes.TimelineController.QueryRelateNotExist, string.Format(TimelineController_QueryRelateNotExist, formatArgs)); @@ -290,6 +285,16 @@ namespace Timeline.Models.Http return new CommonResponse(ErrorCodes.TimelineController.QueryRelateNotExist, string.Format(message, formatArgs)); } + public static CommonResponse PostNoData(params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineController.PostNoData, string.Format(TimelineController_PostNoData, formatArgs)); + } + + public static CommonResponse CustomMessage_PostNoData(string message, params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineController.PostNoData, string.Format(message, formatArgs)); + } + } } diff --git a/Timeline/Resources/Messages.Designer.cs b/Timeline/Resources/Messages.Designer.cs index fb093f07..cae91093 100644 --- a/Timeline/Resources/Messages.Designer.cs +++ b/Timeline/Resources/Messages.Designer.cs @@ -151,65 +151,74 @@ namespace Timeline.Resources { } /// - /// Looks up a localized string similar to The user to set as member does not exist.. + /// Looks up a localized string similar to Unknown type of post content.. /// - internal static string TimelineCommon_MemberPut_NotExist { + internal static string TimelineController_ContentUnknownType { get { - return ResourceManager.GetString("TimelineCommon_MemberPut_NotExist", resourceCulture); + return ResourceManager.GetString("TimelineController_ContentUnknownType", resourceCulture); } } /// - /// Looks up a localized string similar to A timeline with given name already exists.. + /// Looks up a localized string similar to Data field is not a valid base64 string in image content.. /// - internal static string TimelineCommon_NameConflict { + internal static string TimelineController_ImageContentDataNotBase64 { get { - return ResourceManager.GetString("TimelineCommon_NameConflict", resourceCulture); + return ResourceManager.GetString("TimelineController_ImageContentDataNotBase64", resourceCulture); } } /// - /// Looks up a localized string similar to The timeline with given name does not exist.. + /// Looks up a localized string similar to Data field is not a valid image after base64 decoding in image content.. /// - internal static string TimelineCommon_NotExist { + internal static string TimelineController_ImageContentDataNotImage { get { - return ResourceManager.GetString("TimelineCommon_NotExist", resourceCulture); + return ResourceManager.GetString("TimelineController_ImageContentDataNotImage", resourceCulture); } } /// - /// Looks up a localized string similar to Unknown type of post content.. + /// Looks up a localized string similar to Data field is required for image content.. /// - internal static string TimelineController_ContentUnknownType { + internal static string TimelineController_ImageContentDataRequired { get { - return ResourceManager.GetString("TimelineController_ContentUnknownType", resourceCulture); + return ResourceManager.GetString("TimelineController_ImageContentDataRequired", resourceCulture); } } /// - /// Looks up a localized string similar to Data field is not a valid base64 string in image content.. + /// Looks up a localized string similar to The user to set as member does not exist.. /// - internal static string TimelineController_ImageContentDataNotBase64 { + internal static string TimelineController_MemberPut_NotExist { get { - return ResourceManager.GetString("TimelineController_ImageContentDataNotBase64", resourceCulture); + return ResourceManager.GetString("TimelineController_MemberPut_NotExist", resourceCulture); } } /// - /// Looks up a localized string similar to Data field is not a valid image after base64 decoding in image content.. + /// Looks up a localized string similar to A timeline with given name already exists.. /// - internal static string TimelineController_ImageContentDataNotImage { + internal static string TimelineController_NameConflict { get { - return ResourceManager.GetString("TimelineController_ImageContentDataNotImage", resourceCulture); + return ResourceManager.GetString("TimelineController_NameConflict", resourceCulture); } } /// - /// Looks up a localized string similar to Data field is required for image content.. + /// Looks up a localized string similar to The timeline with given name does not exist.. /// - internal static string TimelineController_ImageContentDataRequired { + internal static string TimelineController_NotExist { get { - return ResourceManager.GetString("TimelineController_ImageContentDataRequired", resourceCulture); + return ResourceManager.GetString("TimelineController_NotExist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The post of that type has no data.. + /// + internal static string TimelineController_PostNoData { + get { + return ResourceManager.GetString("TimelineController_PostNoData", resourceCulture); } } diff --git a/Timeline/Resources/Messages.resx b/Timeline/Resources/Messages.resx index 6a4cb1b6..631bd749 100644 --- a/Timeline/Resources/Messages.resx +++ b/Timeline/Resources/Messages.resx @@ -147,15 +147,6 @@ Model is of bad format. - - The user to set as member does not exist. - - - A timeline with given name already exists. - - - The timeline with given name does not exist. - Unknown type of post content. @@ -168,6 +159,18 @@ Data field is required for image content. + + The user to set as member does not exist. + + + A timeline with given name already exists. + + + The timeline with given name does not exist. + + + The post of that type has no data. + The user specified by query param "relate" does not exist. diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 97280728..301a1d97 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -287,11 +287,11 @@ namespace Timeline.Services } - public abstract class BaseTimelineManager : IBaseTimelineService + public abstract class BaseTimelineService : IBaseTimelineService { - protected BaseTimelineManager(ILoggerFactory loggerFactory, DatabaseContext database, IImageValidator imageValidator, IDataManager dataManager, IUserService userService, IClock clock) + protected BaseTimelineService(ILoggerFactory loggerFactory, DatabaseContext database, IImageValidator imageValidator, IDataManager dataManager, IUserService userService, IClock clock) { - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.CreateLogger(); Clock = clock; Database = database; ImageValidator = imageValidator; @@ -299,7 +299,7 @@ namespace Timeline.Services UserService = userService; } - private ILogger _logger; + private ILogger _logger; protected IClock Clock { get; } @@ -546,7 +546,7 @@ namespace Timeline.Services var post = await Database.TimelinePosts.Where(p => p.TimelineId == timelineId && p.LocalId == id).SingleOrDefaultAsync(); - if (post == null) + if (post == null || post.Content == null) throw new TimelinePostNotExistException(name, id); string? dataTag = null; @@ -739,7 +739,7 @@ namespace Timeline.Services } } - public class OrdinaryTimelineService : BaseTimelineManager, IOrdinaryTimelineService + public class OrdinaryTimelineService : BaseTimelineService, IOrdinaryTimelineService { private readonly TimelineNameValidator _timelineNameValidator = new TimelineNameValidator(); @@ -782,7 +782,7 @@ namespace Timeline.Services } } - public class PersonalTimelineService : BaseTimelineManager, IPersonalTimelineService + public class PersonalTimelineService : BaseTimelineService, IPersonalTimelineService { public PersonalTimelineService(ILoggerFactory loggerFactory, DatabaseContext database, IImageValidator imageValidator, IDataManager dataManager, IUserService userService, IClock clock) : base(loggerFactory, database, imageValidator, dataManager, userService, clock) -- cgit v1.2.3