From ff8206df1b76b41e11c6f57a6e392563c480e390 Mon Sep 17 00:00:00 2001 From: Matej Vavrek <matvav13@gmail.com> Date: Fri, 15 Nov 2024 22:54:53 +0100 Subject: [PATCH] Added documentation to business layer services --- .../IEventParticipantService.cs | 3 -- .../Services/ImageService/IImageService.cs | 36 +++++++++++++++ .../LocationService/ILocationService.cs | 28 +++++++++++- .../IRestaurantMaintainerService.cs | 16 +++++++ .../RestaurantService/IRestaurantService.cs | 40 +++++++++++++++++ .../IReviewAggregateResultService.cs | 19 ++++++++ .../IReviewCommentService.cs | 43 ++++++++++++++++++ .../Services/ReviewService/IReviewService.cs | 44 ++++++++++++++++++- .../Services/ReviewService/ReviewService.cs | 5 ++- .../Services/UserService/IUserService.cs | 41 ++++++++++++++++- 10 files changed, 266 insertions(+), 9 deletions(-) diff --git a/BusinessLayer/Services/EventParticipantService/IEventParticipantService.cs b/BusinessLayer/Services/EventParticipantService/IEventParticipantService.cs index 48ca653..48d49cf 100644 --- a/BusinessLayer/Services/EventParticipantService/IEventParticipantService.cs +++ b/BusinessLayer/Services/EventParticipantService/IEventParticipantService.cs @@ -1,8 +1,5 @@ using BusinessLayer.DTOs.EventParticipant; using BusinessLayer.Utils.Filters; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; namespace BusinessLayer.Services.EventParticipantService { diff --git a/BusinessLayer/Services/ImageService/IImageService.cs b/BusinessLayer/Services/ImageService/IImageService.cs index 4716e5e..da196fc 100644 --- a/BusinessLayer/Services/ImageService/IImageService.cs +++ b/BusinessLayer/Services/ImageService/IImageService.cs @@ -3,15 +3,51 @@ using BusinessLayer.Utils.Enums; namespace BusinessLayer.Services.ImageService { + /// <summary> + /// Provides methods for managing images in the application. + /// </summary> public interface IImageService { + /// <summary> + /// Retrieves paths to all available images for a given entity. + /// </summary> + /// <param name="entityId">The ID of the entity that owns the images.</param> + /// <param name="entityType">The type or name of the entity that owns the images.</param> + /// <param name="imageType">The type of the images.</param> + /// <returns>An array of paths to the available images.</returns> public string[] GetImagePaths(Guid entityId, OwnerEntityType entityType, ImageType imageType); + + /// <summary> + /// Reads images and retrieves them as loaded data with associated metadata. + /// </summary> + /// <param name="entityId">The ID of the entity that owns the images.</param> + /// <param name="entityType">The type or name of the entity that owns the images.</param> + /// <param name="imageType">The type of the images.</param> + /// <returns>A List of loaded images.</returns> public Task<List<ImageDTO>> GetImagesAsync(Guid entityId, OwnerEntityType entityType, ImageType imageType); + /// <summary> + /// Saves a single image to the image storage medium. + /// </summary> + /// <param name="imageUploadDTO">The data and metadata of the uploaded image.</param> + /// <param name="checkEntityExistence">A flag determining whether the existence of a given entity should be checked.</param> + /// <returns>True if image saved, otherwise false.</returns> public Task<bool> SaveImageAsync(ImageUploadDTO imageUploadDTO, bool checkEntityExistence = true); + /// <summary> + /// Saves multiple images to the image storage medium. + /// </summary> + /// <param name="imageUploadDTOs">A list of multiple structures containing data and metadata of uploaded images.</param> + /// <returns>True if all images saved succesfully, otherwise false. No changes should be performed in the storage if any image upload fails.</returns> public Task<bool> SaveImagesAsync(ImageUploadDTO[] imageUploadDTOs); + /// <summary> + /// Deletes an image specified by the provided data. + /// </summary> + /// <param name="entityId">The ID of the entity that owns the images.</param> + /// <param name="entityType">The type or name of the entity that owns the images.</param> + /// <param name="imageName">The name of the image to be deleted, including its extension.</param> + /// <returns>True if deleted succesfully, otherwise false.</returns> public Task<bool> RemoveImageAsync(Guid entityId, OwnerEntityType entityType, string imageName); } } diff --git a/BusinessLayer/Services/LocationService/ILocationService.cs b/BusinessLayer/Services/LocationService/ILocationService.cs index a15ab6f..bad7e41 100644 --- a/BusinessLayer/Services/LocationService/ILocationService.cs +++ b/BusinessLayer/Services/LocationService/ILocationService.cs @@ -4,18 +4,44 @@ using BusinessLayer.Utils.Ordering; namespace BusinessLayer.Services.LocationService { + /// <summary> + /// Provides methods for manipulating Locations in the database. + /// </summary> public interface ILocationService : IBaseService { + /// <summary> + /// Retrieves multiple locations according to the criteria selected by the provided parameters. + /// </summary> + /// <param name="filter">Used to build a filter for the queried data.</param> + /// <param name="orderBy">Used for simple ordering of the queried data.</param> + /// <param name="limit">The maximum amount of items retrieved. If 0, all possible items will be retrieved.</param> + /// <param name="offset">The amount of items skipped from the beginning of the ordering. 0 means no items will be skipped.</param> + /// <param name="ids">The exact IDs to be found among the locations. These are restaurant Ids, as locations are bound to restaurants.</param> + /// <returns>A list of found locations.</returns> public Task<List<LocationDto>> GetLocationsAsync( LocationFilter filter, LocationOrdering orderBy, int limit = 0, int offset = 0, Guid[]? ids = null); + + /// <summary> + /// Retrieve a single location based on the ID of the restaurant it is tied to. + /// </summary> + /// <param name="id">The GUID of a restaurant the location is related to.</param> + /// <returns>The location of the restaurant, null otherwise.</returns> public Task<LocationDto?> GetLocationAsync(Guid id); + + /// <summary> + /// Updates location based on the data provided. + /// </summary> + /// <param name="id">The ID of the related restaurant</param> + /// <param name="data">The data to be changed, null means that the corresponding property will not be changed.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>The updated location.</returns> public Task<LocationDto?> UpdateLocationAsync( Guid id, - LocationUpdateDto restaurant, + LocationUpdateDto data, bool save = true); } } diff --git a/BusinessLayer/Services/RestaurantMaintainerService/IRestaurantMaintainerService.cs b/BusinessLayer/Services/RestaurantMaintainerService/IRestaurantMaintainerService.cs index ac347ac..d7e7691 100644 --- a/BusinessLayer/Services/RestaurantMaintainerService/IRestaurantMaintainerService.cs +++ b/BusinessLayer/Services/RestaurantMaintainerService/IRestaurantMaintainerService.cs @@ -1,10 +1,26 @@ namespace BusinessLayer.Services.RestaurantMaintainerService { + /// <summary> + /// Provides methods for mantaining the state of the restaurant maintainer relationships. + /// </summary> public interface IRestaurantMaintainerService : IBaseService { + /// <summary> + /// Create a maintainer relationship between a user and a restaurant. + /// </summary> + /// <param name="restaurantId">The ID of the maintained restaurant.</param> + /// <param name="userId">The ID of the maintainer user.</param> + /// <returns>True if the relationship was established. False if either the user or restaurant were not found, or the relationship already existed.</returns> public Task<bool> AddRestaurantMaintainerAsync( Guid restaurantId, Guid userId); + + /// <summary> + /// Destroys a maintainer relationship between a user and a restaurant. + /// </summary> + /// <param name="restaurantId">The ID of the maintained restaurant.</param> + /// <param name="userId">The ID of the maintainer user.</param> + /// <returns>True if the relationship was removed. False if either the user or restaurant were not found, or the relationship already does not exist.</returns> public Task<bool> DeleteRestaurantMaintainerAsync( Guid restaurantId, Guid userId); diff --git a/BusinessLayer/Services/RestaurantService/IRestaurantService.cs b/BusinessLayer/Services/RestaurantService/IRestaurantService.cs index c37174c..56776c9 100644 --- a/BusinessLayer/Services/RestaurantService/IRestaurantService.cs +++ b/BusinessLayer/Services/RestaurantService/IRestaurantService.cs @@ -4,22 +4,62 @@ using BusinessLayer.Utils.Ordering; namespace BusinessLayer.Services.RestaurantService { + /// <summary> + /// Provides methods for maintaing restaurants. + /// </summary> public interface IRestaurantService : IBaseService { + /// <summary> + /// Retrieves restaurants according to the criteria specified in the parameters. + /// </summary> + /// <param name="filter">Used to build a filter for the queried data.</param> + /// <param name="orderBy">Used for simple ordering of the queried data.</param> + /// <param name="limit">The maximum amount of items retrieved. If 0, all possible items will be retrieved.</param> + /// <param name="offset">The amount of items skipped from the beginning of the ordering. 0 means no items will be skipped.</param> + /// <param name="ids">The exact IDs to be found among the restaurants.</param> + /// <returns>A list of found restaurants.</returns> public Task<List<RestaurantDto>> GetRestaurantsAsync( RestaurantFilter filter, RestaurantOrdering orderBy, int limit = 0, int offset = 0, Guid[]? ids = null); + + /// <summary> + /// Retrieve a single restaurant based on the ID. + /// </summary> + /// <param name="id">The GUID of the desired restaurant.</param> + /// <returns>The found restaurant, otherwise null</returns> public Task<RestaurantDetailDto?> GetRestaurantAsync(Guid id); + + /// <summary> + /// Creates a new restaurant entry based on the provided data. + /// </summary> + /// <param name="restaurant">The data for a new restaurant.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>The newly created restaurant.</returns> public Task<RestaurantDetailDto?> CreateRestaurantAsync( RestaurantCreateDto restaurant, bool save = true); + + /// <summary> + /// Updates a restaurant based on the data provided. + /// </summary> + /// <param name="id">The ID of the restaurant to be updated.</param> + /// <param name="restaurant">The data to be changed, null means that the corresponding property will not be changed.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>The updated restaurant.</returns> public Task<RestaurantDetailDto?> UpdateRestaurantAsync( Guid id, RestaurantUpdateDto restaurant, bool save = true); + + /// <summary> + /// Deletes the restaurant with a matching ID. + /// </summary> + /// <param name="id">The ID of the restaurant to be deleted.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>True if a restaurant was deleted, false if the restaurant was not found.</returns> public Task<bool> DeleteRestaurantAsync( Guid id, bool save = true); diff --git a/BusinessLayer/Services/ReviewAggregateResultService/IReviewAggregateResultService.cs b/BusinessLayer/Services/ReviewAggregateResultService/IReviewAggregateResultService.cs index 564803c..3c11881 100644 --- a/BusinessLayer/Services/ReviewAggregateResultService/IReviewAggregateResultService.cs +++ b/BusinessLayer/Services/ReviewAggregateResultService/IReviewAggregateResultService.cs @@ -4,14 +4,33 @@ namespace BusinessLayer.Services.ReviewAggregateService { public interface IReviewAggregateResultService : IBaseService { + /// <summary> + /// Determines whether review aggregate results with the given restaurant IDs exist. + /// </summary> + /// <param name="ids">The IDs of the related restaurants.</param> + /// <returns>True if these review aggregate results exist, otherwise false.</returns> public Task<bool> DoesAggregateExistAsync(params Guid[] ids); + /// <summary> + /// Retrieves multiple review aggregate results according to the criteria selected by the provided parameters. + /// </summary> + /// <param name="orderBy">Used for simple ordering of the queried data.</param> + /// <param name="limit">The maximum amount of items retrieved. If 0, all possible items will be retrieved.</param> + /// <param name="offset">The amount of items skipped from the beginning of the ordering. 0 means no items will be skipped.</param> + /// <param name="includeRestaurant">Determines whether the review aggregate results should include the relevant restaurant.</param> + /// <returns>A list of found review aggregate results.</returns> public Task<List<ReviewAggregateDTO>> GetAggregatesAsync( string orderBy = "", int limit = 0, int offset = 0, bool includeRestaurant = false); + /// <summary> + /// Retrieves a specific review aggregate result based on the ID of the related restaurant. + /// </summary> + /// <param name="id">The ID of the related restaurant.</param> + /// <param name="includeRestaurant">Determines whether the review aggregate results should include the relevant restaurant.</param> + /// <returns>The found review aggregate result, null otherwise.</returns> public Task<ReviewAggregateDTO?> GetAggregateByIdAsync(Guid id, bool includeRestaurant = false); public Task<bool> RecalculateAggregateAsync(Guid id, bool save = true); diff --git a/BusinessLayer/Services/ReviewCommentService/IReviewCommentService.cs b/BusinessLayer/Services/ReviewCommentService/IReviewCommentService.cs index e0f80c3..0be5e65 100644 --- a/BusinessLayer/Services/ReviewCommentService/IReviewCommentService.cs +++ b/BusinessLayer/Services/ReviewCommentService/IReviewCommentService.cs @@ -5,14 +5,38 @@ namespace BusinessLayer.Services.ReviewCommentService { public interface IReviewCommentService : IBaseService { + /// <summary> + /// Determines whether comments with the given IDs exist. + /// </summary> + /// <param name="ids">The IDs of the comments.</param> + /// <returns>True if these comments exist, otherwise false.</returns> public Task<bool> DoesCommentExistAsync(params Guid[] ids); + /// <summary> + /// Retrieves a single review comment by its ID. + /// </summary> + /// <param name="id">The ID of the comment.</param> + /// <param name="includeUser">Determines whether the poster should be included.</param> + /// <param name="includeReview">Determines whether the review the comment was made for should be included.</param> + /// <param name="includeChildren">Determines whether child comments should be included.</param> + /// <returns>The comment searched for, otherwise null.</returns> public Task<ReviewCommentDTO?> GetByIdAsync( Guid id, bool includeUser = true, bool includeReview = false, bool includeChildren = false); + /// <summary> + /// Retrieves comments according to the criteria set in the parameters. + /// </summary> + /// <param name="filter">Used to build a filter for the queried data.</param> + /// <param name="limit">The maximum amount of items retrieved. If 0, all possible items will be retrieved.</param> + /// <param name="offset">The amount of items skipped from the beginning of the ordering. 0 means no items will be skipped.</param> + /// <param name="ids">The exact IDs to be found among the comments.</param> + /// <param name="includeUser">Determines whether the poster should be included.</param> + /// <param name="includeReview">Determines whether the review the comment was made for should be included.</param> + /// <param name="includeChildren">Determines whether child comments should be included.</param> + /// <returns>The comments that satisfy search criteria.</returns> public Task<List<ReviewCommentDTO>> GetCommentsAsync( ReviewCommentFilter filter, int limit = 0, @@ -22,10 +46,29 @@ namespace BusinessLayer.Services.ReviewCommentService bool includeReview = false, bool includeChildren = false); + /// <summary> + /// Creates a review comment based on the provided data. + /// </summary> + /// <param name="data">The data for the review comment to be created.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>The newly created review comment.</returns> public Task<ReviewCommentDTO?> CreateCommentAsync(ReviewCommentCreateDTO data, bool save = true); + /// <summary> + /// Updates a review comment based on the provided data. + /// </summary> + /// <param name="id">The ID of the comment to be updated.</param> + /// <param name="data">The data to be changed, null means that the corresponding property will not be changed.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns></returns> public Task<ReviewCommentDTO?> UpdateCommentAsync(Guid id, ReviewCommentUpdateDTO data, bool save = true); + /// <summary> + /// Removes a comment based on its ID. + /// </summary> + /// <param name="id">The ID of the comment to be deleted.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns></returns> public Task<bool> DeleteCommentAsync(Guid id, bool save = true); } } diff --git a/BusinessLayer/Services/ReviewService/IReviewService.cs b/BusinessLayer/Services/ReviewService/IReviewService.cs index faae2ba..daa3698 100644 --- a/BusinessLayer/Services/ReviewService/IReviewService.cs +++ b/BusinessLayer/Services/ReviewService/IReviewService.cs @@ -6,8 +6,23 @@ namespace BusinessLayer.Services.ReviewService { public interface IReviewService : IBaseService { + /// <summary> + /// Determines whether reviews with the given IDs exist. + /// </summary> + /// <param name="ids">The IDs of the reviews.</param> + /// <returns>True if these reviews exist, otherwise false.</returns> public Task<bool> DoesReviewExistAsync(params Guid[] ids); + /// <summary> + /// Retrieves multiple reviews according to the criteria selected by the provided parameters. + /// </summary> + /// <param name="filter">Used to build a filter for the queried data.</param> + /// <param name="orderBy">Used for simple ordering of the queried data.</param> + /// <param name="limit">The maximum amount of items retrieved. If 0, all possible items will be retrieved.</param> + /// <param name="offset">The amount of items skipped from the beginning of the ordering. 0 means no items will be skipped.</param> + /// <param name="ids">The exact IDs to be found among the locations. These are restaurant Ids, as locations are bound to restaurants.</param> + /// <param name="includeUser">Determines whether the reviews should include the poster.</param> + /// <returns>A list of found locations.</returns> public Task<List<ReviewDTO>> GetReviewsAsync( ReviewFilter filter, ReviewOrdering orderBy, @@ -16,16 +31,43 @@ namespace BusinessLayer.Services.ReviewService Guid[]? ids = null, bool includeUser = true); + /// <summary> + /// Retrieves a single review by its ID. + /// </summary> + /// <param name="id">The ID of the review.</param> + /// <param name="includeUser">Determines whether the poster should be included.</param> + /// <param name="includeRestaurant">Determines whether the restaurant the review was made for should be included.</param> + /// <param name="includeComments">Determines whether comments for the review should be included.</param> + /// <returns>The review searched for, otherwise null.</returns> public Task<ReviewDetailDTO?> GetReviewAsync( Guid id, bool includeUser = true, bool includeRestaurant = true, - bool IncludeComments = true); + bool includeComments = true); + /// <summary> + /// Creates a new review based on the data provided. + /// </summary> + /// <param name="data">The data for the new review.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>The new review created, null otherwise.</returns> public Task<ReviewDetailDTO?> CreateReviewAsync(ReviewCreateDTO data, bool save = true); + /// <summary> + /// Updates an existing review based on the data provided. + /// </summary> + /// <param name="id">The ID of the review to be updated.</param> + /// <param name="data">The data to be changed, null means that the corresponding property will not be changed.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>The updated review, or null if the review does not exist.</returns> public Task<ReviewDetailDTO?> UpdateReviewAsync(Guid id, ReviewUpdateDTO data, bool save = true); + /// <summary> + /// Deletes a review identified by its ID. + /// </summary> + /// <param name="id">The ID of the review to be deleted.</param> + /// <param name="save">The data to be changed, null means that the corresponding property will not be changed.</param> + /// <returns>True if deleted succesfully, false otherwise.</returns> public Task<bool> DeleteReviewByIdAsync(Guid id, bool save = true); } } diff --git a/BusinessLayer/Services/ReviewService/ReviewService.cs b/BusinessLayer/Services/ReviewService/ReviewService.cs index ff27b85..9e0ac04 100644 --- a/BusinessLayer/Services/ReviewService/ReviewService.cs +++ b/BusinessLayer/Services/ReviewService/ReviewService.cs @@ -68,9 +68,10 @@ namespace BusinessLayer.Services.ReviewService return await _dbContext.Reviews.AnyAsync(r => ids.Contains(r.Id) && r.DeletedAt == null); } - public async Task<ReviewDetailDTO?> GetReviewAsync(Guid id, bool includeUser = true, bool includeRestaurant = true, bool IncludeComments = true) + public async Task<ReviewDetailDTO?> GetReviewAsync(Guid id, bool includeUser = true, + bool includeRestaurant = true, bool includeComments = true) { - var query = CreateQuery(includeUser, includeRestaurant, IncludeComments); + var query = CreateQuery(includeUser, includeRestaurant, includeComments); var review = await query.SingleOrDefaultAsync(r => r.Id == id); if (review is null || review.DeletedAt is not null) diff --git a/BusinessLayer/Services/UserService/IUserService.cs b/BusinessLayer/Services/UserService/IUserService.cs index 7e3c32d..27f575d 100644 --- a/BusinessLayer/Services/UserService/IUserService.cs +++ b/BusinessLayer/Services/UserService/IUserService.cs @@ -6,20 +6,57 @@ namespace BusinessLayer.Services.UserService { public interface IUserService : IBaseService { + /// <summary> + /// Retrieves multiple locations according to the criteria selected by the provided parameters. + /// </summary> + /// <param name="filter">Used to build a filter for the queried data.</param> + /// <param name="orderBy">Used for simple ordering of the queried data.</param> + /// <param name="limit">The maximum amount of items retrieved. If 0, all possible items will be retrieved.</param> + /// <param name="offset">The amount of items skipped from the beginning of the ordering. 0 means no items will be skipped.</param> + /// <param name="ids">The exact IDs to be found among the users.</param> + /// <returns>A list of users matching the criteria.</returns> public Task<List<UserDto>> GetUsersAsync( UserFilter filter, UserOrdering orderBy, int limit = 0, int offset = 0, Guid[]? ids = null); + + /// <summary> + /// Retrieve a single user based on the ID provided. + /// </summary> + /// <param name="id">The GUID of the user.</param> + /// <returns>The searched user, null otherwise.</returns> public Task<UserDetailDto?> GetUserAsync(Guid id); + + /// <summary> + /// Creates a new user based on the data provided. + /// </summary> + /// <param name="data">The data from which a user will be created.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>The newly created user, null otherwise.</returns> public Task<UserDetailDto?> CreateUserAsync( - UserCreateDto restaurant, + UserCreateDto data, bool save = true); + + /// <summary> + /// Updates a specific user based on data provided. + /// </summary> + /// <param name="id">The ID of the user to be updated.</param> + /// <param name="data">The data to be changed, null means that the corresponding property will not be changed.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>The updated user, otherwise null.</returns> public Task<UserDetailDto?> UpdateUserAsync( Guid id, - UserUpdateDto restaurant, + UserUpdateDto data, bool save = true); + + /// <summary> + /// Deletes a user identified by the provided ID. + /// </summary> + /// <param name="id">The ID of a user to be deleted.</param> + /// <param name="save">Determines whether the change is to be committed at the end of the call. If there are no other changes done in the function that is invoking this, consider setting this to true.</param> + /// <returns>True if the user was succesfully deleted, otherwise false.</returns> public Task<bool> DeleteUserAsync( Guid id, bool save = true); -- GitLab