Skip to content

Commit

Permalink
✨ Mobile | Link company URL (#1059)
Browse files Browse the repository at this point in the history
* Initial company url code

* Cleanup

* Update name

* Update title

* Cleanup

* Show title

* Update settings page

* Add comment

* Add company constant

* Fix width on tablets
  • Loading branch information
zacharykeeping authored Sep 26, 2024
1 parent 76db7a7 commit 87ae1a8
Show file tree
Hide file tree
Showing 33 changed files with 1,636 additions and 759 deletions.
20 changes: 19 additions & 1 deletion src/ApiClient/Services/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Task<UserPendingRedemptionsViewModel> GetUserPendingRedemptions(int userId,
Task<int> UpsertUserSocialMediaIdAsync(int achievementId, string socialMediaUserProfile, CancellationToken cancellationToken = default);

Task<UserSocialMediaIdDto?> GetSocialMediaId(int userId, int socialMediaPlatformId, CancellationToken cancellationToken = default);

Task<UserSocialMediaDto?> GetSocialMedia(int userId, CancellationToken cancellationToken = default);
}

public class UserService : IUserService
Expand Down Expand Up @@ -219,7 +221,23 @@ public async Task<int> UpsertUserSocialMediaIdAsync(int achievementId, string so
}

var responseContent = await result.Content.ReadAsStringAsync(cancellationToken);
throw new Exception($"Failed to upsert social media: {responseContent}");
throw new Exception($"Failed to get social media id: {responseContent}");
}

public async Task<UserSocialMediaDto?> GetSocialMedia(int userId, CancellationToken cancellationToken = default)
{
var result = await _httpClient.GetAsync(
$"{_baseRoute}SocialMedia?userId={userId}",
cancellationToken);

if (result.IsSuccessStatusCode)
{
var response = await result.Content.ReadFromJsonAsync<UserSocialMediaDto>(cancellationToken: cancellationToken);
return response;
}

var responseContent = await result.Content.ReadAsStringAsync(cancellationToken);
throw new Exception($"Failed to get social media: {responseContent}");
}

public async Task<NewUsersViewModel> GetNewUsers(LeaderboardFilter filter, bool filterStaff, CancellationToken cancellationToken = default)
Expand Down
9 changes: 8 additions & 1 deletion src/Application/ActivityFeed/Queries/GetActivitiesQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public async Task<ActivityFeedViewModel> Handle(GetActivitiesQuery request, Canc

userAchievements = await dbContext.UserAchievements
.Include(u => u.User)
.ThenInclude(u => u.SocialMediaIds)
.ThenInclude(sm => sm.SocialMediaPlatform)
.Include(a => a.Achievement)
.OrderByDescending(x => x.AwardedAt)
.Where(x => friendIds.Contains(x.UserId))
Expand All @@ -93,6 +95,8 @@ public async Task<ActivityFeedViewModel> Handle(GetActivitiesQuery request, Canc
{
userAchievements = await dbContext.UserAchievements
.Include(u => u.User)
.ThenInclude(u => u.SocialMediaIds)
.ThenInclude(sm => sm.SocialMediaPlatform)
.Include(a => a.Achievement)
.OrderByDescending(x => x.AwardedAt)
.Skip(skip)
Expand All @@ -103,11 +107,14 @@ public async Task<ActivityFeedViewModel> Handle(GetActivitiesQuery request, Canc
var feed = userAchievements.Select(userAchievement =>
{
var staff = staffDetails.FirstOrDefault(s => s.Email == userAchievement.User.Email);
var company = userAchievement.User.SocialMediaIds
.FirstOrDefault(s => s.SocialMediaPlatform.Name == "Company")?.SocialMediaUserId;
return new ActivityFeedItemDto
{
UserAvatar = userAchievement.User.Avatar ?? string.Empty,
UserName = userAchievement.User.FullName ?? string.Empty,
UserTitle = staff?.Title ?? "Community",
UserTitle = staff?.Title ?? company ?? "Community",
UserId = userAchievement.User.Id,
Achievement = new UserAchievementDto
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public async Task<LeaderboardViewModel> Handle(GetLeaderboardListQuery request,
var users = await _context.Users
.Where(u => u.Activated)
.Include(u => u.UserAchievements)
.ThenInclude(ua => ua.Achievement)
.ThenInclude(ua => ua.Achievement)
.Include(u => u.SocialMediaIds)
.ThenInclude(s => s.SocialMediaPlatform)
.Where(u => !string.IsNullOrWhiteSpace(u.FullName))
.Select(u => new LeaderboardUserDto(u, DateTime.Now.FirstDayOfWeek()))
.ToListAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using SSW.Rewards.Shared.DTOs.Users;

namespace Microsoft.Extensions.DependencyInjection.Users.Queries.GetSocialMediaId;

public class GetSocialMediaQuery : IRequest<UserSocialMediaDto>
{
public int UserId { get; set; }
}

public class GetSocialMediaQueryHandler(IApplicationDbContext context) : IRequestHandler<GetSocialMediaQuery, UserSocialMediaDto>
{
public async Task<UserSocialMediaDto> Handle(GetSocialMediaQuery request, CancellationToken cancellationToken)
{
var socialMedia = await context.UserSocialMediaIds
.Where(x => x.UserId == request.UserId)
.OrderByDescending(x => x.CreatedUtc)
.Select(x => new UserSocialMediaIdDto
{
SocialMediaUserId = x.SocialMediaUserId,
SocialMediaPlatformId = x.SocialMediaPlatformId
})
.ToListAsync(cancellationToken: cancellationToken);

return new UserSocialMediaDto { SocialMedia = socialMedia };
}
}
13 changes: 13 additions & 0 deletions src/Common/DTOs/Leaderboard/LeaderboardUserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class LeaderboardUserDto
public int PointsThisMonth { get; set; }
public int PointsThisYear { get; set; }
public int Balance => TotalPoints - PointsClaimed;
public string Title { get; set; }

public LeaderboardUserDto() {}

Expand Down Expand Up @@ -45,5 +46,17 @@ public LeaderboardUserDto(User user, DateTime firstDayOfWeek)
PointsThisYear = user.UserAchievements
.Where(ua => ua.AwardedAt.Year == DateTime.Now.Year)
.Sum(ua => ua.Achievement.Value);

var company = user.SocialMediaIds.FirstOrDefault(s => s.SocialMediaPlatform.Name == "Company")
?.SocialMediaUserId;

if (!string.IsNullOrEmpty(company))
{
Title = company;
}
else
{
Title = user.Email?.EndsWith("ssw.com.au") == true ? "SSW" : "Community";
}
}
}
6 changes: 6 additions & 0 deletions src/Common/DTOs/Users/UserSocialMediaDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SSW.Rewards.Shared.DTOs.Users;

public class UserSocialMediaDto
{
public List<UserSocialMediaIdDto> SocialMedia { get; set; } = [];
}
Loading

0 comments on commit 87ae1a8

Please sign in to comment.