From e01c203ac4cf27bfdc7df827c84e5b0b1398088d Mon Sep 17 00:00:00 2001 From: Abdullahi Olaniyan Date: Mon, 9 Sep 2024 17:28:03 +0300 Subject: [PATCH 1/3] Move Blogger API using statement to globalUsings --- src/Blogger.APIs/DependencyInjection.cs | 4 +-- .../CreateArticle/CreateArticleEndPoint.cs | 1 - .../CreateArticleMappingProfile.cs | 6 +---- .../CreateArticle/CreateArticleResponse.cs | 3 +-- .../Articles/GetArchive/GetArchiveEndpoint.cs | 4 +-- .../GetArchive/GetArchiveMappingProfile.cs | 4 +-- .../GetArticle/GetArticleMappingProfile.cs | 5 +--- .../GetArticles/GetArticlesEndpoint.cs | 4 +-- .../GetArticles/GetArticlesMappingProfile.cs | 4 +-- .../GetPopularArticlesEndpoint.cs | 4 +-- .../GetPopularArticlesMappingProfile.cs | 4 +-- .../GetPopularTags/GetPopularTagsEndpoint.cs | 4 +-- .../GetPopularTagsMappingProfile.cs | 4 +-- .../GetTaggedArticlesEndpoint.cs | 5 +--- .../GetTaggedArticlesMappingProfile.cs | 5 +--- .../Articles/GetTags/GetTagsEndpoint.cs | 4 +-- .../Articles/GetTags/GetTagsMappingProfile.cs | 4 +-- .../Articles/MakeDraft/MakeDraftEndpoint.cs | 5 +--- .../MakeDraft/MakeDraftMappingProfile.cs | 5 +--- .../PublishDraft/PublishDraftEndpoint.cs | 5 +--- .../PublishDraftMappingProfile.cs | 5 +--- .../UpdateDraft/UpdateDraftEndpoint.cs | 5 +--- .../UpdateDraft/UpdateDraftMappingProfile.cs | 5 +--- .../ApproveComment/ApproveCommentEndpoint.cs | 5 +--- .../ApproveCommentMappingProfile.cs | 4 +-- .../ApproveReply/ApproveReplyEndpoint.cs | 5 +--- .../ApproveReplyMappingProfile.cs | 5 +--- .../GetComments/GetCommentsEndpoint.cs | 5 +--- .../GetComments/GetCommentsMappingProfile.cs | 5 +--- .../Comments/GetReplies/GetRepliesEndpoint.cs | 4 +-- .../GetReplies/GetRepliesMappingProfile.cs | 6 +---- .../MakeComment/MakeCommentEndpoint.cs | 5 +--- .../MakeComment/MakeCommentMappingProfile.cs | 6 +---- .../ReplyToCommet/ReplyToCommentEndpoint.cs | 5 +--- .../ReplyToCommentMappingProfile.cs | 5 +--- .../Subscribe/SubscribeEndpoint.cs | 5 +--- .../Subscribe/SubscribeMappingProfile.cs | 3 +-- .../ErrorHandling/GlobalExceptionHandler.cs | 7 +----- src/Blogger.APIs/GlobalUsings.cs | 25 +++++++++++++++++++ src/Blogger.APIs/Program.cs | 2 -- 40 files changed, 62 insertions(+), 139 deletions(-) diff --git a/src/Blogger.APIs/DependencyInjection.cs b/src/Blogger.APIs/DependencyInjection.cs index 6bf03d3..8266d6a 100644 --- a/src/Blogger.APIs/DependencyInjection.cs +++ b/src/Blogger.APIs/DependencyInjection.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.DependencyInjection.Extensions; - -namespace Blogger.APIs; +namespace Blogger.APIs; public static class DependencyInjection { diff --git a/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleEndPoint.cs b/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleEndPoint.cs index f8bba9a..61f3c5b 100644 --- a/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleEndPoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleEndPoint.cs @@ -1,5 +1,4 @@ using Blogger.APIs.Endpoints; -using Blogger.Application.Articles.CreateArticle; namespace Blogger.APIs.Endpoints.Articles.CreateArticle; diff --git a/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleMappingProfile.cs index 1ffdf0a..eeb571c 100644 --- a/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleMappingProfile.cs @@ -1,8 +1,4 @@ -using Blogger.Application.Articles.CreateArticle; -using Blogger.Domain.ArticleAggregate; -using System.Collections.Immutable; - -namespace Blogger.APIs.Endpoints.Articles.CreateArticle; +namespace Blogger.APIs.Endpoints.Articles.CreateArticle; public class CreateArticleMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleResponse.cs b/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleResponse.cs index 46301d1..491b808 100644 --- a/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleResponse.cs +++ b/src/Blogger.APIs/Endpoints/Articles/CreateArticle/CreateArticleResponse.cs @@ -1,4 +1,3 @@ -using Blogger.Domain.ArticleAggregate; -namespace Blogger.APIs.Endpoints.Articles.CreateArticle; +namespace Blogger.APIs.Endpoints.Articles.CreateArticle; public record CreateArticleResponse(string ArticleId); diff --git a/src/Blogger.APIs/Endpoints/Articles/GetArchive/GetArchiveEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/GetArchive/GetArchiveEndpoint.cs index 76e0b12..ecd1840 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetArchive/GetArchiveEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetArchive/GetArchiveEndpoint.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetArchive; - -namespace Blogger.APIs.Endpoints.Articles.GetArchive; +namespace Blogger.APIs.Endpoints.Articles.GetArchive; public class GetArchiveEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetArchive/GetArchiveMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/GetArchive/GetArchiveMappingProfile.cs index bd5ae0f..70e6ee1 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetArchive/GetArchiveMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetArchive/GetArchiveMappingProfile.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetArchive; - -namespace Blogger.APIs.Endpoints.Articles.GetArchive; +namespace Blogger.APIs.Endpoints.Articles.GetArchive; public class GetArchiveMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetArticle/GetArticleMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/GetArticle/GetArticleMappingProfile.cs index 7bbef9e..bc7f199 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetArticle/GetArticleMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetArticle/GetArticleMappingProfile.cs @@ -1,7 +1,4 @@ -using Blogger.Application.Articles.GetArticle; -using Blogger.Domain.ArticleAggregate; - -namespace Blogger.APIs.Endpoints.Articles.GetArticle; +namespace Blogger.APIs.Endpoints.Articles.GetArticle; public class GetArticleMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetArticles/GetArticlesEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/GetArticles/GetArticlesEndpoint.cs index 1c99b6a..496624e 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetArticles/GetArticlesEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetArticles/GetArticlesEndpoint.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetArticles; - -namespace Blogger.APIs.Endpoints.Articles.GetArticles; +namespace Blogger.APIs.Endpoints.Articles.GetArticles; public class GetArticlesEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetArticles/GetArticlesMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/GetArticles/GetArticlesMappingProfile.cs index aa00888..b2976f1 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetArticles/GetArticlesMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetArticles/GetArticlesMappingProfile.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetArticles; - -namespace Blogger.APIs.Endpoints.Articles.GetArticles; +namespace Blogger.APIs.Endpoints.Articles.GetArticles; public class GetArticlesMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetPopularArticles/GetPopularArticlesEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/GetPopularArticles/GetPopularArticlesEndpoint.cs index 90cdfdb..c5c4f25 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetPopularArticles/GetPopularArticlesEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetPopularArticles/GetPopularArticlesEndpoint.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetPopularArticles; - -namespace Blogger.APIs.Endpoints.Articles.GetPopularArticles; +namespace Blogger.APIs.Endpoints.Articles.GetPopularArticles; public class GetPopularArticlesEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetPopularArticles/GetPopularArticlesMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/GetPopularArticles/GetPopularArticlesMappingProfile.cs index 632d3d4..4e78058 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetPopularArticles/GetPopularArticlesMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetPopularArticles/GetPopularArticlesMappingProfile.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetPopularArticles; - -namespace Blogger.APIs.Endpoints.Articles.GetPopularArticles; +namespace Blogger.APIs.Endpoints.Articles.GetPopularArticles; public class GetPopularArticlesMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetPopularTags/GetPopularTagsEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/GetPopularTags/GetPopularTagsEndpoint.cs index 73b9f90..150a579 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetPopularTags/GetPopularTagsEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetPopularTags/GetPopularTagsEndpoint.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetPopularTags; - -namespace Blogger.APIs.Endpoints.Articles.GetPopularTags; +namespace Blogger.APIs.Endpoints.Articles.GetPopularTags; public class GetPopularTagsEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetPopularTags/GetPopularTagsMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/GetPopularTags/GetPopularTagsMappingProfile.cs index a83592c..e70a8bd 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetPopularTags/GetPopularTagsMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetPopularTags/GetPopularTagsMappingProfile.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetPopularTags; - -namespace Blogger.APIs.Endpoints.Articles.GetPopularTags; +namespace Blogger.APIs.Endpoints.Articles.GetPopularTags; public class GetPopularTagsMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetTaggedArticles/GetTaggedArticlesEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/GetTaggedArticles/GetTaggedArticlesEndpoint.cs index ff70eb3..49cca3a 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetTaggedArticles/GetTaggedArticlesEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetTaggedArticles/GetTaggedArticlesEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Articles.GetTaggedArticles; - -namespace Blogger.APIs.Endpoints.Articles.GetTaggedArticles; +namespace Blogger.APIs.Endpoints.Articles.GetTaggedArticles; public class GetTaggedArticlesEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetTaggedArticles/GetTaggedArticlesMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/GetTaggedArticles/GetTaggedArticlesMappingProfile.cs index 7fe77f2..68b9eda 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetTaggedArticles/GetTaggedArticlesMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetTaggedArticles/GetTaggedArticlesMappingProfile.cs @@ -1,7 +1,4 @@ -using Blogger.Application.Articles.GetTaggedArticles; -using Blogger.Domain.ArticleAggregate; - -namespace Blogger.APIs.Endpoints.Articles.GetTaggedArticles; +namespace Blogger.APIs.Endpoints.Articles.GetTaggedArticles; public class GetTaggedArticlesMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetTags/GetTagsEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/GetTags/GetTagsEndpoint.cs index a051293..ceb5ff4 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetTags/GetTagsEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetTags/GetTagsEndpoint.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetTags; - -namespace Blogger.APIs.Endpoints.Articles.GetTags; +namespace Blogger.APIs.Endpoints.Articles.GetTags; public class GetTagsEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/GetTags/GetTagsMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/GetTags/GetTagsMappingProfile.cs index bd80caa..dd9df1c 100644 --- a/src/Blogger.APIs/Endpoints/Articles/GetTags/GetTagsMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/GetTags/GetTagsMappingProfile.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Articles.GetTags; - -namespace Blogger.APIs.Endpoints.Articles.GetTags; +namespace Blogger.APIs.Endpoints.Articles.GetTags; public class GetTagsMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/MakeDraft/MakeDraftEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/MakeDraft/MakeDraftEndpoint.cs index 06c2ef7..83a2fff 100644 --- a/src/Blogger.APIs/Endpoints/Articles/MakeDraft/MakeDraftEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/MakeDraft/MakeDraftEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Articles.MakeDraft; - -namespace Blogger.APIs.Endpoints.Articles.MakeDraft; +namespace Blogger.APIs.Endpoints.Articles.MakeDraft; public class MakeCommentEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/MakeDraft/MakeDraftMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/MakeDraft/MakeDraftMappingProfile.cs index 0b42cc6..2891b53 100644 --- a/src/Blogger.APIs/Endpoints/Articles/MakeDraft/MakeDraftMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/MakeDraft/MakeDraftMappingProfile.cs @@ -1,7 +1,4 @@ -using Blogger.Application.Articles.MakeDraft; -using Blogger.Domain.ArticleAggregate; - -namespace Blogger.APIs.Endpoints.Articles.MakeDraft; +namespace Blogger.APIs.Endpoints.Articles.MakeDraft; public class MakeDraftMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/PublishDraft/PublishDraftEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/PublishDraft/PublishDraftEndpoint.cs index b17a425..dc4890e 100644 --- a/src/Blogger.APIs/Endpoints/Articles/PublishDraft/PublishDraftEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/PublishDraft/PublishDraftEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Articles.PublishDraft; - -namespace Blogger.APIs.Endpoints.Articles.PublishDraft; +namespace Blogger.APIs.Endpoints.Articles.PublishDraft; public class PublishDraftEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/PublishDraft/PublishDraftMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/PublishDraft/PublishDraftMappingProfile.cs index 5ed79bf..06031d1 100644 --- a/src/Blogger.APIs/Endpoints/Articles/PublishDraft/PublishDraftMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/PublishDraft/PublishDraftMappingProfile.cs @@ -1,7 +1,4 @@ -using Blogger.Application.Articles.PublishDraft; -using Blogger.Domain.ArticleAggregate; - -namespace Blogger.APIs.Endpoints.Articles.PublishDraft; +namespace Blogger.APIs.Endpoints.Articles.PublishDraft; public class PublishDraftMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Articles/UpdateDraft/UpdateDraftEndpoint.cs b/src/Blogger.APIs/Endpoints/Articles/UpdateDraft/UpdateDraftEndpoint.cs index 86e4474..b84a4b8 100644 --- a/src/Blogger.APIs/Endpoints/Articles/UpdateDraft/UpdateDraftEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Articles/UpdateDraft/UpdateDraftEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Articles.UpdateDraft; - -namespace Blogger.APIs.Endpoints.Articles.UpdateDraft; +namespace Blogger.APIs.Endpoints.Articles.UpdateDraft; public class UpdateDraftEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Articles/UpdateDraft/UpdateDraftMappingProfile.cs b/src/Blogger.APIs/Endpoints/Articles/UpdateDraft/UpdateDraftMappingProfile.cs index fd67f6f..b2e007f 100644 --- a/src/Blogger.APIs/Endpoints/Articles/UpdateDraft/UpdateDraftMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Articles/UpdateDraft/UpdateDraftMappingProfile.cs @@ -1,7 +1,4 @@ -using Blogger.Application.Articles.UpdateDraft; -using Blogger.Domain.ArticleAggregate; - -namespace Blogger.APIs.Endpoints.Articles.UpdateDraft; +namespace Blogger.APIs.Endpoints.Articles.UpdateDraft; public class UpdateDraftMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Comments/ApproveComment/ApproveCommentEndpoint.cs b/src/Blogger.APIs/Endpoints/Comments/ApproveComment/ApproveCommentEndpoint.cs index 87613f7..e29443f 100644 --- a/src/Blogger.APIs/Endpoints/Comments/ApproveComment/ApproveCommentEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Comments/ApproveComment/ApproveCommentEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Comments.ApproveComment; - -namespace Blogger.APIs.Endpoints.Comments.ApproveComment; +namespace Blogger.APIs.Endpoints.Comments.ApproveComment; public class ApproveCommentEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Comments/ApproveComment/ApproveCommentMappingProfile.cs b/src/Blogger.APIs/Endpoints/Comments/ApproveComment/ApproveCommentMappingProfile.cs index 0ad4706..a727756 100644 --- a/src/Blogger.APIs/Endpoints/Comments/ApproveComment/ApproveCommentMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Comments/ApproveComment/ApproveCommentMappingProfile.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Comments.ApproveComment; - -namespace Blogger.APIs.Endpoints.Comments.ApproveComment; +namespace Blogger.APIs.Endpoints.Comments.ApproveComment; public class ApproveCommentMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Comments/ApproveReply/ApproveReplyEndpoint.cs b/src/Blogger.APIs/Endpoints/Comments/ApproveReply/ApproveReplyEndpoint.cs index d420797..0417ce1 100644 --- a/src/Blogger.APIs/Endpoints/Comments/ApproveReply/ApproveReplyEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Comments/ApproveReply/ApproveReplyEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Comments.ApproveReply; - -namespace Blogger.APIs.Endpoints.Comments.ApproveReply; +namespace Blogger.APIs.Endpoints.Comments.ApproveReply; public class ApproveReplyEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Comments/ApproveReply/ApproveReplyMappingProfile.cs b/src/Blogger.APIs/Endpoints/Comments/ApproveReply/ApproveReplyMappingProfile.cs index a4d07f3..89690a5 100644 --- a/src/Blogger.APIs/Endpoints/Comments/ApproveReply/ApproveReplyMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Comments/ApproveReply/ApproveReplyMappingProfile.cs @@ -1,7 +1,4 @@ -using Blogger.Application.Comments.ApproveReply; -using Blogger.Domain.CommentAggregate; - -namespace Blogger.APIs.Endpoints.Comments.ApproveReply; +namespace Blogger.APIs.Endpoints.Comments.ApproveReply; public class ApproveReplyMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Comments/GetComments/GetCommentsEndpoint.cs b/src/Blogger.APIs/Endpoints/Comments/GetComments/GetCommentsEndpoint.cs index 275a0e2..46a2886 100644 --- a/src/Blogger.APIs/Endpoints/Comments/GetComments/GetCommentsEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Comments/GetComments/GetCommentsEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Comments.GetComments; - -namespace Blogger.APIs.Endpoints.Comments.GetComments; +namespace Blogger.APIs.Endpoints.Comments.GetComments; public class GetCommentsEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Comments/GetComments/GetCommentsMappingProfile.cs b/src/Blogger.APIs/Endpoints/Comments/GetComments/GetCommentsMappingProfile.cs index 4ee983b..267030a 100644 --- a/src/Blogger.APIs/Endpoints/Comments/GetComments/GetCommentsMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Comments/GetComments/GetCommentsMappingProfile.cs @@ -1,7 +1,4 @@ -using Blogger.Application.Comments.GetComments; -using Blogger.Domain.ArticleAggregate; - -namespace Blogger.APIs.Endpoints.Comments.GetComments; +namespace Blogger.APIs.Endpoints.Comments.GetComments; public class GetCommentsMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Comments/GetReplies/GetRepliesEndpoint.cs b/src/Blogger.APIs/Endpoints/Comments/GetReplies/GetRepliesEndpoint.cs index f254464..648d6c0 100644 --- a/src/Blogger.APIs/Endpoints/Comments/GetReplies/GetRepliesEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Comments/GetReplies/GetRepliesEndpoint.cs @@ -1,6 +1,4 @@ -using Blogger.Application.Comments.GetReplies; - -namespace Blogger.APIs.Endpoints.Comments.GetReplies; +namespace Blogger.APIs.Endpoints.Comments.GetReplies; public class GetRepliesEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Comments/GetReplies/GetRepliesMappingProfile.cs b/src/Blogger.APIs/Endpoints/Comments/GetReplies/GetRepliesMappingProfile.cs index 72f6eb8..9d045fd 100644 --- a/src/Blogger.APIs/Endpoints/Comments/GetReplies/GetRepliesMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Comments/GetReplies/GetRepliesMappingProfile.cs @@ -1,8 +1,4 @@ -using Blogger.Application.Comments.GetReplies; -using Blogger.Domain.ArticleAggregate; -using Blogger.Domain.CommentAggregate; - -namespace Blogger.APIs.Endpoints.Comments.GetReplies; +namespace Blogger.APIs.Endpoints.Comments.GetReplies; public class GetRepliesMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Comments/MakeComment/MakeCommentEndpoint.cs b/src/Blogger.APIs/Endpoints/Comments/MakeComment/MakeCommentEndpoint.cs index e74fc11..2319b4c 100644 --- a/src/Blogger.APIs/Endpoints/Comments/MakeComment/MakeCommentEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Comments/MakeComment/MakeCommentEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Comments.MakeComment; - -namespace Blogger.APIs.Endpoints.Comments.MakeComment; +namespace Blogger.APIs.Endpoints.Comments.MakeComment; public class MakeCommentEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Comments/MakeComment/MakeCommentMappingProfile.cs b/src/Blogger.APIs/Endpoints/Comments/MakeComment/MakeCommentMappingProfile.cs index ffd1675..c4a58d6 100644 --- a/src/Blogger.APIs/Endpoints/Comments/MakeComment/MakeCommentMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Comments/MakeComment/MakeCommentMappingProfile.cs @@ -1,8 +1,4 @@ -using Blogger.Application.Comments.MakeComment; -using Blogger.Domain.ArticleAggregate; -using Blogger.Domain.CommentAggregate; - -namespace Blogger.APIs.Endpoints.Comments.MakeComment; +namespace Blogger.APIs.Endpoints.Comments.MakeComment; public class MakeCommentMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Comments/ReplyToCommet/ReplyToCommentEndpoint.cs b/src/Blogger.APIs/Endpoints/Comments/ReplyToCommet/ReplyToCommentEndpoint.cs index 49c45e2..d7d18d8 100644 --- a/src/Blogger.APIs/Endpoints/Comments/ReplyToCommet/ReplyToCommentEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Comments/ReplyToCommet/ReplyToCommentEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Comments.ReplyToComment; - -namespace Blogger.APIs.Endpoints.Comments.ReplyToCommet; +namespace Blogger.APIs.Endpoints.Comments.ReplyToCommet; public class ReplyToCommentEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Comments/ReplyToCommet/ReplyToCommentMappingProfile.cs b/src/Blogger.APIs/Endpoints/Comments/ReplyToCommet/ReplyToCommentMappingProfile.cs index 46c2fda..e929e5f 100644 --- a/src/Blogger.APIs/Endpoints/Comments/ReplyToCommet/ReplyToCommentMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Comments/ReplyToCommet/ReplyToCommentMappingProfile.cs @@ -1,7 +1,4 @@ -using Blogger.Application.Comments.ReplyToComment; -using Blogger.Domain.CommentAggregate; - -namespace Blogger.APIs.Endpoints.Comments.ReplyToCommet; +namespace Blogger.APIs.Endpoints.Comments.ReplyToCommet; public class ReplyToCommentMappingProfile : IRegister { diff --git a/src/Blogger.APIs/Endpoints/Subscribers/Subscribe/SubscribeEndpoint.cs b/src/Blogger.APIs/Endpoints/Subscribers/Subscribe/SubscribeEndpoint.cs index 7f68ad3..2cdcb4a 100644 --- a/src/Blogger.APIs/Endpoints/Subscribers/Subscribe/SubscribeEndpoint.cs +++ b/src/Blogger.APIs/Endpoints/Subscribers/Subscribe/SubscribeEndpoint.cs @@ -1,7 +1,4 @@ -using Blogger.APIs.Endpoints; -using Blogger.Application.Subscribers.Subscribe; - -namespace Blogger.APIs.Endpoints.Subscribers.Subscribe; +namespace Blogger.APIs.Endpoints.Subscribers.Subscribe; public class SubscribeEndpoint : IEndpoint { diff --git a/src/Blogger.APIs/Endpoints/Subscribers/Subscribe/SubscribeMappingProfile.cs b/src/Blogger.APIs/Endpoints/Subscribers/Subscribe/SubscribeMappingProfile.cs index bc95730..109090a 100644 --- a/src/Blogger.APIs/Endpoints/Subscribers/Subscribe/SubscribeMappingProfile.cs +++ b/src/Blogger.APIs/Endpoints/Subscribers/Subscribe/SubscribeMappingProfile.cs @@ -1,5 +1,4 @@ -using Blogger.Application.Subscribers.Subscribe; -using Blogger.Domain.SubscriberAggregate; +using Blogger.Domain.SubscriberAggregate; namespace Blogger.APIs.Endpoints.Subscribers.Subscribe; diff --git a/src/Blogger.APIs/ErrorHandling/GlobalExceptionHandler.cs b/src/Blogger.APIs/ErrorHandling/GlobalExceptionHandler.cs index 45099f0..d7675b4 100644 --- a/src/Blogger.APIs/ErrorHandling/GlobalExceptionHandler.cs +++ b/src/Blogger.APIs/ErrorHandling/GlobalExceptionHandler.cs @@ -1,9 +1,4 @@ -using Blogger.BuildingBlocks.Domain; - - -using Microsoft.AspNetCore.Diagnostics; - -namespace Blogger.APIs.ErrorHandling; +namespace Blogger.APIs.ErrorHandling; public sealed class GlobalExceptionHandler : IExceptionHandler { diff --git a/src/Blogger.APIs/GlobalUsings.cs b/src/Blogger.APIs/GlobalUsings.cs index 8943175..48a17f2 100644 --- a/src/Blogger.APIs/GlobalUsings.cs +++ b/src/Blogger.APIs/GlobalUsings.cs @@ -16,4 +16,29 @@ global using Blogger.APIs.Filters; global using Blogger.Infrastructure; global using Blogger.APIs.Abstractions; +global using Blogger.APIs.ErrorHandling; +global using Blogger.Application.Articles.CreateArticle; +global using Blogger.Application.Articles.GetArchive; +global using Blogger.Application.Articles.GetArticle; +global using Blogger.Application.Articles.GetArticles; +global using Blogger.Application.Articles.GetPopularArticles; +global using Blogger.Application.Articles.GetPopularTags; +global using Blogger.Application.Articles.GetTaggedArticles; +global using Blogger.Application.Articles.GetTags; +global using Blogger.Application.Articles.MakeDraft; +global using Blogger.Application.Articles.PublishDraft; +global using Blogger.Application.Articles.UpdateDraft; +global using Blogger.Application.Comments.ApproveComment; +global using Blogger.Application.Comments.ApproveReply; +global using Blogger.Application.Comments.GetComments; +global using Blogger.Application.Comments.GetReplies; +global using Blogger.Application.Comments.MakeComment; +global using Blogger.Application.Comments.ReplyToComment; +global using Blogger.Application.Subscribers.Subscribe; +global using Blogger.BuildingBlocks.Domain; +global using Blogger.Domain.ArticleAggregate; +global using Blogger.Domain.CommentAggregate; + +global using Microsoft.AspNetCore.Diagnostics; +global using Microsoft.Extensions.DependencyInjection.Extensions; diff --git a/src/Blogger.APIs/Program.cs b/src/Blogger.APIs/Program.cs index bf8a18d..73486d7 100644 --- a/src/Blogger.APIs/Program.cs +++ b/src/Blogger.APIs/Program.cs @@ -1,5 +1,3 @@ -using Blogger.APIs.ErrorHandling; - var builder = WebApplication.CreateBuilder(args); builder.Configuration.AddEnvironmentVariables(); From 81b55f77a3b463f3d9f5db6516ea9ff5b3d69bb8 Mon Sep 17 00:00:00 2001 From: Abdullahi Olaniyan Date: Tue, 10 Sep 2024 19:19:20 +0300 Subject: [PATCH 2/3] fix typo in naming --- src/Blogger.Application/ApplicationSettings.cs | 2 +- .../Comments/MakeComment/MakeCommentCommandHandler.cs | 2 +- .../Comments/ReplyToComment/ReplyToCommentCommandHandler.cs | 2 +- .../Comments/ApproveCommentCommandHandlerTests.cs | 2 +- .../Comments/ApproveReplyCommandHandlerTests.cs | 4 ++-- .../Comments/GetCommentsHandlerTests.cs | 2 +- .../Comments/GetRepliesHandlerTests.cs | 2 +- .../Comments/ReplyToCommentCommandHandlerTests.cs | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Blogger.Application/ApplicationSettings.cs b/src/Blogger.Application/ApplicationSettings.cs index 8763ff3..a86faa8 100644 --- a/src/Blogger.Application/ApplicationSettings.cs +++ b/src/Blogger.Application/ApplicationSettings.cs @@ -3,7 +3,7 @@ public static class ApplicationSettings { public static class ApproveLink { - public const int ExpairationOnHours = 10; + public const int ExpirationOnHours = 10; public const string ConfirmEmailSubject = "Confirm Your Engagement - thisisnabi.dev"; } } diff --git a/src/Blogger.Application/Comments/MakeComment/MakeCommentCommandHandler.cs b/src/Blogger.Application/Comments/MakeComment/MakeCommentCommandHandler.cs index 6652afb..1003a9b 100644 --- a/src/Blogger.Application/Comments/MakeComment/MakeCommentCommandHandler.cs +++ b/src/Blogger.Application/Comments/MakeComment/MakeCommentCommandHandler.cs @@ -22,7 +22,7 @@ public async Task Handle(MakeCommentCommand request, } var link = _linkGenerator.Generate(); - var approveLink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpairationOnHours)); + var approveLink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpirationOnHours)); var comment = Comment.Create(request.ArticleId, request.Client, request.Content, approveLink); comment.RaiseMakeCommentEvent(); diff --git a/src/Blogger.Application/Comments/ReplyToComment/ReplyToCommentCommandHandler.cs b/src/Blogger.Application/Comments/ReplyToComment/ReplyToCommentCommandHandler.cs index cd99230..94a0ee5 100644 --- a/src/Blogger.Application/Comments/ReplyToComment/ReplyToCommentCommandHandler.cs +++ b/src/Blogger.Application/Comments/ReplyToComment/ReplyToCommentCommandHandler.cs @@ -14,7 +14,7 @@ public async Task Handle(ReplyToCommentCommand re if (comment is null) throw new NotFoundCommentException(); var link = linkGenerator.Generate(); - var approveLink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpairationOnHours)); + var approveLink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpirationOnHours)); var Reply = comment.ReplyComment(request.Client, request.Content, approveLink); await commentRepository.SaveChangesAsync(cancellationToken); diff --git a/tests/Blogger.IntegrationTests/Comments/ApproveCommentCommandHandlerTests.cs b/tests/Blogger.IntegrationTests/Comments/ApproveCommentCommandHandlerTests.cs index 4f04432..642d4d7 100644 --- a/tests/Blogger.IntegrationTests/Comments/ApproveCommentCommandHandlerTests.cs +++ b/tests/Blogger.IntegrationTests/Comments/ApproveCommentCommandHandlerTests.cs @@ -47,7 +47,7 @@ public async Task Handle_CommentFound_ShouldApproveCommentAndSaveChanges() { // Arrange var link = new LinkGenerator().Generate(); - var approveLink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpairationOnHours)); + var approveLink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpirationOnHours)); var command = new ApproveCommentCommand(approveLink.ApproveId); var dbContext = _fixture.BuildDbContext(Guid.NewGuid().ToString()); diff --git a/tests/Blogger.IntegrationTests/Comments/ApproveReplyCommandHandlerTests.cs b/tests/Blogger.IntegrationTests/Comments/ApproveReplyCommandHandlerTests.cs index 7f46fd8..6ad958a 100644 --- a/tests/Blogger.IntegrationTests/Comments/ApproveReplyCommandHandlerTests.cs +++ b/tests/Blogger.IntegrationTests/Comments/ApproveReplyCommandHandlerTests.cs @@ -41,8 +41,8 @@ public async Task Handle_CommentFound_ShouldApproveReplyAndSaveChanges() { // Arrange var link = new LinkGenerator().Generate(); - var approveLinkComment = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpairationOnHours)); - var approveLink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpairationOnHours)); + var approveLinkComment = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpirationOnHours)); + var approveLink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpirationOnHours)); var dbContext = _fixture.BuildDbContext(Guid.NewGuid().ToString()); var commentRepository = new CommentRepository(dbContext); diff --git a/tests/Blogger.IntegrationTests/Comments/GetCommentsHandlerTests.cs b/tests/Blogger.IntegrationTests/Comments/GetCommentsHandlerTests.cs index 06db5ed..5cc23a4 100644 --- a/tests/Blogger.IntegrationTests/Comments/GetCommentsHandlerTests.cs +++ b/tests/Blogger.IntegrationTests/Comments/GetCommentsHandlerTests.cs @@ -49,7 +49,7 @@ public async Task Handle_CommentsFound_ShouldReturnComments() var articleId_2 = ArticleId.Create("this-is-nabi_2"); var link = new LinkGenerator().Generate(); - var approveLinkComment = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpairationOnHours)); + var approveLinkComment = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpirationOnHours)); var client1 = Client.Create("Nabi Karampour 1", "thisisnabi@outlook.com"); var client2 = Client.Create("Nabi Karampour 2", "thisisnabi@outlook.com"); diff --git a/tests/Blogger.IntegrationTests/Comments/GetRepliesHandlerTests.cs b/tests/Blogger.IntegrationTests/Comments/GetRepliesHandlerTests.cs index 913e74a..824f849 100644 --- a/tests/Blogger.IntegrationTests/Comments/GetRepliesHandlerTests.cs +++ b/tests/Blogger.IntegrationTests/Comments/GetRepliesHandlerTests.cs @@ -43,7 +43,7 @@ public async Task Handle_RepliesFound_ShouldReturnReplies() var articleId_1 = ArticleId.Create("this-is-nabi"); var link = new LinkGenerator().Generate(); - var approveLinkComment = Domain.CommentAggregate.ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpairationOnHours)); + var approveLinkComment = Domain.CommentAggregate.ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpirationOnHours)); var client1 = Client.Create("Nabi Karampour 1", "thisisnabi@outlook.com"); var client2 = Client.Create("Nabi Karampour 2", "thisisnabi@outlook.com"); diff --git a/tests/Blogger.IntegrationTests/Comments/ReplyToCommentCommandHandlerTests.cs b/tests/Blogger.IntegrationTests/Comments/ReplyToCommentCommandHandlerTests.cs index bc5375d..e8535cb 100644 --- a/tests/Blogger.IntegrationTests/Comments/ReplyToCommentCommandHandlerTests.cs +++ b/tests/Blogger.IntegrationTests/Comments/ReplyToCommentCommandHandlerTests.cs @@ -53,7 +53,7 @@ public async Task Handle_CommentFound_ShouldReplyToCommentAndSendEmail() { // Arrange var link = new LinkGenerator().Generate(); - var approvelink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpairationOnHours)); + var approvelink = ApproveLink.Create(link, DateTime.UtcNow.AddHours(ApplicationSettings.ApproveLink.ExpirationOnHours)); var articleId = ArticleId.Create("this-is-nabi"); var client = Client.Create("Nabi Karampour", "thisisnabi@outlook.com"); From 031745903339beb3512fefed4337b399f3681a6e Mon Sep 17 00:00:00 2001 From: Abdullahi Olaniyan Date: Tue, 10 Sep 2024 19:54:49 +0300 Subject: [PATCH 3/3] Implement Token Generation Algorithm using snowflakes algorithm --- src/Blogger.Infrastructure/GlobalUsings.cs | 2 + .../Services/LinkGenerator.cs | 60 ++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/Blogger.Infrastructure/GlobalUsings.cs b/src/Blogger.Infrastructure/GlobalUsings.cs index e7bfca9..89fc89d 100644 --- a/src/Blogger.Infrastructure/GlobalUsings.cs +++ b/src/Blogger.Infrastructure/GlobalUsings.cs @@ -1,6 +1,8 @@ // built-int global using Microsoft.EntityFrameworkCore; global using System.Collections.Immutable; +global using System.Text; + global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.DependencyInjection; diff --git a/src/Blogger.Infrastructure/Services/LinkGenerator.cs b/src/Blogger.Infrastructure/Services/LinkGenerator.cs index f7344f1..16126a9 100644 --- a/src/Blogger.Infrastructure/Services/LinkGenerator.cs +++ b/src/Blogger.Infrastructure/Services/LinkGenerator.cs @@ -3,9 +3,65 @@ namespace Blogger.Infrastructure.Services; public class LinkGenerator : ILinkGenerator { + + private const string Characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + private static readonly object LockObject = new object(); + private static long _lastTimestamp = -1L; + private static long _sequence = 0L; + private const long MaxSequence = 4095; // 12-bit sequence + + // implementing snowflakes algorithm to generate short and unique link public string Generate() { - // TODO: implement a generator algorithm - return Guid.NewGuid().ToString(); + lock (LockObject) + { + long timestamp = GetTimestamp(); + + if (timestamp == _lastTimestamp) + { + _sequence = (_sequence + 1) & MaxSequence; + if (_sequence == 0) + { + // Wait for the next millisecond if the sequence is full + timestamp = WaitForNextMillis(_lastTimestamp); + } + } + else + { + _sequence = 0; + } + + _lastTimestamp = timestamp; + + string uniqueId = Base62Encode(timestamp) + Base62Encode(_sequence); + return uniqueId; + } + } + + private static long GetTimestamp() + { + return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + } + + private static long WaitForNextMillis(long lastTimestamp) + { + long timestamp; + do + { + timestamp = GetTimestamp(); + } while (timestamp <= lastTimestamp); + return timestamp; + } + + private static string Base62Encode(long value) + { + var sb = new StringBuilder(); + int baseSize = Characters.Length; + do + { + sb.Insert(0, Characters[(int)(value % baseSize)]); + value /= baseSize; + } while (value > 0); + return sb.ToString(); } }