-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 3ac8542 Merge: 9f8efe2 c371eb9 Author: DustSwiffer Date: Tue Jul 23 21:05:20 2024 +0200 Merge branch 'feature/user-related-endpoints' into develop commit c371eb9 Author: DustSwiffer Date: Tue Jul 23 21:04:28 2024 +0200 Small fix within the UserService and UpdateLastSeen unit tests added commit fb4ad70 Author: DustSwiffer Date: Tue Jul 23 20:54:21 2024 +0200 Unit tests added for GetUserProfile commit 5127a94 Author: DustSwiffer Date: Tue Jul 23 00:43:09 2024 +0200 User last seen is being created or updated & shown in the user profile commit 704738f Author: DustSwiffer Date: Mon Jul 22 22:41:02 2024 +0200 user profile added
- Loading branch information
1 parent
9f8efe2
commit 04e10b9
Showing
41 changed files
with
1,706 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using AdvancedAPI.Data.ViewModels.User; | ||
|
||
namespace Business.Services.Interfaces; | ||
|
||
/// <summary> | ||
/// User service. | ||
/// </summary> | ||
public interface IUserService | ||
{ | ||
/// <summary> | ||
/// Gets the user profile of the given user id. | ||
/// </summary> | ||
public Task<UserProfileResponseModel?> GetUserProfile(string userId); | ||
|
||
/// <summary> | ||
/// Updates the last seen state of the user. | ||
/// </summary> | ||
public Task UpdateLastSeen(string userId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System.Globalization; | ||
using AdvancedAPI.Data.Models; | ||
using AdvancedAPI.Data.Repositories.Interfaces; | ||
using AdvancedAPI.Data.ViewModels.User; | ||
using AutoMapper; | ||
using Business.Services.Interfaces; | ||
|
||
namespace Business.Services; | ||
|
||
/// <inheritdoc /> | ||
public class UserService : IUserService | ||
{ | ||
private readonly IIdentityRepository _identityRepository; | ||
private readonly IGenderRepository _genderRepository; | ||
private readonly ILastSeenRepository _lastSeenRepository; | ||
private readonly IMapper _mapper; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public UserService( | ||
IMapper mapper, | ||
IIdentityRepository identityRepository, | ||
IGenderRepository genderRepository, | ||
ILastSeenRepository lastSeenRepository) | ||
{ | ||
_identityRepository = identityRepository; | ||
_genderRepository = genderRepository; | ||
_lastSeenRepository = lastSeenRepository; | ||
_mapper = mapper; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<UserProfileResponseModel?> GetUserProfile(string userId) | ||
{ | ||
User? user = await _identityRepository.GetUserById(userId); | ||
|
||
if (user == null) | ||
{ | ||
return null; | ||
} | ||
|
||
user.Gender = await _genderRepository.GetByIdAsync(user.GenderId); | ||
|
||
UserProfileResponseModel responseModel = _mapper.Map<UserProfileResponseModel>(user); | ||
|
||
responseModel.Birthday = user.DateOfBirth.ToString("MMMM d"); | ||
LastSeen? lastSeen = await _lastSeenRepository.GetByUserId(user.Id); | ||
|
||
responseModel.LastSeen = lastSeen != null ? lastSeen.DateTime.ToString(CultureInfo.InvariantCulture) : "unknown"; | ||
return responseModel; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task UpdateLastSeen(string userId) | ||
{ | ||
LastSeen? lastSeen = await _lastSeenRepository.GetByUserId(userId); | ||
|
||
if (lastSeen != null) | ||
{ | ||
lastSeen.DateTime = DateTime.Now; | ||
_lastSeenRepository.Update(lastSeen); | ||
} | ||
else | ||
{ | ||
await _lastSeenRepository.AddAsync( | ||
new LastSeen() | ||
{ | ||
UserId = userId, | ||
DateTime = DateTime.Now, | ||
}); | ||
} | ||
|
||
await _lastSeenRepository.SaveAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using AdvancedAPI.Data.Repositories; | ||
using AdvancedAPI.Data.Repositories.Interfaces; | ||
|
||
namespace AdvancedAPI.Data; | ||
|
||
/// <summary> | ||
/// Service extension used to prepare the data layer for usage. | ||
/// </summary> | ||
public static class DataExtension | ||
{ | ||
/// <summary> | ||
/// Registers everything data layer related. | ||
/// </summary> | ||
public static void AddDataRepositories(this IServiceCollection services) | ||
{ | ||
services.AddScoped<IIdentityRepository, IdentityRepository>(); | ||
services.AddScoped<INewsArticleRepository, NewsArticleRepository>(); | ||
services.AddScoped<IGenderRepository, GenderRepository>(); | ||
services.AddScoped<ILastSeenRepository, LastSeenRepository>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.