Skip to content

Commit

Permalink
(#402) web: update the studnets service
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Sep 2, 2024
1 parent b5e4ad2 commit 369b84d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace MiniSpace.Web.Areas.Events.CommandsDto
{
public class ViewEventCommand
{
public Guid UserId { get; set; }
public Guid EventId { get; set; }

public ViewEventCommand(Guid userId, Guid eventId)
{
UserId = userId;
EventId = eventId;
}
}
}
14 changes: 6 additions & 8 deletions MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ public Task<EventRatingDto> GetEventRatingAsync(Guid eventId)
return _httpClient.GetAsync<EventRatingDto>($"events/{eventId}/rating");
}

// public Task<HttpResponse<PagedResult<IEnumerable<EventDto>>>> SearchEventsAsync(SearchEvents command)
// {
// _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
// return _httpClient.PostAsync<SearchEvents, PagedResult<IEnumerable<EventDto>>>("events/search", command);
// }

public Task<PagedResult<EventDto>> SearchEventsAsync(SearchEvents command)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
Expand Down Expand Up @@ -124,7 +118,6 @@ public Task<PagedResult<EventDto>> SearchEventsAsync(SearchEvents command)

var queryString = "?" + string.Join("&", queryParams);

// Return the correct type based on your API response
return _httpClient.GetAsync<PagedResult<EventDto>>($"events/search{queryString}");
}

Expand All @@ -136,7 +129,6 @@ public Task<HttpResponse<PagedResult<IEnumerable<EventDto>>>> SearchOrganizerEve
return _httpClient.PostAsync<SearchOrganizerEvents, PagedResult<IEnumerable<EventDto>>>("events/search/organizer", command);
}

// Implementations for participant-related methods
public Task<EventParticipantsDto> GetEventParticipantsAsync(Guid eventId)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
Expand Down Expand Up @@ -178,5 +170,11 @@ public async Task<PagedResult<EventDto>> GetUserEventsFeedAsync(Guid userId, int
return await _httpClient.GetAsync<PagedResult<EventDto>>($"events/users/{userId}/feed{queryString}");
}

public Task ViewEventAsync(ViewEventCommand command)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PostAsync<ViewEventCommand, object>($"events/{command.EventId}/view", command);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public interface IEventsService
Task<PagedResult<EventDto>> GetMyEventsAsync(Guid organizerId, int page, int pageSize);
Task<PagedResult<EventDto>> GetUserEventsAsync(Guid userId, int page, int pageSize, string engagementType);
Task<PagedResult<EventDto>> GetUserEventsFeedAsync(Guid userId, int pageNumber, int pageSize, string sortBy, string direction);
Task ViewEventAsync(ViewEventCommand command);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MiniSpace.Web.Areas.Students.CommandsDto
{
public class ViewUserProfileCommand
{
public Guid UserId { get; }
public Guid UserProfileId { get; }

public ViewUserProfileCommand(Guid userId, Guid userProfileId)
{
UserId = userId;
UserProfileId = userProfileId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MiniSpace.Web.DTO;
using MiniSpace.Web.DTO.Interests;
using MiniSpace.Web.DTO.Languages;
using MiniSpace.Web.DTO.Views;
using MiniSpace.Web.HttpClients;

namespace MiniSpace.Web.Areas.Students
Expand Down Expand Up @@ -50,5 +51,8 @@ Task UpdateStudentLanguagesAndInterestsAsync(

Task<bool> IsUserOnlineAsync(Guid studentId);

Task ViewUserProfileAsync(Guid userId, Guid userProfileId);

Task<PaginatedResponseDto<UserProfileViewDto>> GetUserProfileViewsAsync(Guid userId, int pageNumber, int pageSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using System.Threading.Tasks;
using MiniSpace.Web.Areas.Identity;
using MiniSpace.Web.Areas.Notifications;
using MiniSpace.Web.Areas.Students.CommandsDto;
using MiniSpace.Web.DTO;
using MiniSpace.Web.DTO.Interests;
using MiniSpace.Web.DTO.Languages;
using MiniSpace.Web.DTO.Views;
using MiniSpace.Web.HttpClients;

namespace MiniSpace.Web.Areas.Students
Expand Down Expand Up @@ -209,8 +211,27 @@ public async Task UpdateStudentLanguagesAndInterestsAsync(

public async Task<bool> IsUserOnlineAsync(Guid studentId)
{
// Assuming the NotificationsService has a method to check if a user is connected
return await _notificationsService.IsUserConnectedAsync(studentId);
}

public async Task ViewUserProfileAsync(Guid userId, Guid userProfileId)
{
var accessToken = await _identityService.GetAccessTokenAsync();
_httpClient.SetAccessToken(accessToken);

var command = new ViewUserProfileCommand(userId, userProfileId);
await _httpClient.PostAsync("students/profiles/users/{userProfileId}/view", command);
}

public async Task<PaginatedResponseDto<UserProfileViewDto>> GetUserProfileViewsAsync(Guid userId, int pageNumber, int pageSize)
{
var accessToken = await _identityService.GetAccessTokenAsync();
_httpClient.SetAccessToken(accessToken);

var queryString = $"?pageNumber={pageNumber}&pageSize={pageSize}";
return await _httpClient.GetAsync<PaginatedResponseDto<UserProfileViewDto>>($"students/profiles/users/{userId}/views/paginated{queryString}");
}


}
}
16 changes: 16 additions & 0 deletions MiniSpace.Web/src/MiniSpace.Web/DTO/Views/UserProfileViewDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MiniSpace.Web.DTO.Views
{
public class UserProfileViewDto
{
public Guid UserProfileId { get; set; }
public DateTime Date { get; set; }
public string IpAddress { get; set; }
public string DeviceType { get; set; }
public string OperatingSystem { get; set; }
}
}

0 comments on commit 369b84d

Please sign in to comment.