From 98e17766b203734a1817eed94338e2d25f4395f7 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 13 Feb 2021 16:20:18 +0200 Subject: Project Restructure P.1 --- .../DevHive.Services/Interfaces/IPostService.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/Services/DevHive.Services/Interfaces/IPostService.cs (limited to 'src/Services/DevHive.Services/Interfaces/IPostService.cs') diff --git a/src/Services/DevHive.Services/Interfaces/IPostService.cs b/src/Services/DevHive.Services/Interfaces/IPostService.cs new file mode 100644 index 0000000..d35acfd --- /dev/null +++ b/src/Services/DevHive.Services/Interfaces/IPostService.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; +using DevHive.Services.Models.Post; + +namespace DevHive.Services.Interfaces +{ + public interface IPostService + { + Task CreatePost(CreatePostServiceModel createPostServiceModel); + + Task GetPostById(Guid id); + + Task UpdatePost(UpdatePostServiceModel updatePostServiceModel); + + Task DeletePost(Guid id); + + Task ValidateJwtForCreating(Guid userId, string rawTokenData); + Task ValidateJwtForPost(Guid postId, string rawTokenData); + } +} -- cgit v1.2.3 From 018e9d303c38407589f06ec37a4a72dc4ce8e3b4 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 13 Feb 2021 18:36:25 +0200 Subject: Merged New Project Structure; Fixed Kamen's Formatting Issues --- src/Data/DevHive.Data.Models/ProfilePicture.cs | 2 +- .../DevHive.Data/Repositories/CommentRepository.cs | 5 ++-- .../DevHive.Data/Repositories/FeedRepository.cs | 8 +++---- .../Repositories/LanguageRepository.cs | 4 ++-- .../DevHive.Data/Repositories/PostRepository.cs | 10 ++++---- .../Repositories/TechnologyRepository.cs | 4 ++-- src/DevHive.code-workspace | 1 - .../DevHive.Services/Interfaces/IPostService.cs | 2 +- .../DevHive.Services/Services/FeedService.cs | 4 ++-- .../DevHive.Services/Services/PostService.cs | 22 ++++++++--------- .../DevHive.Services/Services/UserService.cs | 28 +++++++++++----------- src/Web/DevHive.Web.Tests/PostController.Tests.cs | 2 +- src/Web/DevHive.Web.Tests/RoleController.Tests.cs | 2 +- src/Web/DevHive.Web.Tests/UserController.Tests.cs | 2 +- 14 files changed, 47 insertions(+), 49 deletions(-) (limited to 'src/Services/DevHive.Services/Interfaces/IPostService.cs') diff --git a/src/Data/DevHive.Data.Models/ProfilePicture.cs b/src/Data/DevHive.Data.Models/ProfilePicture.cs index c5dec68..c502654 100644 --- a/src/Data/DevHive.Data.Models/ProfilePicture.cs +++ b/src/Data/DevHive.Data.Models/ProfilePicture.cs @@ -3,7 +3,7 @@ using DevHive.Data.Models.Interfaces; namespace DevHive.Data.Models { - public class ProfilePicture: IProfilePicture + public class ProfilePicture : IProfilePicture { public Guid Id { get; set; } diff --git a/src/Data/DevHive.Data/Repositories/CommentRepository.cs b/src/Data/DevHive.Data/Repositories/CommentRepository.cs index c63fe65..9364776 100644 --- a/src/Data/DevHive.Data/Repositories/CommentRepository.cs +++ b/src/Data/DevHive.Data/Repositories/CommentRepository.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using DevHive.Data.Interfaces; @@ -29,8 +28,8 @@ namespace DevHive.Data.Repositories } /// - /// This method returns the comment that is made at exactly the given time and by the given creator - /// + /// This method returns the comment that is made at exactly the given time and by the given creator + /// public async Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) { return await this._context.Comments diff --git a/src/Data/DevHive.Data/Repositories/FeedRepository.cs b/src/Data/DevHive.Data/Repositories/FeedRepository.cs index 8899675..d3312d7 100644 --- a/src/Data/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/Data/DevHive.Data/Repositories/FeedRepository.cs @@ -19,14 +19,14 @@ namespace DevHive.Data.Repositories } /// - /// This returns a given amount of posts of all given friends, created before "firstRequestIssued", + /// This returns a given amount of posts of all given friends, created before "firstRequestIssued", /// ordered from latest to oldest (time created). /// PageSize specifies how many posts to get, and pageNumber specifices how many posts to skip (pageNumber * pageSize). /// /// This method is used in the feed page. /// Posts from friends are meant to be gotten in chunks, meaning you get X posts, and then get another amount of posts, /// that are after the first X posts. - /// + /// public async Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize) { List friendsIds = friendsList.Select(f => f.Id).ToList(); @@ -49,14 +49,14 @@ namespace DevHive.Data.Repositories } /// - /// This returns a given amount of posts, that a user has made, created before "firstRequestIssued", + /// This returns a given amount of posts, that a user has made, created before "firstRequestIssued", /// ordered from latest to oldest (time created). /// PageSize specifies how many posts to get, and pageNumber specifices how many posts to skip (pageNumber * pageSize). /// /// This method is used in the profile page. /// Posts from friends are meant to be gotten in chunks, meaning you get X posts, and then get another amount of posts, /// that are after the first X posts. - /// + /// public async Task> GetUsersPosts(User user, DateTime firstRequestIssued, int pageNumber, int pageSize) { List posts = await this._context.Posts diff --git a/src/Data/DevHive.Data/Repositories/LanguageRepository.cs b/src/Data/DevHive.Data/Repositories/LanguageRepository.cs index 61f4792..3528ea8 100644 --- a/src/Data/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/Data/DevHive.Data/Repositories/LanguageRepository.cs @@ -26,8 +26,8 @@ namespace DevHive.Data.Repositories } /// - /// Returns all technologies that exist in the database - /// + /// Returns all technologies that exist in the database + /// public HashSet GetLanguages() { return this._context.Languages.ToHashSet(); diff --git a/src/Data/DevHive.Data/Repositories/PostRepository.cs b/src/Data/DevHive.Data/Repositories/PostRepository.cs index d35c475..b6c5e37 100644 --- a/src/Data/DevHive.Data/Repositories/PostRepository.cs +++ b/src/Data/DevHive.Data/Repositories/PostRepository.cs @@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class PostRepository : BaseRepository, IPostRepository + public class PostRepository : BaseRepository, IPostRepository { private readonly DevHiveContext _context; private readonly IUserRepository _userRepository; @@ -41,8 +41,8 @@ namespace DevHive.Data.Repositories } /// - /// This method returns the post that is made at exactly the given time and by the given creator - /// + /// This method returns the post that is made at exactly the given time and by the given creator + /// public async Task GetPostByCreatorAndTimeCreatedAsync(Guid creatorId, DateTime timeCreated) { return await this._context.Posts @@ -68,12 +68,12 @@ namespace DevHive.Data.Repositories .SetValues(newEntity); List postAttachments = new(); - foreach(var attachment in newEntity.Attachments) + foreach (var attachment in newEntity.Attachments) postAttachments.Add(attachment); post.Attachments = postAttachments; post.Comments.Clear(); - foreach(var comment in newEntity.Comments) + foreach (var comment in newEntity.Comments) post.Comments.Add(comment); // post.Rating.Id = ratingId; diff --git a/src/Data/DevHive.Data/Repositories/TechnologyRepository.cs b/src/Data/DevHive.Data/Repositories/TechnologyRepository.cs index 8cb7da1..d0d1f3f 100644 --- a/src/Data/DevHive.Data/Repositories/TechnologyRepository.cs +++ b/src/Data/DevHive.Data/Repositories/TechnologyRepository.cs @@ -26,8 +26,8 @@ namespace DevHive.Data.Repositories } /// - /// Returns all technologies that exist in the database - /// + /// Returns all technologies that exist in the database + /// public HashSet GetTechnologies() { return this._context.Technologies.ToHashSet(); diff --git a/src/DevHive.code-workspace b/src/DevHive.code-workspace index 36e1700..8511609 100644 --- a/src/DevHive.code-workspace +++ b/src/DevHive.code-workspace @@ -31,7 +31,6 @@ "omnisharp.enableEditorConfigSupport": true, "omnisharp.enableRoslynAnalyzers": true, "prettier.useEditorConfig": true, - "workbench.editor.labelFormat": "short" }, "launch": { "configurations": [ diff --git a/src/Services/DevHive.Services/Interfaces/IPostService.cs b/src/Services/DevHive.Services/Interfaces/IPostService.cs index d35acfd..5ccecff 100644 --- a/src/Services/DevHive.Services/Interfaces/IPostService.cs +++ b/src/Services/DevHive.Services/Interfaces/IPostService.cs @@ -4,7 +4,7 @@ using DevHive.Services.Models.Post; namespace DevHive.Services.Interfaces { - public interface IPostService + public interface IPostService { Task CreatePost(CreatePostServiceModel createPostServiceModel); diff --git a/src/Services/DevHive.Services/Services/FeedService.cs b/src/Services/DevHive.Services/Services/FeedService.cs index a0f1f1b..5feef6e 100644 --- a/src/Services/DevHive.Services/Services/FeedService.cs +++ b/src/Services/DevHive.Services/Services/FeedService.cs @@ -27,7 +27,7 @@ namespace DevHive.Services.Services /// /// This method is used in the feed page. /// See the FeedRepository "GetFriendsPosts" menthod for more information on how it works. - /// + /// public async Task GetPage(GetPageServiceModel model) { User user = null; @@ -58,7 +58,7 @@ namespace DevHive.Services.Services /// /// This method is used in the profile pages. /// See the FeedRepository "GetUsersPosts" menthod for more information on how it works. - /// + /// public async Task GetUserPage(GetPageServiceModel model) { User user = null; diff --git a/src/Services/DevHive.Services/Services/PostService.cs b/src/Services/DevHive.Services/Services/PostService.cs index c368ce6..0becd9f 100644 --- a/src/Services/DevHive.Services/Services/PostService.cs +++ b/src/Services/DevHive.Services/Services/PostService.cs @@ -13,7 +13,7 @@ using DevHive.Data.Models.Relational; namespace DevHive.Services.Services { - public class PostService : IPostService + public class PostService : IPostService { private readonly ICloudService _cloudService; private readonly IUserRepository _userRepository; @@ -144,8 +144,8 @@ namespace DevHive.Services.Services #region Validations /// - /// Checks whether the user Id in the token and the given user Id match - /// + /// Checks whether the user Id in the token and the given user Id match + /// public async Task ValidateJwtForCreating(Guid userId, string rawTokenData) { User user = await this.GetUserForValidation(rawTokenData); @@ -154,10 +154,10 @@ namespace DevHive.Services.Services } /// - /// Checks whether the post, gotten with the postId, + /// Checks whether the post, gotten with the postId, /// is made by the user in the token /// or if the user in the token is an admin - /// + /// public async Task ValidateJwtForPost(Guid postId, string rawTokenData) { Post post = await this._postRepository.GetByIdAsync(postId) ?? @@ -175,10 +175,10 @@ namespace DevHive.Services.Services } /// - /// Checks whether the comment, gotten with the commentId, + /// Checks whether the comment, gotten with the commentId, /// is made by the user in the token /// or if the user in the token is an admin - /// + /// public async Task ValidateJwtForComment(Guid commentId, string rawTokenData) { Comment comment = await this._commentRepository.GetByIdAsync(commentId) ?? @@ -196,8 +196,8 @@ namespace DevHive.Services.Services } /// - /// Returns the user, via their Id in the token - /// + /// Returns the user, via their Id in the token + /// private async Task GetUserForValidation(string rawTokenData) { JwtSecurityToken jwt = new JwtSecurityTokenHandler().ReadJwtToken(rawTokenData.Remove(0, 7)); @@ -212,8 +212,8 @@ namespace DevHive.Services.Services } /// - /// Returns all values from a given claim type - /// + /// Returns all values from a given claim type + /// private List GetClaimTypeValues(string type, IEnumerable claims) { List toReturn = new(); diff --git a/src/Services/DevHive.Services/Services/UserService.cs b/src/Services/DevHive.Services/Services/UserService.cs index f2c5a5b..9a63853 100644 --- a/src/Services/DevHive.Services/Services/UserService.cs +++ b/src/Services/DevHive.Services/Services/UserService.cs @@ -54,9 +54,9 @@ namespace DevHive.Services.Services #region Authentication /// - /// Adds a new user to the database with the values from the given model. + /// Adds a new user to the database with the values from the given model. /// Returns a JSON Web Token (that can be used for authorization) - /// + /// public async Task LoginUser(LoginServiceModel loginModel) { if (!await this._userRepository.DoesUsernameExistAsync(loginModel.UserName)) @@ -71,8 +71,8 @@ namespace DevHive.Services.Services } /// - /// Returns a new JSON Web Token (that can be used for authorization) for the given user - /// + /// Returns a new JSON Web Token (that can be used for authorization) for the given user + /// public async Task RegisterUser(RegisterServiceModel registerModel) { if (await this._userRepository.DoesUsernameExistAsync(registerModel.UserName)) @@ -143,8 +143,8 @@ namespace DevHive.Services.Services } /// - /// Uploads the given picture and assigns it's link to the user in the database - /// + /// Uploads the given picture and assigns it's link to the user in the database + /// public async Task UpdateProfilePicture(UpdateProfilePictureServiceModel updateProfilePictureServiceModel) { User user = await this._userRepository.GetByIdAsync(updateProfilePictureServiceModel.UserId); @@ -183,10 +183,10 @@ namespace DevHive.Services.Services #region Validations /// - /// Checks whether the given user, gotten by the "id" property, + /// Checks whether the given user, gotten by the "id" property, /// is the same user as the one in the token (uness the user in the token has the admin role) /// and the roles in the token are the same as those in the user, gotten by the id in the token - /// + /// public async Task ValidJWT(Guid id, string rawTokenData) { // There is authorization name in the beginning, i.e. "Bearer eyJh..." @@ -220,8 +220,8 @@ namespace DevHive.Services.Services } /// - /// Returns all values from a given claim type - /// + /// Returns all values from a given claim type + /// private List GetClaimTypeValues(string type, IEnumerable claims) { List toReturn = new(); @@ -234,10 +234,10 @@ namespace DevHive.Services.Services } /// - /// Checks whether the user in the model exists + /// Checks whether the user in the model exists /// and whether the username in the model is already taken. /// If the check fails (is false), it throws an exception, otherwise nothing happens - /// + /// private async Task ValidateUserOnUpdate(UpdateUserServiceModel updateUserServiceModel) { if (!await this._userRepository.DoesUserExistAsync(updateUserServiceModel.Id)) @@ -259,9 +259,9 @@ namespace DevHive.Services.Services } /// - /// Return a new JSON Web Token, containing the user id, username and roles. + /// Return a new JSON Web Token, containing the user id, username and roles. /// Tokens have an expiration time of 7 days. - /// + /// private string WriteJWTSecurityToken(Guid userId, string username, HashSet roles) { byte[] signingKey = Encoding.ASCII.GetBytes(_jwtOptions.Secret); diff --git a/src/Web/DevHive.Web.Tests/PostController.Tests.cs b/src/Web/DevHive.Web.Tests/PostController.Tests.cs index 3a4e45e..96b0356 100644 --- a/src/Web/DevHive.Web.Tests/PostController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/PostController.Tests.cs @@ -12,7 +12,7 @@ using NUnit.Framework; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] public class PostControllerTests { const string MESSAGE = "Gosho Trapov"; diff --git a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs index 8e33bee..64e3f11 100644 --- a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs @@ -12,7 +12,7 @@ using NUnit.Framework; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] public class RoleControllerTests { const string NAME = "Gosho Trapov"; diff --git a/src/Web/DevHive.Web.Tests/UserController.Tests.cs b/src/Web/DevHive.Web.Tests/UserController.Tests.cs index efdfdbb..7457ad7 100644 --- a/src/Web/DevHive.Web.Tests/UserController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/UserController.Tests.cs @@ -12,7 +12,7 @@ using NUnit.Framework; namespace DevHive.Web.Tests { - [TestFixture] + [TestFixture] public class UserControllerTests { const string USERNAME = "Gosho Trapov"; -- cgit v1.2.3