diff --git a/Backend/Controllers/ActivityController.cs b/Backend/Controllers/ActivityController.cs index c146e63..a183d2f 100644 --- a/Backend/Controllers/ActivityController.cs +++ b/Backend/Controllers/ActivityController.cs @@ -248,7 +248,7 @@ public async Task> UpdateActivity(int id, ActivityU { await _activityRepository.UpdateActivity(activity, model); await _tripRepository.RecalculateTripDistanceAndBudget(trip); - return Ok(_mapper.Map(trip)); + return Ok(_mapper.Map(trip)); } catch (CustomException exception) { diff --git a/Backend/Controllers/AuthenticationController.cs b/Backend/Controllers/AuthenticationController.cs index 264fbce..e13d2e2 100644 --- a/Backend/Controllers/AuthenticationController.cs +++ b/Backend/Controllers/AuthenticationController.cs @@ -83,7 +83,7 @@ public async Task Register(UserRegisterModel model) } } Ranking ranking = await rankingRepository.GetDefaultRanking(); - if (ranking==null) + if (ranking == null) { ranking = await rankingRepository.CreateDefaultRanking(); } @@ -113,7 +113,8 @@ public async Task Register(UserRegisterModel model) return BadRequest(new ErrorModel() { ErrorType = ErrorType.INVALID_COUNTRY_CODE, Message = "A country with this code doesn't exist" }); } int NumberUsers = await userManager.Users.CountAsync(); - User user = new() { + User user = new() + { Email = model.Email, UserName = model.UserName, Name = model.Name, @@ -125,9 +126,9 @@ public async Task Register(UserRegisterModel model) Locale = model.Locale, CreationDate = DateTime.Now, IsActive = true, - Facebook="", - Twitter="", - Instagram="" + Facebook = "", + Twitter = "", + Instagram = "" }; IdentityResult result = await userManager.CreateAsync(user, model.Password); if (!result.Succeeded) @@ -211,7 +212,8 @@ public async Task Login(UserLoginModel model) new Claim(ClaimTypes.NameIdentifier, user.Id), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), }; - foreach (string userRole in userRoles){ + foreach (string userRole in userRoles) + { authClaims.Add(new Claim(ClaimTypes.Role, userRole)); } SymmetricSecurityKey authSigningKey = new(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"])); diff --git a/Backend/Controllers/GroupsController.cs b/Backend/Controllers/GroupsController.cs index 13c4758..95ef2fd 100644 --- a/Backend/Controllers/GroupsController.cs +++ b/Backend/Controllers/GroupsController.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using AutoMapper; using BackendAPI.Entities; -using BackendAPI.Repositories; -using AutoMapper; -using BackendAPI.Models.Group; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Identity; using BackendAPI.Entities.Enums; using BackendAPI.Exceptions; using BackendAPI.Models; +using BackendAPI.Models.Group; +using BackendAPI.Repositories; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace BackendAPI.Controllers { @@ -55,7 +55,7 @@ public async Task>> GetAllGroups() IEnumerable groups = await _repository.GetAll(); if (!is_admin) { - groups = groups.Where(g => !(g.IsPrivate && !user.Groups.Any(ug=>ug.Group.Id == g.Id))); + groups = groups.Where(g => !(g.IsPrivate && !user.Groups.Any(ug => ug.Group.Id == g.Id))); IEnumerable groups_ret = from g in groups select _mapper.Map(g); return Ok(groups_ret); } @@ -173,7 +173,7 @@ public async Task SendInvite(GroupSendInviteModel model) bool is_admin = user_roles.Contains(Enum.GetName(UserRole.ADMIN)); Group group = await _repository.GetById(model.GroupId); User user_to_add = await _userManager.FindByIdAsync(model.UserId); - if (group == null|| user_to_add == null) + if (group == null || user_to_add == null) { return NotFound(); } @@ -261,8 +261,8 @@ public async Task> CreateGroup(GroupCreateModel gr try { await _repository.Create(group); - await _repository.AddUser(group,user,null,true); - return Ok(_mapper.Map(group)); + await _repository.AddUser(group, user, null, true); + return Ok(_mapper.Map(group)); } catch (CustomException exception) { @@ -409,7 +409,7 @@ public async Task JoinGroup(GroupJoinModel model) try { //se for um admin, pode ignorar o requisito de convite caso o grupo seja privado - await _repository.AddUser(group, user,model.InviteId,is_admin); + await _repository.AddUser(group, user, model.InviteId, is_admin); return Ok(); } catch (CustomException exception) @@ -485,7 +485,8 @@ public async Task DeleteGroup(int id) return NotFound(); } UserGroupRole role = await _repository.GetUserRole(group, user); - if (!(is_admin || role == UserGroupRole.MANAGER)){ + if (!(is_admin || role == UserGroupRole.MANAGER)) + { return Forbid(); } try @@ -616,13 +617,13 @@ public async Task BanUser(GroupBanUserModel model) IList user_roles = await _userManager.GetRolesAsync(CurrentUser); bool is_admin = user_roles.Contains(Enum.GetName(UserRole.ADMIN)); UserGroupRole role = await _repository.GetUserRole(group, CurrentUser); - if (!(role== UserGroupRole.MANAGER|| role == UserGroupRole.MODERATOR || is_admin)) + if (!(role == UserGroupRole.MANAGER || role == UserGroupRole.MODERATOR || is_admin)) { return Forbid(); } try { - await _repository.BanUser(group,user,model.BanReason,model.BanUntil,model.HidePosts); + await _repository.BanUser(group, user, model.BanReason, model.BanUntil, model.HidePosts); return Ok(); } catch (CustomException exception) diff --git a/Backend/Controllers/InfoController.cs b/Backend/Controllers/InfoController.cs index b6c2d28..7d9dca6 100644 --- a/Backend/Controllers/InfoController.cs +++ b/Backend/Controllers/InfoController.cs @@ -30,7 +30,7 @@ public async Task> GetRecommendations() { User current_user = await _userManager.GetUserAsync(this.User); Recommendation recommendation = await _informationRepository.GetRecommendations(current_user); - RecommendationModel model = _mapper.Map(recommendation); + RecommendationModel model = _mapper.Map(recommendation); return Ok(model); } [Authorize(Roles = "ADMIN")] diff --git a/Backend/Controllers/PostsController.cs b/Backend/Controllers/PostsController.cs index 4daa742..769c2bc 100644 --- a/Backend/Controllers/PostsController.cs +++ b/Backend/Controllers/PostsController.cs @@ -44,7 +44,7 @@ public PostsController(IMapper mapper, ITripRepository tripRepository, IGroupRep public async Task>> GetAllPosts() { IEnumerable posts = await _postRepository.GetAll(); - IEnumerable posts_ret = from post in posts select _mapper.Map(post); + IEnumerable posts_ret = from post in posts select _mapper.Map(post); return Ok(posts_ret); } /// @@ -99,8 +99,8 @@ public async Task> GetById(int Id) return NotFound(); } if ( - (post.Trip.IsPrivate && !current_user.Trips.Any(cut=>cut.Trip.Id == post.Trip.Id)) || - (post.Trip.Group.IsPrivate && !current_user.Groups.Any(cug=>cug.Group.Id == post.Trip.Group.Id)) + (post.Trip.IsPrivate && !current_user.Trips.Any(cut => cut.Trip.Id == post.Trip.Id)) || + (post.Trip.Group.IsPrivate && !current_user.Groups.Any(cug => cug.Group.Id == post.Trip.Group.Id)) ) { return NotFound(); @@ -147,9 +147,9 @@ public async Task> CreatePost(PostCreateModel model) { return NotFound(); } - if ((await _tripRepository.GetUserTrip(trip,user) == null || await _groupRepository.GetUserGroup(trip.Group,user) == null) && !is_admin) + if ((await _tripRepository.GetUserTrip(trip, user) == null || await _groupRepository.GetUserGroup(trip.Group, user) == null) && !is_admin) { - return BadRequest(new ErrorModel() { ErrorType = ErrorType.POST_USER_NOT_IN_TRIP, Message = "Can't create a post since the user isn't in the trip"}); + return BadRequest(new ErrorModel() { ErrorType = ErrorType.POST_USER_NOT_IN_TRIP, Message = "Can't create a post since the user isn't in the trip" }); } Post post = _mapper.Map(model); post.User = user; @@ -157,7 +157,7 @@ public async Task> CreatePost(PostCreateModel model) try { await _postRepository.Create(post); - return Ok(_mapper.Map(post)); + return Ok(_mapper.Map(post)); } catch (CustomException exception) { @@ -206,14 +206,14 @@ public async Task UpdatePost(int Id, PostUpdateModel model) { return NotFound(); } - if (!(role==UserGroupRole.MANAGER || role == UserGroupRole.MODERATOR || is_admin) && current_user != post.User) + if (!(role == UserGroupRole.MANAGER || role == UserGroupRole.MODERATOR || is_admin) && current_user != post.User) { return Forbid(); } try { await _postRepository.Update(post, model); - return Ok(_mapper.Map(post)); + return Ok(_mapper.Map(post)); } catch (CustomException exception) { @@ -318,8 +318,8 @@ public async Task> AddAttachment([FromForm] int postId, } try { - await _postRepository.AddAttachment(post,file); - return Ok(_mapper.Map(post)); + await _postRepository.AddAttachment(post, file); + return Ok(_mapper.Map(post)); } catch (CustomException exception) { diff --git a/Backend/Controllers/RankingsController.cs b/Backend/Controllers/RankingsController.cs index b5fe906..858962f 100644 --- a/Backend/Controllers/RankingsController.cs +++ b/Backend/Controllers/RankingsController.cs @@ -55,7 +55,7 @@ public async Task> GetById(int Id) { return NotFound(); } - return _mapper.Map(ranking); + return _mapper.Map(ranking); } /// /// Atualizar os detalhes de um ranking no sistema @@ -87,7 +87,7 @@ public async Task> UpdateRanking(int Id, Ranking { return BadRequest(new ErrorModel() { ErrorType = exception.ErrorType, Message = exception.Message }); } - catch(Exception ex) + catch (Exception ex) { return BadRequest(new ErrorModel() { ErrorType = ErrorType.OTHER, Message = ex.Message }); } @@ -102,7 +102,7 @@ public async Task> UpdateRanking(int Id, Ranking [HttpPost] public async Task> CreateRanking(RankingCreateModel model) { - Ranking r = _mapper.Map(model); + Ranking r = _mapper.Map(model); try { await _repository.Create(r); diff --git a/Backend/Controllers/TripsController.cs b/Backend/Controllers/TripsController.cs index bf3540d..dfb1a8e 100644 --- a/Backend/Controllers/TripsController.cs +++ b/Backend/Controllers/TripsController.cs @@ -1,19 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; +using AutoMapper; using BackendAPI.Entities; -using AutoMapper; -using BackendAPI.Repositories; -using BackendAPI.Models.Trip; -using Microsoft.AspNetCore.Identity; using BackendAPI.Entities.Enums; -using Microsoft.AspNetCore.Authorization; +using BackendAPI.Exceptions; +using BackendAPI.Models; +using BackendAPI.Models.Trip; +using BackendAPI.Repositories; using GoogleApi.Entities.Maps.Directions.Response; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; -using BackendAPI.Models; -using BackendAPI.Exceptions; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace BackendAPI.Controllers { @@ -69,7 +69,7 @@ public async Task> CreateTrip(TripCreateModel tripCreate try { await _repository.Create(trip, group); - await _repository.AddUser(trip,current_user,null,true); + await _repository.AddUser(trip, current_user, null, true); return Ok(_mapper.Map(trip)); //redireciona depois baseado no ID } catch (CustomException exception) @@ -106,7 +106,7 @@ public async Task>> GetAllTrips() bool is_admin = user_roles.Contains(Enum.GetName(UserRole.ADMIN)); if (!is_admin) { - trips = trips.Where(t => + trips = trips.Where(t => !(t.Group.IsPrivate && !user.Groups.Any(ug => ug.Group.Id == t.Group.Id)) && !(t.IsPrivate && !user.Trips.Any(ut => ut.Trip.Id == t.Id))).ToList(); IEnumerable tripsList = from trip in trips select _mapper.Map(trip); @@ -207,7 +207,7 @@ public async Task JoinTrip(TripJoinModel model) } try { - await _repository.AddUser(trip, user,model.InviteId, (is_admin|| IsManager)); + await _repository.AddUser(trip, user, model.InviteId, (is_admin || IsManager)); return Ok(); } catch (CustomException exception) @@ -283,7 +283,7 @@ public async Task> RemoveUser(TripRemoveUserModel model) } try { - await _repository.RemoveUser(trip,user_to_remove); + await _repository.RemoveUser(trip, user_to_remove); return Ok(); } catch (CustomException exception) diff --git a/Backend/Controllers/UsersController.cs b/Backend/Controllers/UsersController.cs index 48ff20a..48dbe1c 100644 --- a/Backend/Controllers/UsersController.cs +++ b/Backend/Controllers/UsersController.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using AutoMapper; using BackendAPI.Entities; +using BackendAPI.Entities.Enums; +using BackendAPI.Exceptions; +using BackendAPI.Models; using BackendAPI.Models.User; -using AutoMapper; using BackendAPI.Repositories; using Microsoft.AspNetCore.Authorization; -using BackendAPI.Entities.Enums; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; -using BackendAPI.Exceptions; -using BackendAPI.Models; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace BackendAPI.Controllers { @@ -45,7 +45,7 @@ public UsersController(IMapper mapper, IUserRepository repository, UserManager>> GetAllUsers() { IEnumerable users = await _repository.GetAll(); - IEnumerable users_ret = from user in users select _mapper.Map(user); + IEnumerable users_ret = from user in users select _mapper.Map(user); return Ok(users_ret); } /// @@ -97,11 +97,11 @@ public async Task> GetUserById(String id) !(ug.Group.IsPrivate && !current_user.Groups.Any(gg => gg.Group.Id == ug.Group.Id))).ToList(); //Esconder Trips e Posts de Trips que estejam escondidas e o utilizador não pertença à mesma, ou que pertençam a grupos privados que o utilizador actual não esteja presente - user.Trips = user.Trips.Where(ut => - !(ut.Trip.IsPrivate && !current_user.Trips.Any(cut=>cut.Trip.Id == ut.Trip.Id)) && + user.Trips = user.Trips.Where(ut => + !(ut.Trip.IsPrivate && !current_user.Trips.Any(cut => cut.Trip.Id == ut.Trip.Id)) && !(ut.Trip.Group.IsPrivate && !current_user.Groups.Any(gg => gg.Group.Id == ut.Trip.Group.Id))).ToList(); - user.Posts = user.Posts.Where(up => - !(up.Trip.IsPrivate && !current_user.Trips.Any(cut => cut.Trip.Id == up.Trip.Id)) && + user.Posts = user.Posts.Where(up => + !(up.Trip.IsPrivate && !current_user.Trips.Any(cut => cut.Trip.Id == up.Trip.Id)) && !(up.Trip.Group.IsPrivate && !current_user.Groups.Any(gg => gg.Group.Id == up.Trip.Group.Id)) && !up.IsHidden).ToList(); user.Following = user.Following.Where(f => f.IsActive).ToList(); @@ -338,7 +338,7 @@ public async Task DeleteOwnPicture() /// /// Remoção do Utilizador do Sistema bem-sucedida /// Não existe um utilizador no sistema com este ID - [Authorize(Roles ="ADMIN")] + [Authorize(Roles = "ADMIN")] [HttpDelete("{id}")] public async Task DeleteUser(String Id) { diff --git a/Backend/Entities/Activity.cs b/Backend/Entities/Activity.cs index 0d46bcb..4de9197 100644 --- a/Backend/Entities/Activity.cs +++ b/Backend/Entities/Activity.cs @@ -1,5 +1,5 @@ -using System; -using BackendAPI.Entities.Enums; +using BackendAPI.Entities.Enums; +using System; namespace BackendAPI.Entities { public class Activity diff --git a/Backend/Entities/Enums/ActivityType.cs b/Backend/Entities/Enums/ActivityType.cs index d4d9d1d..fd7cd6f 100644 --- a/Backend/Entities/Enums/ActivityType.cs +++ b/Backend/Entities/Enums/ActivityType.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace BackendAPI.Entities.Enums +namespace BackendAPI.Entities.Enums { public enum ActivityType { diff --git a/Backend/Entities/Enums/ErrorType.cs b/Backend/Entities/Enums/ErrorType.cs index 9a700ac..f4ec269 100644 --- a/Backend/Entities/Enums/ErrorType.cs +++ b/Backend/Entities/Enums/ErrorType.cs @@ -3,67 +3,67 @@ public enum ErrorType { //ADICIONAR SEMPRE NOVAS ENUMERAÇÕES NO FIM - AUTHENTICATION_EMAIL_EXISTS=0, - AUTHENTICATION_USERNAME_EXISTS=1, - AUTHENTICATION_WRONG_PASSWORD=2, - AUTHENTICATION_ACCOUNT_NOT_CONFIRMED=3, - AUTHENTICATION_INVALID_PASSWORD=4, - AUTHENTICATION_INVALID_USER=5, - AUTHENTICATION_DELETED_ACCOUNT=6, - AUTHENTICATION_WRONG_PASSWORD_RESET=7, - AUTHENTICATION_WRONG_EMAIL_CONFIRMATION=8, - AUTHENTICATION_EMAIL_ALREADY_CONFIRMED=9, - AUTHENTICATION_ACCOUNT_CREATION_ERROR=10, + AUTHENTICATION_EMAIL_EXISTS = 0, + AUTHENTICATION_USERNAME_EXISTS = 1, + AUTHENTICATION_WRONG_PASSWORD = 2, + AUTHENTICATION_ACCOUNT_NOT_CONFIRMED = 3, + AUTHENTICATION_INVALID_PASSWORD = 4, + AUTHENTICATION_INVALID_USER = 5, + AUTHENTICATION_DELETED_ACCOUNT = 6, + AUTHENTICATION_WRONG_PASSWORD_RESET = 7, + AUTHENTICATION_WRONG_EMAIL_CONFIRMATION = 8, + AUTHENTICATION_EMAIL_ALREADY_CONFIRMED = 9, + AUTHENTICATION_ACCOUNT_CREATION_ERROR = 10, - RANKING_DEFAULT_DELETE=11, - RANKING_EXISTS=12, - RANKING_INVALID_NUMBER_MINIMUM_KILOMETERS=53, + RANKING_DEFAULT_DELETE = 11, + RANKING_EXISTS = 12, + RANKING_INVALID_NUMBER_MINIMUM_KILOMETERS = 53, - ACTIVITY_TYPE_NOT_DEFINED=13, - ACTIVITY_TRANSPORT_TYPE_NOT_DEFINED=14, - ACTIVITY_NOT_IN_TRIP_RANGE=15, - ACTIVITY_NOT_SAME_DAY=16, - ACTIVITY_MISSING_TRANSPORT=17, - ACTIVITY_REPEATED=18, - ACTIVITY_OVERLAP=19, - ACTIVITY_REMOVE_TRANSPORT=20, - ACTIVITY_REMOVE_NOT_LAST=21, - ACTIVITY_CHANGE_TYPE=22, - ACTIVITY_PLACE_ID_NONEXIST=23, - ACTIVITY_SEARCH_TRANSPORT_NO_DEPARTURE_AND_ARRIVAL_TIME=51, + ACTIVITY_TYPE_NOT_DEFINED = 13, + ACTIVITY_TRANSPORT_TYPE_NOT_DEFINED = 14, + ACTIVITY_NOT_IN_TRIP_RANGE = 15, + ACTIVITY_NOT_SAME_DAY = 16, + ACTIVITY_MISSING_TRANSPORT = 17, + ACTIVITY_REPEATED = 18, + ACTIVITY_OVERLAP = 19, + ACTIVITY_REMOVE_TRANSPORT = 20, + ACTIVITY_REMOVE_NOT_LAST = 21, + ACTIVITY_CHANGE_TYPE = 22, + ACTIVITY_PLACE_ID_NONEXIST = 23, + ACTIVITY_SEARCH_TRANSPORT_NO_DEPARTURE_AND_ARRIVAL_TIME = 51, - TRIP_COMPLETED=24, - TRIP_INVITE_INVALID=25, - TRIP_USER_ALREADY_PRESENT=26, - TRIP_USER_ALREADY_INVITED=27, - TRIP_USER_NOT_PRESENT_GROUP=28, - TRIP_DATE_INVALID=29, - TRIP_DATE_EXISTING_ACTIVITIES=30, - TRIP_USER_NOT_PRESENT=31, + TRIP_COMPLETED = 24, + TRIP_INVITE_INVALID = 25, + TRIP_USER_ALREADY_PRESENT = 26, + TRIP_USER_ALREADY_INVITED = 27, + TRIP_USER_NOT_PRESENT_GROUP = 28, + TRIP_DATE_INVALID = 29, + TRIP_DATE_EXISTING_ACTIVITIES = 30, + TRIP_USER_NOT_PRESENT = 31, - GROUP_INVITE_INVALID=32, - GROUP_USER_ALREADY_PRESENT=33, - GROUP_USER_ALREADY_INVITED=34, - GROUP_USER_NOT_PRESENT=35, - GROUP_LAST_MANAGER_LEAVE=36, - GROUP_ROLE_INVALID=37, - GROUP_MANAGER_MANAGE_ITSELF=38, + GROUP_INVITE_INVALID = 32, + GROUP_USER_ALREADY_PRESENT = 33, + GROUP_USER_ALREADY_INVITED = 34, + GROUP_USER_NOT_PRESENT = 35, + GROUP_LAST_MANAGER_LEAVE = 36, + GROUP_ROLE_INVALID = 37, + GROUP_MANAGER_MANAGE_ITSELF = 38, GROUP_USER_ALREADY_BANNED = 46, GROUP_USER_NOT_BANNED = 47, GROUP_USER_JOIN_BANNED = 48, GROUP_BAN_DATE_INVALID = 50, - POST_DATE_INVALID=39, - POST_USER_NOT_IN_TRIP=52, + POST_DATE_INVALID = 39, + POST_USER_NOT_IN_TRIP = 52, - INVALID_COUNTRY_CODE=40, - EMAIL_ERROR=41, - MEDIA_ERROR=42, - OTHER=43, + INVALID_COUNTRY_CODE = 40, + EMAIL_ERROR = 41, + MEDIA_ERROR = 42, + OTHER = 43, - USER_ALREADY_FOLLOWING=44, - USER_NOT_FOLLOWING=45, - USER_NOT_FOLLOW_SELF=49 + USER_ALREADY_FOLLOWING = 44, + USER_NOT_FOLLOWING = 45, + USER_NOT_FOLLOW_SELF = 49 } } diff --git a/Backend/Entities/Enums/EventType.cs b/Backend/Entities/Enums/EventType.cs index fee0ead..57e9496 100644 --- a/Backend/Entities/Enums/EventType.cs +++ b/Backend/Entities/Enums/EventType.cs @@ -2,25 +2,25 @@ { public enum EventType { - GROUP_CREATE=0, - GROUP_USER_ENTER=1, - GROUP_USER_ENTER_INVITE=2, - GROUP_USER_LEAVE=3, - GROUP_INVITE_CREATE=4, - GROUP_INVITE_REJECT=5, - GROUP_DETAILS_UPDATE=6, - GROUP_USER_ROLE_CHANGE=7, - GROUP_DELETE=8, - GROUP_USER_BAN=17, - GROUP_USER_UNBAN=18, + GROUP_CREATE = 0, + GROUP_USER_ENTER = 1, + GROUP_USER_ENTER_INVITE = 2, + GROUP_USER_LEAVE = 3, + GROUP_INVITE_CREATE = 4, + GROUP_INVITE_REJECT = 5, + GROUP_DETAILS_UPDATE = 6, + GROUP_USER_ROLE_CHANGE = 7, + GROUP_DELETE = 8, + GROUP_USER_BAN = 17, + GROUP_USER_UNBAN = 18, - TRIP_CREATE=9, - TRIP_DETAILS_UPDATE=10, - TRIP_USER_ENTER=11, - TRIP_USER_ENTER_INVITE=12, - TRIP_USER_LEAVE=13, - TRIP_INVITE_CREATE=14, - TRIP_INVITE_REJECT=15, - TRIP_DELETE=16 + TRIP_CREATE = 9, + TRIP_DETAILS_UPDATE = 10, + TRIP_USER_ENTER = 11, + TRIP_USER_ENTER_INVITE = 12, + TRIP_USER_LEAVE = 13, + TRIP_INVITE_CREATE = 14, + TRIP_INVITE_REJECT = 15, + TRIP_DELETE = 16 } } diff --git a/Backend/Entities/Enums/UserGroupRole.cs b/Backend/Entities/Enums/UserGroupRole.cs index 1e42f6a..0aff3d6 100644 --- a/Backend/Entities/Enums/UserGroupRole.cs +++ b/Backend/Entities/Enums/UserGroupRole.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace BackendAPI.Entities.Enums +namespace BackendAPI.Entities.Enums { public enum UserGroupRole { diff --git a/Backend/Entities/GroupInvite.cs b/Backend/Entities/GroupInvite.cs index ef5eb45..554ef8c 100644 --- a/Backend/Entities/GroupInvite.cs +++ b/Backend/Entities/GroupInvite.cs @@ -1,6 +1,4 @@ -using BackendAPI.Entities.Enums; -using System; -using System.ComponentModel.DataAnnotations.Schema; +using System; namespace BackendAPI.Entities { diff --git a/Backend/Entities/Post.cs b/Backend/Entities/Post.cs index 204bc6c..b0dbc95 100644 --- a/Backend/Entities/Post.cs +++ b/Backend/Entities/Post.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; namespace BackendAPI.Entities { diff --git a/Backend/Entities/Ranking.cs b/Backend/Entities/Ranking.cs index 907c5f0..b29214d 100644 --- a/Backend/Entities/Ranking.cs +++ b/Backend/Entities/Ranking.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace BackendAPI.Entities { diff --git a/Backend/Entities/Statistic.cs b/Backend/Entities/Statistic.cs index fc2006c..0c8b329 100644 --- a/Backend/Entities/Statistic.cs +++ b/Backend/Entities/Statistic.cs @@ -1,12 +1,11 @@ using BackendAPI.Entities.Enums; -using System; using System.Collections.Generic; namespace BackendAPI.Entities { public class Statistic { - public Dictionary MostVisitedPlaces { get; set; } + public Dictionary MostVisitedPlaces { get; set; } public Dictionary TripsByTotalDistance { get; set; } public Dictionary TripsByTotalCost { get; set; } public Dictionary TripsByNumberUsers { get; set; } diff --git a/Backend/Entities/Trip.cs b/Backend/Entities/Trip.cs index 2dacad6..7be2bef 100644 --- a/Backend/Entities/Trip.cs +++ b/Backend/Entities/Trip.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; namespace BackendAPI.Entities { diff --git a/Backend/Entities/TripInvite.cs b/Backend/Entities/TripInvite.cs index d1425bb..088891d 100644 --- a/Backend/Entities/TripInvite.cs +++ b/Backend/Entities/TripInvite.cs @@ -1,5 +1,4 @@ -using BackendAPI.Entities.Enums; -using System; +using System; namespace BackendAPI.Entities { diff --git a/Backend/Entities/User.cs b/Backend/Entities/User.cs index 55c0569..32f297c 100644 --- a/Backend/Entities/User.cs +++ b/Backend/Entities/User.cs @@ -1,6 +1,6 @@ -using System; +using Microsoft.AspNetCore.Identity; +using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Identity; namespace BackendAPI.Entities { diff --git a/Backend/Entities/UserGroup.cs b/Backend/Entities/UserGroup.cs index 29cd356..a364e9d 100644 --- a/Backend/Entities/UserGroup.cs +++ b/Backend/Entities/UserGroup.cs @@ -1,8 +1,5 @@ -using System; -using BackendAPI.Entities.Enums; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using BackendAPI.Entities.Enums; +using System; namespace BackendAPI.Entities { diff --git a/Backend/Helpers/EmailHelper.cs b/Backend/Helpers/EmailHelper.cs index 8be11e2..8ff9033 100644 --- a/Backend/Helpers/EmailHelper.cs +++ b/Backend/Helpers/EmailHelper.cs @@ -38,11 +38,11 @@ public string GetEmailConfirmationLink(string UserId, string EmailConfirmationTo string EmailConfirmationTokenEncoded = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(EmailConfirmationToken)); return $"{_domain}/confirm-email/{UserId}/{EmailConfirmationTokenEncoded}"; } - public async Task SendEmail(string Subject, string Body,string Destination) + public async Task SendEmail(string Subject, string Body, string Destination) { Body += _footer; TransactionalEmail email = new TransactionalEmailBuilder() - .WithFrom(new SendContact(_email,"Viagens Sociais")) + .WithFrom(new SendContact(_email, "Viagens Sociais")) .WithSubject(Subject) .WithHtmlPart(Body) .WithTo(new SendContact(Destination)) @@ -50,14 +50,14 @@ public async Task SendEmail(string Subject, string Body,string Destination TransactionalEmailResponse response = await _mailjetClient.SendTransactionalEmailAsync(email); return (response.Messages.Length == 1 && response.Messages[0].Status == "success"); } - public async Task<(int,int)> SendEmailToMultiple(string Subject, string Body,List Destinations) + public async Task<(int, int)> SendEmailToMultiple(string Subject, string Body, List Destinations) { Body += _footer; int NumberMessagesDelivered = 0; int NumberMessagesNonDelivered = 0; IEnumerable SendContacts = from contact in Destinations select new SendContact(contact); TransactionalEmail email = new TransactionalEmailBuilder() - .WithFrom(new SendContact(_bulkEmail,"Viagens Sociais")) + .WithFrom(new SendContact(_bulkEmail, "Viagens Sociais")) .WithSubject(Subject) .WithHtmlPart(Body) .WithTo(SendContacts) diff --git a/Backend/Helpers/FileHelper.cs b/Backend/Helpers/FileHelper.cs index e8f6712..7f13df0 100644 --- a/Backend/Helpers/FileHelper.cs +++ b/Backend/Helpers/FileHelper.cs @@ -13,7 +13,7 @@ public class FileHelper { public const int ImageMinimumBytes = 512; private readonly static string[] AllowedImageExtensions = { ".jpg", ".png", ".gif", ".jpeg" }; - private readonly static string[] AllowedVideoExtensions = { ".mp4", ".avi", ".mov", ".mkv",".webm",".wmv" }; + private readonly static string[] AllowedVideoExtensions = { ".mp4", ".avi", ".mov", ".mkv", ".webm", ".wmv" }; private readonly static string[] AllowedImageMimeTypes = { "image/jpg", "image/jpeg", "image/pjpeg", "image/gif", "image/x-png", "image/png" }; /// /// Checks for the Validity of an image file (valid file extension, MIME type or any sort of disguised file) @@ -26,7 +26,8 @@ public static bool IsImage(IFormFile postedFile) { return false; } - if (!AllowedImageExtensions.Contains(Path.GetExtension(postedFile.FileName).ToLower())){ + if (!AllowedImageExtensions.Contains(Path.GetExtension(postedFile.FileName).ToLower())) + { return false; } try diff --git a/Backend/Helpers/GoogleMapsHelper.cs b/Backend/Helpers/GoogleMapsHelper.cs index 8358c4b..166002c 100644 --- a/Backend/Helpers/GoogleMapsHelper.cs +++ b/Backend/Helpers/GoogleMapsHelper.cs @@ -1,23 +1,23 @@ using BackendAPI.Entities.Enums; +using BackendAPI.Exceptions; using BackendAPI.Models.Activity; +using Ganss.Xss; +using Geolocation; using GoogleApi; +using GoogleApi.Entities.Common.Enums.Extensions; using GoogleApi.Entities.Maps.Common; using GoogleApi.Entities.Maps.Common.Enums; using GoogleApi.Entities.Maps.Directions.Request; using GoogleApi.Entities.Maps.Directions.Response; -using GoogleApi.Entities.Common.Enums.Extensions; +using GoogleApi.Entities.Maps.DistanceMatrix.Request; +using GoogleApi.Entities.Maps.DistanceMatrix.Response; +using GoogleApi.Entities.Places.Details.Request; +using GoogleApi.Entities.Places.Details.Response; +using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Geolocation; -using GoogleApi.Entities.Maps.DistanceMatrix.Request; -using GoogleApi.Entities.Places.Details.Request; -using Microsoft.Extensions.Configuration; -using GoogleApi.Entities.Maps.DistanceMatrix.Response; -using GoogleApi.Entities.Places.Details.Response; -using BackendAPI.Exceptions; -using Ganss.Xss; namespace BackendAPI.Helpers { @@ -107,7 +107,7 @@ public async Task> GetAllTransporationMethod Description = sanitizer.Sanitize(Description); DateTime DepartureTime = departTime; DateTime ArrivalTime = DepartureTime.AddSeconds(leg.Duration.Value); - if (travelMode == TravelMode.Transit && leg.DepartureTime!=null) + if (travelMode == TravelMode.Transit && leg.DepartureTime != null) { DepartureTime = DateTimeOffset.FromUnixTimeSeconds(leg.DepartureTime.Value).DateTime; ArrivalTime = DateTimeOffset.FromUnixTimeSeconds(leg.ArrivalTime.Value).DateTime; @@ -118,11 +118,11 @@ public async Task> GetAllTransporationMethod return result; } - public async Task<(Coordinate,String,String)> GetCoordinatesAndAddressFromPlaceId(string PlaceId) + public async Task<(Coordinate, String, String)> GetCoordinatesAndAddressFromPlaceId(string PlaceId) { PlacesDetailsRequest request = new PlacesDetailsRequest { - Key=ApiKey, + Key = ApiKey, PlaceId = PlaceId, }; PlacesDetailsResponse response = await GooglePlaces.Details.QueryAsync(request); diff --git a/Backend/Helpers/IGoogleMapsHelper.cs b/Backend/Helpers/IGoogleMapsHelper.cs index 664ad8d..d12f390 100644 --- a/Backend/Helpers/IGoogleMapsHelper.cs +++ b/Backend/Helpers/IGoogleMapsHelper.cs @@ -1,9 +1,9 @@ -using System.Threading.Tasks; -using System; -using Geolocation; +using BackendAPI.Entities.Enums; using BackendAPI.Models.Activity; +using Geolocation; +using System; using System.Collections.Generic; -using BackendAPI.Entities.Enums; +using System.Threading.Tasks; namespace BackendAPI.Helpers { diff --git a/Backend/Helpers/MapperProfile.cs b/Backend/Helpers/MapperProfile.cs index 6d1b4dd..da33ee2 100644 --- a/Backend/Helpers/MapperProfile.cs +++ b/Backend/Helpers/MapperProfile.cs @@ -1,14 +1,13 @@ using AutoMapper; using BackendAPI.Entities; -using BackendAPI.Models.Group; -using BackendAPI.Models.User; -using BackendAPI.Models.Trip; -using BackendAPI.Models.Ranking; using BackendAPI.Models.Activity; using BackendAPI.Models.Attachment; -using BackendAPI.Models.Post; +using BackendAPI.Models.Group; using BackendAPI.Models.Information; -using System.Collections.Generic; +using BackendAPI.Models.Post; +using BackendAPI.Models.Ranking; +using BackendAPI.Models.Trip; +using BackendAPI.Models.User; namespace BackendAPI.Data { @@ -44,19 +43,19 @@ public MapperProfile() CreateMap(); CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); CreateMap(); CreateMap(); CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); CreateMap(); CreateMap(); CreateMap(); CreateMap(); CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); CreateMap(); CreateMap(); CreateMap(); diff --git a/Backend/Migrations/20221105161918_InitialMigration.cs b/Backend/Migrations/20221105161918_InitialMigration.cs index 1b930c1..d58ec09 100644 --- a/Backend/Migrations/20221105161918_InitialMigration.cs +++ b/Backend/Migrations/20221105161918_InitialMigration.cs @@ -1,5 +1,5 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; +using System; namespace BackendAPI.Migrations { diff --git a/Backend/Models/Authentication/ResetPasswordModel.cs b/Backend/Models/Authentication/ResetPasswordModel.cs index 050cc3a..7c536cd 100644 --- a/Backend/Models/Authentication/ResetPasswordModel.cs +++ b/Backend/Models/Authentication/ResetPasswordModel.cs @@ -9,6 +9,6 @@ public class ResetPasswordModel [Required] public string PasswordResetToken { get; set; } [Required] - public string NewPassword {get; set; } + public string NewPassword { get; set; } } } diff --git a/Backend/Models/Authentication/UserRegisterModel.cs b/Backend/Models/Authentication/UserRegisterModel.cs index 3368314..5180330 100644 --- a/Backend/Models/Authentication/UserRegisterModel.cs +++ b/Backend/Models/Authentication/UserRegisterModel.cs @@ -1,6 +1,4 @@ -using BackendAPI.Models.Attachment; -using Microsoft.AspNetCore.Http; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace BackendAPI.Models.User { diff --git a/Backend/Models/Group/GroupCreateModel.cs b/Backend/Models/Group/GroupCreateModel.cs index 4ba3393..0d107d2 100644 --- a/Backend/Models/Group/GroupCreateModel.cs +++ b/Backend/Models/Group/GroupCreateModel.cs @@ -1,7 +1,4 @@ -using BackendAPI.Entities; -using BackendAPI.Models.Attachment; -using Microsoft.AspNetCore.Http; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace BackendAPI.Models.Group { diff --git a/Backend/Models/Group/GroupDetailsUpdateModel.cs b/Backend/Models/Group/GroupDetailsUpdateModel.cs index cdc1d94..5d612eb 100644 --- a/Backend/Models/Group/GroupDetailsUpdateModel.cs +++ b/Backend/Models/Group/GroupDetailsUpdateModel.cs @@ -1,7 +1,4 @@ -using BackendAPI.Models.Attachment; -using Microsoft.AspNetCore.Http; - -namespace BackendAPI.Models.Group +namespace BackendAPI.Models.Group { public class GroupDetailsUpdateModel { diff --git a/Backend/Models/Group/GroupInviteModel.cs b/Backend/Models/Group/GroupInviteModel.cs index a4cd163..a9f9488 100644 --- a/Backend/Models/Group/GroupInviteModel.cs +++ b/Backend/Models/Group/GroupInviteModel.cs @@ -1,5 +1,4 @@ -using BackendAPI.Entities.Enums; -using BackendAPI.Models.User; +using BackendAPI.Models.User; using System; namespace BackendAPI.Models.Group diff --git a/Backend/Models/Group/GroupModel.cs b/Backend/Models/Group/GroupModel.cs index 2c54e56..df7d817 100644 --- a/Backend/Models/Group/GroupModel.cs +++ b/Backend/Models/Group/GroupModel.cs @@ -1,7 +1,4 @@ -using BackendAPI.Entities; -using BackendAPI.Models.Attachment; -using BackendAPI.Models.Trip; -using BackendAPI.Models.User; +using BackendAPI.Models.Trip; using System; using System.Collections.Generic; diff --git a/Backend/Models/Group/GroupModelAdmin.cs b/Backend/Models/Group/GroupModelAdmin.cs index 003bcbc..6363383 100644 --- a/Backend/Models/Group/GroupModelAdmin.cs +++ b/Backend/Models/Group/GroupModelAdmin.cs @@ -1,7 +1,4 @@ -using BackendAPI.Entities; -using BackendAPI.Models.Attachment; -using BackendAPI.Models.Trip; -using BackendAPI.Models.User; +using BackendAPI.Models.Trip; using System; using System.Collections.Generic; diff --git a/Backend/Models/Group/GroupModelSimple.cs b/Backend/Models/Group/GroupModelSimple.cs index 788a5d4..e494040 100644 --- a/Backend/Models/Group/GroupModelSimple.cs +++ b/Backend/Models/Group/GroupModelSimple.cs @@ -1,5 +1,4 @@ -using BackendAPI.Models.Attachment; -using System; +using System; namespace BackendAPI.Models.Group { diff --git a/Backend/Models/Group/GroupModelTrip.cs b/Backend/Models/Group/GroupModelTrip.cs index 2d3de53..8d4a6d3 100644 --- a/Backend/Models/Group/GroupModelTrip.cs +++ b/Backend/Models/Group/GroupModelTrip.cs @@ -1,5 +1,4 @@ -using BackendAPI.Models.Attachment; -using System; +using System; using System.Collections.Generic; namespace BackendAPI.Models.Group diff --git a/Backend/Models/Information/StatisticsModel.cs b/Backend/Models/Information/StatisticsModel.cs index 6148fb5..1033d94 100644 --- a/Backend/Models/Information/StatisticsModel.cs +++ b/Backend/Models/Information/StatisticsModel.cs @@ -1,5 +1,4 @@ using BackendAPI.Entities.Enums; -using System; using System.Collections.Generic; namespace BackendAPI.Models.Information diff --git a/Backend/Models/Post/PostCreateModel.cs b/Backend/Models/Post/PostCreateModel.cs index 5cd68ef..1ce5355 100644 --- a/Backend/Models/Post/PostCreateModel.cs +++ b/Backend/Models/Post/PostCreateModel.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; namespace BackendAPI.Models.Post { diff --git a/Backend/Models/Post/PostModel.cs b/Backend/Models/Post/PostModel.cs index f117d9c..d149cfd 100644 --- a/Backend/Models/Post/PostModel.cs +++ b/Backend/Models/Post/PostModel.cs @@ -16,7 +16,7 @@ public class PostModel public int Id { get; set; } public string Description { get; set; } public UserModelSimple User { get; set; } - public TripModelSimple Trip{ get; set; } + public TripModelSimple Trip { get; set; } public DateTime Date { get; set; } public DateTime PublishedDate { get; set; } public List Attachments { get; set; } diff --git a/Backend/Models/Post/PostModelTrip.cs b/Backend/Models/Post/PostModelTrip.cs index eb0ed1a..522625a 100644 --- a/Backend/Models/Post/PostModelTrip.cs +++ b/Backend/Models/Post/PostModelTrip.cs @@ -1,5 +1,4 @@ using BackendAPI.Models.Attachment; -using BackendAPI.Models.Trip; using BackendAPI.Models.User; using System; using System.Collections.Generic; diff --git a/Backend/Models/Post/PostUpdateModel.cs b/Backend/Models/Post/PostUpdateModel.cs index 58db227..31df2bf 100644 --- a/Backend/Models/Post/PostUpdateModel.cs +++ b/Backend/Models/Post/PostUpdateModel.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; namespace BackendAPI.Models.Post { diff --git a/Backend/Models/Trip/TripCreateModel.cs b/Backend/Models/Trip/TripCreateModel.cs index 105bad0..88b3e4c 100644 --- a/Backend/Models/Trip/TripCreateModel.cs +++ b/Backend/Models/Trip/TripCreateModel.cs @@ -1,11 +1,5 @@ -using BackendAPI.Entities; -using BackendAPI.Models.Attachment; -using Microsoft.AspNetCore.Http; -using System; -using System.Collections.Generic; +using System; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; namespace BackendAPI.Models.Trip { diff --git a/Backend/Models/Trip/TripDetailsUpdateModel.cs b/Backend/Models/Trip/TripDetailsUpdateModel.cs index 2ef318b..e320bb7 100644 --- a/Backend/Models/Trip/TripDetailsUpdateModel.cs +++ b/Backend/Models/Trip/TripDetailsUpdateModel.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Http; -using System; +using System; namespace BackendAPI.Models.Trip { diff --git a/Backend/Models/Trip/TripModel.cs b/Backend/Models/Trip/TripModel.cs index 71021d6..732c14d 100644 --- a/Backend/Models/Trip/TripModel.cs +++ b/Backend/Models/Trip/TripModel.cs @@ -1,12 +1,8 @@ -using BackendAPI.Entities; -using BackendAPI.Models.Activity; -using BackendAPI.Models.Attachment; +using BackendAPI.Models.Activity; using BackendAPI.Models.Group; using BackendAPI.Models.Post; using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace BackendAPI.Models.Trip { diff --git a/Backend/Models/Trip/TripModelAdmin.cs b/Backend/Models/Trip/TripModelAdmin.cs index 0204d35..2ffca27 100644 --- a/Backend/Models/Trip/TripModelAdmin.cs +++ b/Backend/Models/Trip/TripModelAdmin.cs @@ -1,6 +1,4 @@ -using BackendAPI.Entities; -using BackendAPI.Models.Activity; -using BackendAPI.Models.Attachment; +using BackendAPI.Models.Activity; using BackendAPI.Models.Group; using BackendAPI.Models.Post; using System; diff --git a/Backend/Models/Trip/TripModelGroup.cs b/Backend/Models/Trip/TripModelGroup.cs index 5ed05fb..6c243fe 100644 --- a/Backend/Models/Trip/TripModelGroup.cs +++ b/Backend/Models/Trip/TripModelGroup.cs @@ -1,7 +1,4 @@ -using BackendAPI.Models.Activity; -using BackendAPI.Models.Attachment; -using BackendAPI.Models.Post; -using System; +using System; using System.Collections.Generic; namespace BackendAPI.Models.Trip diff --git a/Backend/Models/Trip/TripModelSimple.cs b/Backend/Models/Trip/TripModelSimple.cs index 96b4d3a..2303ad1 100644 --- a/Backend/Models/Trip/TripModelSimple.cs +++ b/Backend/Models/Trip/TripModelSimple.cs @@ -1,5 +1,4 @@ -using BackendAPI.Models.Attachment; -using System; +using System; namespace BackendAPI.Models.Trip { diff --git a/Backend/Models/Trip/TripSearchModel.cs b/Backend/Models/Trip/TripSearchModel.cs index 74de52d..3a4f267 100644 --- a/Backend/Models/Trip/TripSearchModel.cs +++ b/Backend/Models/Trip/TripSearchModel.cs @@ -3,7 +3,7 @@ public class TripSearchModel { public string TripName { get; set; } - public string TripDescription { get; set;} - public string TripDestination { get; set;} + public string TripDescription { get; set; } + public string TripDestination { get; set; } } } diff --git a/Backend/Models/User/UserDetailsUpdateModel.cs b/Backend/Models/User/UserDetailsUpdateModel.cs index 41007e8..2659410 100644 --- a/Backend/Models/User/UserDetailsUpdateModel.cs +++ b/Backend/Models/User/UserDetailsUpdateModel.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Http; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace BackendAPI.Models.User { diff --git a/Backend/Models/User/UserGroupInviteModel.cs b/Backend/Models/User/UserGroupInviteModel.cs index ed44587..9f1b6d1 100644 --- a/Backend/Models/User/UserGroupInviteModel.cs +++ b/Backend/Models/User/UserGroupInviteModel.cs @@ -1,5 +1,4 @@ -using BackendAPI.Entities.Enums; -using BackendAPI.Models.Group; +using BackendAPI.Models.Group; using System; namespace BackendAPI.Models.User diff --git a/Backend/Models/User/UserModel.cs b/Backend/Models/User/UserModel.cs index 02407ec..61c3217 100644 --- a/Backend/Models/User/UserModel.cs +++ b/Backend/Models/User/UserModel.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using System; -using BackendAPI.Models.Post; +using BackendAPI.Models.Post; using BackendAPI.Models.Ranking; +using System; +using System.Collections.Generic; namespace BackendAPI.Models.User { diff --git a/Backend/Models/User/UserModelSimple.cs b/Backend/Models/User/UserModelSimple.cs index e229473..54b9735 100644 --- a/Backend/Models/User/UserModelSimple.cs +++ b/Backend/Models/User/UserModelSimple.cs @@ -1,6 +1,4 @@ -using BackendAPI.Entities; -using BackendAPI.Models.Attachment; -using BackendAPI.Models.Ranking; +using BackendAPI.Models.Ranking; using System; namespace BackendAPI.Models.User diff --git a/Backend/Models/User/UserSearchModel.cs b/Backend/Models/User/UserSearchModel.cs index b13418a..54f4ede 100644 --- a/Backend/Models/User/UserSearchModel.cs +++ b/Backend/Models/User/UserSearchModel.cs @@ -1,7 +1,4 @@ -using System; -using System.ComponentModel.DataAnnotations; - -namespace BackendAPI.Models.User +namespace BackendAPI.Models.User { public class UserSearchModel { diff --git a/Backend/Program.cs b/Backend/Program.cs index 617a007..0ea4112 100644 --- a/Backend/Program.cs +++ b/Backend/Program.cs @@ -1,11 +1,5 @@ using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace BackendAPI { diff --git a/Backend/Repositories/ActivityRepository.cs b/Backend/Repositories/ActivityRepository.cs index bb3cda7..94c93d8 100644 --- a/Backend/Repositories/ActivityRepository.cs +++ b/Backend/Repositories/ActivityRepository.cs @@ -112,7 +112,7 @@ public async Task AddActivity(Trip trip, Activity activity, Activity transport) transport.Trip = trip; _context.Activities.Add(transport); } - (Coordinate, String,String) CoordinateAddressName = await _googleMapsHelper.GetCoordinatesAndAddressFromPlaceId(activity.GooglePlaceId); + (Coordinate, String, String) CoordinateAddressName = await _googleMapsHelper.GetCoordinatesAndAddressFromPlaceId(activity.GooglePlaceId); activity.Latitude = CoordinateAddressName.Item1.Latitude; activity.Longitude = CoordinateAddressName.Item1.Longitude; activity.Trip = trip; @@ -132,7 +132,7 @@ public async Task AddActivity(Trip trip, Activity activity, Activity transport) public async Task GetById(int Id) { - return await _context.Activities.Where(a=>a.Id == Id).FirstOrDefaultAsync(); + return await _context.Activities.Where(a => a.Id == Id).FirstOrDefaultAsync(); } public async Task RemoveActivity(Trip trip, Activity activity) { @@ -197,14 +197,14 @@ public async Task UpdateActivity(Activity activity, ActivityUpdateModel model) throw new CustomException("The activity to update isn't in the trip date range (the beginning date is lower than the trip beginning date or the ending date is higher than the trip ending date)", ErrorType.ACTIVITY_NOT_IN_TRIP_RANGE); } //transporte. se for null, significa que é a primeira actividade do dia, logo não é preciso verificar a bound inferior - Activity ActivityBefore = await _context.Activities.Where(a=>a.Trip.Id==activity.Trip.Id && a.BeginningDate.Date == ActivityDate && a.EndingDate < activity.BeginningDate).OrderByDescending(a=>a.EndingDate).FirstOrDefaultAsync(); + Activity ActivityBefore = await _context.Activities.Where(a => a.Trip.Id == activity.Trip.Id && a.BeginningDate.Date == ActivityDate && a.EndingDate < activity.BeginningDate).OrderByDescending(a => a.EndingDate).FirstOrDefaultAsync(); //transporte. se for null, significa que é a última actividade do dia, logo não é preciso verificar a bound superior - Activity ActivityAfter = await _context.Activities.Where(a => a.Trip.Id == activity.Trip.Id && a.BeginningDate.Date == ActivityDate && a.BeginningDate > activity.EndingDate).OrderBy(a=>a.BeginningDate).FirstOrDefaultAsync(); + Activity ActivityAfter = await _context.Activities.Where(a => a.Trip.Id == activity.Trip.Id && a.BeginningDate.Date == ActivityDate && a.BeginningDate > activity.EndingDate).OrderBy(a => a.BeginningDate).FirstOrDefaultAsync(); if (ActivityBefore != null && model.BeginningDate < ActivityBefore.EndingDate) { throw new CustomException("The new beginning date cannot be lower than the previous activity ending date", ErrorType.ACTIVITY_OVERLAP); } - if(ActivityAfter != null && model.EndingDate > ActivityAfter.BeginningDate) + if (ActivityAfter != null && model.EndingDate > ActivityAfter.BeginningDate) { throw new CustomException("The new ending date cannot be lower than the next activity beginning date", ErrorType.ACTIVITY_OVERLAP); } diff --git a/Backend/Repositories/DatabaseContext.cs b/Backend/Repositories/DatabaseContext.cs index e1dadda..1596061 100644 --- a/Backend/Repositories/DatabaseContext.cs +++ b/Backend/Repositories/DatabaseContext.cs @@ -1,12 +1,13 @@ -using Microsoft.EntityFrameworkCore; -using BackendAPI.Entities; +using BackendAPI.Entities; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; namespace BackendAPI.Data { public class DatabaseContext : IdentityDbContext { - public DatabaseContext (DbContextOptions options): base(options){ + public DatabaseContext(DbContextOptions options) : base(options) + { } public DbSet User { get; set; } diff --git a/Backend/Repositories/GroupRepository.cs b/Backend/Repositories/GroupRepository.cs index ceea481..2b5a9ac 100644 --- a/Backend/Repositories/GroupRepository.cs +++ b/Backend/Repositories/GroupRepository.cs @@ -39,7 +39,7 @@ public async Task GroupHasExperiencedMember(Group group) } public async Task AddUser(Group group, User user, Guid? InviteId, bool IsManager) { - GroupBan ban = await _context.GroupBans.Where(gb=>gb.User == user && gb.Group == group).FirstOrDefaultAsync(); + GroupBan ban = await _context.GroupBans.Where(gb => gb.User == user && gb.Group == group).FirstOrDefaultAsync(); if (ban != null) { //unban user and continue join process @@ -79,9 +79,9 @@ public async Task AddUser(Group group, User user, Guid? InviteId, bool IsManager UserGroup userGroup = await GetUserGroup(group, user); if (userGroup == null) { - int NumberMembersGroup = await _context.UserGroups.CountAsync(ug=>ug.Group.Id==group.Id); + int NumberMembersGroup = await _context.UserGroups.CountAsync(ug => ug.Group.Id == group.Id); //caso não hajam gestores no grupo, o primeiro a entrar será gestor. Administrador apesar de ter role de regular será sempre administrador e pode chamar os endpoints com permissões. - UserGroup userGroupCreate = new(){ User = user, Group=group, EntranceDate = DateTime.Now, Role= NumberMembersGroup==0?UserGroupRole.MANAGER:UserGroupRole.REGULAR}; + UserGroup userGroupCreate = new() { User = user, Group = group, EntranceDate = DateTime.Now, Role = NumberMembersGroup == 0 ? UserGroupRole.MANAGER : UserGroupRole.REGULAR }; _context.UserGroups.Add(userGroupCreate); await _context.SaveChangesAsync(); group.HasExperiencedUser = await GroupHasExperiencedMember(group); @@ -131,7 +131,7 @@ public async Task Delete(Group group) group.Users.Clear(); group.Invites.Clear(); //Remover todos os utilizadores e convites das viagens e esconder todos os posts desta - foreach(Trip trip in group.Trips) + foreach (Trip trip in group.Trips) { trip.Users.Clear(); trip.Invites.Clear(); @@ -172,7 +172,7 @@ public async Task GetUserGroup(Group group, User user) public async Task InviteUser(GroupInvite groupInvite) { //novos convites apenas podem ser enviados se os anteriores tiverem sido consumidos. isto irá procurar por um convite existente - if (_context.GroupInvites.Any(gi=>gi.User.Id==groupInvite.User.Id && gi.Group.Id == groupInvite.Group.Id)) + if (_context.GroupInvites.Any(gi => gi.User.Id == groupInvite.User.Id && gi.Group.Id == groupInvite.Group.Id)) { throw new CustomException("User was already invited", ErrorType.GROUP_USER_ALREADY_INVITED); } @@ -192,7 +192,7 @@ public async Task InviteUser(GroupInvite groupInvite) await _context.SaveChangesAsync(); } - public async Task GetUserRole(Group group,User user) + public async Task GetUserRole(Group group, User user) { UserGroup ug = await GetUserGroup(group, user); if (ug == null) @@ -208,9 +208,9 @@ public async Task RemoveUser(Group group, User user) UserGroup userGroup = await GetUserGroup(group, user); if (userGroup != null) { - int NumberManagers = await _context.UserGroups.Where(ug=>ug.Role==UserGroupRole.MANAGER && ug.Group.Id == group.Id).CountAsync(); + int NumberManagers = await _context.UserGroups.Where(ug => ug.Role == UserGroupRole.MANAGER && ug.Group.Id == group.Id).CountAsync(); //um gestor não se pode demover a ele próprio, apenas a outros, logo vai haver sempre pelo menos 1 - if (NumberManagers == 1 && userGroup.Role==UserGroupRole.MANAGER) + if (NumberManagers == 1 && userGroup.Role == UserGroupRole.MANAGER) { throw new CustomException("Group only has one manager left.", ErrorType.GROUP_LAST_MANAGER_LEAVE); } @@ -348,12 +348,12 @@ public async Task BanUser(Group group, User user, string BanReason, DateTime? Ba _context.UserTrips.RemoveRange(user.Trips.Where(ut => ut.Trip.Group == group && ut.User == user)); _context.GroupInvites.RemoveRange(user.GroupInvites.Where(gi => gi.Group == group && gi.User == user)); _context.TripInvites.RemoveRange(user.TripInvites.Where(ut => ut.User == user && ut.Trip.Group == group)); - _context.GroupBans.Add(new GroupBan() { Group=group,User=user,BanReason= BanReason , BanUntil=BanUntil, BanDate = DateTime.Now}); + _context.GroupBans.Add(new GroupBan() { Group = group, User = user, BanReason = BanReason, BanUntil = BanUntil, BanDate = DateTime.Now }); if (HidePosts) { - foreach(Trip trip in group.Trips) + foreach (Trip trip in group.Trips) { - foreach(Post post in trip.Posts) + foreach (Post post in trip.Posts) { if (post.User == user) { @@ -376,7 +376,7 @@ public async Task BanUser(Group group, User user, string BanReason, DateTime? Ba public async Task UnbanUser(Group group, User user) { GroupBan ban = await _context.GroupBans.Where(gb => gb.Group == group && gb.User == user).FirstOrDefaultAsync(); - if (ban==null) + if (ban == null) { throw new CustomException("This user isn't banned", ErrorType.GROUP_USER_NOT_BANNED); } @@ -394,7 +394,7 @@ public async Task UnbanUser(Group group, User user) public async Task GetBanById(int Id) { - return await _context.GroupBans.Where(gb=>gb.Id == Id).FirstOrDefaultAsync(); + return await _context.GroupBans.Where(gb => gb.Id == Id).FirstOrDefaultAsync(); } public async Task RemoveImage(Group group) diff --git a/Backend/Repositories/IGroupRepository.cs b/Backend/Repositories/IGroupRepository.cs index 03f372c..3f2ef04 100644 --- a/Backend/Repositories/IGroupRepository.cs +++ b/Backend/Repositories/IGroupRepository.cs @@ -67,7 +67,7 @@ public interface IGroupRepository /// Group to remove an user from /// User to be removed from a group /// - Task RemoveUser(Group group,User user); + Task RemoveUser(Group group, User user); /// /// Adds an invite to an user for a group. Fails if an invite was already sent or the user is already in the group. /// diff --git a/Backend/Repositories/IUserRepository.cs b/Backend/Repositories/IUserRepository.cs index 32470e7..deb3ea6 100644 --- a/Backend/Repositories/IUserRepository.cs +++ b/Backend/Repositories/IUserRepository.cs @@ -1,11 +1,11 @@ using BackendAPI.Entities; -using System.Threading.Tasks; -using System.Collections.Generic; -using System; +using BackendAPI.Entities.Enums; using BackendAPI.Models.User; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Http; -using BackendAPI.Entities.Enums; +using Microsoft.AspNetCore.Identity; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace BackendAPI.Repositories { diff --git a/Backend/Repositories/InformationRepository.cs b/Backend/Repositories/InformationRepository.cs index 528bd71..2ea58fb 100644 --- a/Backend/Repositories/InformationRepository.cs +++ b/Backend/Repositories/InformationRepository.cs @@ -1,10 +1,7 @@ using AutoMapper; using BackendAPI.Data; using BackendAPI.Entities; -using BackendAPI.Models.Information; -using BackendAPI.Models.Post; using Microsoft.EntityFrameworkCore; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -28,13 +25,13 @@ public async Task GetRecommendations(User user) if (user == null) { recommendation.latestPostsFriends = new List(); - recommendation.latestPostsCommunity = await _context.Posts.Where(p => !p.IsHidden && !p.Trip.IsPrivate && !p.Trip.Group.IsPrivate).OrderByDescending(p=>p.PublishedDate).Take(25).ToListAsync(); + recommendation.latestPostsCommunity = await _context.Posts.Where(p => !p.IsHidden && !p.Trip.IsPrivate && !p.Trip.Group.IsPrivate).OrderByDescending(p => p.PublishedDate).Take(25).ToListAsync(); recommendation.featuredGroups = await _context.Groups.Where(g => g.IsFeatured && !g.IsPrivate). OrderByDescending(g => g.Users.Count). - ThenByDescending(g=>g.CreationDate). + ThenByDescending(g => g.CreationDate). Take(12).ToListAsync(); - recommendation.recommendedGroups = await _context.Groups.OrderByDescending(g=>g.Users.Count).ThenByDescending(g => g.CreationDate).Take(12).ToListAsync(); - recommendation.recommendedTrips = await _context.Trips.Where(t=>!t.IsPrivate && !t.Group.IsPrivate ).OrderByDescending(t=>t.Users.Count).ThenBy(t=>t.BeginningDate).Take(12).ToListAsync(); + recommendation.recommendedGroups = await _context.Groups.OrderByDescending(g => g.Users.Count).ThenByDescending(g => g.CreationDate).Take(12).ToListAsync(); + recommendation.recommendedTrips = await _context.Trips.Where(t => !t.IsPrivate && !t.Group.IsPrivate).OrderByDescending(t => t.Users.Count).ThenBy(t => t.BeginningDate).Take(12).ToListAsync(); } else { @@ -47,20 +44,20 @@ public async Task GetRecommendations(User user) recommendation.latestPostsCommunity = await _context.Posts.Where(p => !p.IsHidden && !(p.User == user) && - !(p.Trip.IsPrivate && !p.Trip.Users.Any(ut=>ut.User == user))&& - !(p.Trip.Group.IsPrivate && !p.Trip.Group.Users.Any(ug=>ug.User==user)) + !(p.Trip.IsPrivate && !p.Trip.Users.Any(ut => ut.User == user)) && + !(p.Trip.Group.IsPrivate && !p.Trip.Group.Users.Any(ug => ug.User == user)) ).OrderByDescending(p => p.PublishedDate).Take(25).ToListAsync(); recommendation.featuredGroups = await _context.Groups.Where(g => g.IsFeatured && - !g.Users.Any(ug=>ug.User==user) && !g.IsPrivate + !g.Users.Any(ug => ug.User == user) && !g.IsPrivate ).OrderByDescending(g => g.Users.Count).ThenByDescending(g => g.CreationDate).Take(12).ToListAsync(); recommendation.recommendedGroups = await _context.Groups.Where(g => - !g.Users.Any(u=>u.User==user) + !g.Users.Any(u => u.User == user) ).OrderByDescending(g => g.Users.Count).ThenByDescending(g => g.CreationDate).Take(12).ToListAsync(); recommendation.recommendedTrips = await _context.Trips.Where(t => !t.IsPrivate && - !(t.Group.IsPrivate && !t.Group.Users.Any(ug=>ug.User==user))&& - !t.Users.Any(ut=>ut.User==user) && + !(t.Group.IsPrivate && !t.Group.Users.Any(ug => ug.User == user)) && + !t.Users.Any(ut => ut.User == user) && !t.IsCompleted ).OrderByDescending(t => t.Users.Count).ThenBy(t => t.BeginningDate).Take(12).ToListAsync(); } @@ -71,15 +68,15 @@ public async Task GetRecommendations(User user) public async Task GetStatistics() { Statistic statistic = new(); - statistic.GroupsByNumberUsers = await _context.Groups.OrderByDescending(g=>g.Users.Count).Take(10).ToDictionaryAsync(g=>g.Name, g=>g.Users.Count); - statistic.TripsByNumberUsers = await _context.Trips.OrderByDescending(t => t.Users.Count).Take(10).ToDictionaryAsync(t=> t.Name, t=>t.Users.Count); - statistic.MostVisitedPlaces = await _context.Activities.Where(a=>a.ActivityType!=Entities.Enums.ActivityType.TRANSPORT&&a.RealAddress!=null).GroupBy(a=>a.RealAddress).Select(a=> new {a.Key,Count=a.Count()}).OrderByDescending(a=>a.Count).Take(10).ToDictionaryAsync(a=>a.Key, a=>a.Count); + statistic.GroupsByNumberUsers = await _context.Groups.OrderByDescending(g => g.Users.Count).Take(10).ToDictionaryAsync(g => g.Name, g => g.Users.Count); + statistic.TripsByNumberUsers = await _context.Trips.OrderByDescending(t => t.Users.Count).Take(10).ToDictionaryAsync(t => t.Name, t => t.Users.Count); + statistic.MostVisitedPlaces = await _context.Activities.Where(a => a.ActivityType != Entities.Enums.ActivityType.TRANSPORT && a.RealAddress != null).GroupBy(a => a.RealAddress).Select(a => new { a.Key, Count = a.Count() }).OrderByDescending(a => a.Count).Take(10).ToDictionaryAsync(a => a.Key, a => a.Count); statistic.GroupsByAverageDistance = await _context.Groups.OrderByDescending(g => g.AverageTripDistance).Take(10).ToDictionaryAsync(g => g.Name, g => g.AverageTripDistance); statistic.GroupsByAverageCost = await _context.Groups.OrderByDescending(g => g.AverageTripCost).Take(10).ToDictionaryAsync(g => g.Name, g => g.AverageTripCost); statistic.TripsByTotalDistance = await _context.Trips.OrderByDescending(t => t.TotalDistance).Take(10).ToDictionaryAsync(t => t.Name, t => t.TotalDistance); statistic.TripsByTotalCost = await _context.Trips.OrderByDescending(t => t.ExpectedBudget).Take(10).ToDictionaryAsync(t => t.Name, t => t.ExpectedBudget); - statistic.RankingUserDistribution = await _context.User.GroupBy(u=>u.Ranking.Name).Select(u=> new {u.Key,Count=u.Count()}).OrderByDescending(u=>u.Count).Take(10).ToDictionaryAsync(u=>u.Key,u=>u.Count); - statistic.TransportTypeDistribution = await _context.Activities.Where(a=>a.ActivityType==Entities.Enums.ActivityType.TRANSPORT).GroupBy(a=>a.TransportType).Select(a => new { a.Key, Count = a.Count() }).OrderByDescending(a => a.Count).Take(10).ToDictionaryAsync(a => a.Key, a => a.Count); + statistic.RankingUserDistribution = await _context.User.GroupBy(u => u.Ranking.Name).Select(u => new { u.Key, Count = u.Count() }).OrderByDescending(u => u.Count).Take(10).ToDictionaryAsync(u => u.Key, u => u.Count); + statistic.TransportTypeDistribution = await _context.Activities.Where(a => a.ActivityType == Entities.Enums.ActivityType.TRANSPORT).GroupBy(a => a.TransportType).Select(a => new { a.Key, Count = a.Count() }).OrderByDescending(a => a.Count).Take(10).ToDictionaryAsync(a => a.Key, a => a.Count); statistic.ActivityTypeDistribution = await _context.Activities.Where(a => a.ActivityType != Entities.Enums.ActivityType.TRANSPORT).GroupBy(a => a.ActivityType).Select(a => new { a.Key, Count = a.Count() }).OrderByDescending(a => a.Count).Take(10).ToDictionaryAsync(a => a.Key, a => a.Count); return statistic; diff --git a/Backend/Repositories/PostRepository.cs b/Backend/Repositories/PostRepository.cs index 4098429..b355be0 100644 --- a/Backend/Repositories/PostRepository.cs +++ b/Backend/Repositories/PostRepository.cs @@ -66,7 +66,7 @@ public async Task Create(Post post) public async Task Delete(Post post) { //Eliminar todos os anexos - foreach(Attachment attachment in post.Attachments) + foreach (Attachment attachment in post.Attachments) { await _storageHelper.Delete(attachment.StorageName); } @@ -101,7 +101,7 @@ public async Task Update(Post post, PostUpdateModel model) public async Task GetAttachmentById(Guid FileId) { - return await _context.Attachments.Where(p=>p.Id==FileId).FirstOrDefaultAsync(); + return await _context.Attachments.Where(p => p.Id == FileId).FirstOrDefaultAsync(); } } } diff --git a/Backend/Repositories/RankingRepository.cs b/Backend/Repositories/RankingRepository.cs index 2454c31..9f99943 100644 --- a/Backend/Repositories/RankingRepository.cs +++ b/Backend/Repositories/RankingRepository.cs @@ -23,7 +23,7 @@ private async Task UpdateUsersRankings() foreach (User user in _context.Users) { double kilometers = user.TravelledKilometers; - foreach(Ranking r in ranking_list) + foreach (Ranking r in ranking_list) { if (kilometers >= r.MinimumKilometers) { @@ -38,9 +38,9 @@ private async Task UpdateUsersRankings() } public async Task Create(Ranking ranking) { - + //não se pode criar um ranking com o mesmo número de quilómetros que outro - if (await _context.Rankings.AnyAsync(r=>r.MinimumKilometers == ranking.MinimumKilometers)) + if (await _context.Rankings.AnyAsync(r => r.MinimumKilometers == ranking.MinimumKilometers)) { throw new CustomException(ErrorType.RANKING_EXISTS); } @@ -55,7 +55,7 @@ public async Task Create(Ranking ranking) public async Task Delete(Ranking ranking) { - if (ranking.MinimumKilometers == 0 || await _context.Rankings.CountAsync()==1) + if (ranking.MinimumKilometers == 0 || await _context.Rankings.CountAsync() == 1) { throw new CustomException(ErrorType.RANKING_DEFAULT_DELETE); } @@ -95,7 +95,7 @@ public async Task Update(Ranking ranking, RankingUpdateModel model) public async Task GetDefaultRanking() { - return await _context.Rankings.Where(r=>r.MinimumKilometers==0).FirstOrDefaultAsync(); + return await _context.Rankings.Where(r => r.MinimumKilometers == 0).FirstOrDefaultAsync(); } public async Task CreateDefaultRanking() diff --git a/Backend/Repositories/TripRepository.cs b/Backend/Repositories/TripRepository.cs index 0be2bcf..ec28a02 100644 --- a/Backend/Repositories/TripRepository.cs +++ b/Backend/Repositories/TripRepository.cs @@ -33,8 +33,8 @@ public TripRepository(IGroupRepository groupRepository, DatabaseContext context, public async Task RecalculateTripDistanceAndBudget(Trip trip) { double distance = 0; - double budget = _context.Activities.Where(a=>a.Trip.Id==trip.Id).Sum(a=>a.ExpectedBudget); - List Activities = trip.Activities.Where(t => t.ActivityType != ActivityType.TRANSPORT).OrderBy(i=>i.Id).ToList(); + double budget = _context.Activities.Where(a => a.Trip.Id == trip.Id).Sum(a => a.ExpectedBudget); + List Activities = trip.Activities.Where(t => t.ActivityType != ActivityType.TRANSPORT).OrderBy(i => i.Id).ToList(); for (int i = 0; i < Activities.Count - 1; i++) { distance += GeoCalculator.GetDistance( @@ -57,7 +57,7 @@ public async Task RecalculateTripDistanceAndBudget(Trip trip) private async Task UpdateUsersRankingsAndDistance(Trip trip) { List ranking_list = await _context.Rankings.OrderByDescending(cr => cr.MinimumKilometers).ToListAsync(); - foreach (User user in trip.Users.Select(t=>t.User)) + foreach (User user in trip.Users.Select(t => t.User)) { user.TravelledKilometers += trip.TotalDistance; foreach (Ranking r in ranking_list) @@ -77,8 +77,8 @@ private async Task UpdateUsersRankingsAndDistance(Trip trip) private async Task UpdateAverageCostAndDistanceTripGroup(Group group) { int NumberTripsCompleted = group.Trips.Count(t => t.IsCompleted); - double TotalCostTripsCompleted = group.Trips.Where(t=>t.IsCompleted).Sum(t => t.ExpectedBudget); - double TotalDistanceTripsCompleted = group.Trips.Where(t=>t.IsCompleted).Sum(t => t.TotalDistance); + double TotalCostTripsCompleted = group.Trips.Where(t => t.IsCompleted).Sum(t => t.ExpectedBudget); + double TotalDistanceTripsCompleted = group.Trips.Where(t => t.IsCompleted).Sum(t => t.TotalDistance); if (NumberTripsCompleted == 0) { group.AverageTripCost = 0; @@ -86,8 +86,8 @@ private async Task UpdateAverageCostAndDistanceTripGroup(Group group) } else { - group.AverageTripCost = (double) (TotalCostTripsCompleted / NumberTripsCompleted); - group.AverageTripDistance = (double) (TotalDistanceTripsCompleted / NumberTripsCompleted); + group.AverageTripCost = (double)(TotalCostTripsCompleted / NumberTripsCompleted); + group.AverageTripDistance = (double)(TotalDistanceTripsCompleted / NumberTripsCompleted); } _context.Groups.Update(group); @@ -135,7 +135,7 @@ public async Task Update(Trip trip, TripDetailsUpdateModel model) * Temos que verificar se ao alterar a data de início ou de fim, estamos a deixar actividades existentes para trás. Exemplo: * Puxar a atividade de início para a frente se já existirem algumas atrás, ou a de fim para trás */ - if(_context.Activities.Any(a=>a.Trip.Id == trip.Id && (a.BeginningDate < model.BeginningDate || a.EndingDate > model.EndingDate))) + if (_context.Activities.Any(a => a.Trip.Id == trip.Id && (a.BeginningDate < model.BeginningDate || a.EndingDate > model.EndingDate))) { throw new CustomException("Activities already exist before the beginning date or after the ending date", ErrorType.TRIP_DATE_EXISTING_ACTIVITIES); } @@ -143,7 +143,7 @@ public async Task Update(Trip trip, TripDetailsUpdateModel model) if ( (model.BeginningDate.Date != trip.BeginningDate.Date || model.EndingDate.Date != trip.EndingDate.Date) && (model.BeginningDate.Date < DateTime.Now.Date || model.EndingDate.Date < DateTime.Now.Date || model.BeginningDate > model.EndingDate) && - !(model.IsCompleted||trip.IsCompleted) + !(model.IsCompleted || trip.IsCompleted) ) { throw new CustomException("The beginning date of the trip must be in the future and the beginning date must be before the ending date", ErrorType.TRIP_DATE_INVALID); @@ -198,7 +198,7 @@ public async Task AddUser(Trip trip, User user, Guid? InviteId, bool IsManager) } //é possível juntar-se a um grupo ou viagem que não seja privado com convite - if (invite!=null) + if (invite != null) { WasInvited = true; _context.TripInvites.Remove(invite); @@ -270,7 +270,7 @@ public async Task InviteUser(TripInvite tripInvite) { throw new CustomException("This user is already on this trip", ErrorType.TRIP_USER_ALREADY_PRESENT); } - if (!(_context.UserGroups.Any(g => g.User.Id == tripInvite.User.Id && g.Group.Id==tripInvite.Trip.Group.Id))) + if (!(_context.UserGroups.Any(g => g.User.Id == tripInvite.User.Id && g.Group.Id == tripInvite.Trip.Group.Id))) { throw new CustomException("This user cannot join this trip because he doesn't belong to the group.", ErrorType.TRIP_USER_NOT_PRESENT_GROUP); } @@ -288,7 +288,7 @@ public async Task InviteUser(TripInvite tripInvite) public async Task> Search(TripSearchModel model) { - if (model.TripDestination == "" && model.TripDescription == "" && model.TripName == "") + if (model.TripDestination == "" && model.TripDescription == "" && model.TripName == "") { return new List(); } @@ -296,8 +296,8 @@ public async Task> Search(TripSearchModel model) !trip.IsCompleted && ( (model.TripName != "" && trip.Name.ToLower().Contains(model.TripName.ToLower())) || - (model.TripDescription!="" && trip.Description.ToLower().Contains(model.TripDescription.ToLower())) || - (model.TripDestination!="" && trip.Activities.Any(a => a.RealAddress.ToLower().Contains(model.TripDestination.ToLower()) || a.Description.ToLower().Contains(model.TripDestination.ToLower()))) + (model.TripDescription != "" && trip.Description.ToLower().Contains(model.TripDescription.ToLower())) || + (model.TripDestination != "" && trip.Activities.Any(a => a.RealAddress.ToLower().Contains(model.TripDestination.ToLower()) || a.Description.ToLower().Contains(model.TripDestination.ToLower()))) ) ).ToListAsync(); } diff --git a/Backend/Repositories/UserRepository.cs b/Backend/Repositories/UserRepository.cs index ea688c2..6c3dcaa 100644 --- a/Backend/Repositories/UserRepository.cs +++ b/Backend/Repositories/UserRepository.cs @@ -52,9 +52,9 @@ public async Task Delete(User user) user.Following.Clear(); user.Groups.Clear(); user.Trips.Clear(); - foreach(Post post in user.Posts) + foreach (Post post in user.Posts) { - foreach(Attachment attachment in post.Attachments) + foreach (Attachment attachment in post.Attachments) { await _storageHelper.Delete(attachment.StorageName); } @@ -91,9 +91,9 @@ public async Task> Search(UserSearchModel userSearch) { return new List(); } - return await userManager.Users.Where(user => + return await userManager.Users.Where(user => user.Name.ToLower().Contains(userSearch.NameOrEmail.ToLower()) || - user.Email.ToLower() == userSearch.NameOrEmail.ToLower() || + user.Email.ToLower() == userSearch.NameOrEmail.ToLower() || user.UserName.ToLower().Contains(userSearch.NameOrEmail.ToLower()) ).ToListAsync(); } @@ -179,7 +179,7 @@ public async Task UpdateImage(User user, IFormFile file) public async Task UpdateUserRoles(User user, List roles) { - foreach(UserRole role in roles) + foreach (UserRole role in roles) { if (!Enum.IsDefined(role)) { diff --git a/Backend/Startup.cs b/Backend/Startup.cs index e8cd859..b18c92a 100644 --- a/Backend/Startup.cs +++ b/Backend/Startup.cs @@ -1,23 +1,23 @@ -using Microsoft.AspNetCore.Builder; +using BackendAPI.Data; +using BackendAPI.Entities; +using BackendAPI.Helpers; +using BackendAPI.Repositories; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpOverrides; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; using System; -using Microsoft.EntityFrameworkCore; -using BackendAPI.Data; -using BackendAPI.Repositories; -using BackendAPI.Entities; -using Microsoft.AspNetCore.Identity; -using System.Text; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.IdentityModel.Tokens; -using BackendAPI.Helpers; -using Microsoft.AspNetCore.HttpOverrides; -using System.Reflection; -using System.IO; using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Text; namespace BackendAPI { @@ -46,7 +46,8 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddIdentity(options => { + services.AddIdentity(options => + { options.SignIn.RequireConfirmedEmail = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; @@ -61,7 +62,8 @@ public void ConfigureServices(IServiceCollection services) options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; - }).AddJwtBearer(options => { + }).AddJwtBearer(options => + { options.SaveToken = true; options.RequireHttpsMetadata = false; options.TokenValidationParameters = new TokenValidationParameters()