Skip to content

Commit

Permalink
Merge pull request #77 from SaintAngeLs/dev
Browse files Browse the repository at this point in the history
(#71) Merge the current prgress to the main branch
  • Loading branch information
SaintAngeLs committed Apr 21, 2024
2 parents 8855e13 + 9a0dd61 commit 0661ecc
Show file tree
Hide file tree
Showing 59 changed files with 1,475 additions and 282 deletions.
78 changes: 75 additions & 3 deletions MiniSpace.APIGateway/src/MiniSpace.APIGateway/ntrada.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ modules:
downstream: identity-service/sign-in
auth: false

- upstream: /users/{userId}/organizer-rights
method: POST
use: downstream
downstream: identity-service/users/{userId}/organizer-rights
auth: true
claims:
role: admin

- upstream: /users/{userId}/organizer-rights
method: DELETE
use: downstream
downstream: identity-service/users/{userId}/organizer-rights
auth: true
claims:
role: admin

- upstream: /users/{userId}/ban
method: POST
use: downstream
downstream: identity-service/users/{userId}/ban
auth: true
claims:
role: admin

- upstream: /users/{userId}/ban
method: DELETE
use: downstream
downstream: identity-service/users/{userId}/ban
auth: true
claims:
role: admin

services:
identity-service:
localUrl: localhost:5004
Expand Down Expand Up @@ -191,6 +223,8 @@ modules:
method: PUT
use: downstream
downstream: students-service/students/{studentId}
bind:
- studentId:{studentId}
auth: true

- upstream: /{studentId}
Expand All @@ -209,10 +243,18 @@ modules:
method: PUT
use: downstream
downstream: students-service/students/{studentId}/state/{state}
bind:
- studentId:{studentId}
- state:{state}
auth: true
claims:
role: admin

- upstream: /{studentId}/events
method: GET
use: downstream
downstream: students-service/students/{studentId}/events
auth: true

services:
students-service:
Expand Down Expand Up @@ -240,6 +282,12 @@ modules:
method: GET
use: downstream
downstream: events-service/events/{eventId}

- upstream: /student/{studentId}
method: GET
use: downstream
downstream: events-service/events/student/{studentId}
auth: true

- upstream: /{eventId}
method: DELETE
Expand All @@ -264,6 +312,12 @@ modules:
downstream: events-service/events/{eventId}/sign-up
auth: true

- upstream: /{eventId}/rate
method: POST
use: downstream
downstream: events-service/events/{eventId}/rate
auth: true

- upstream: /organizer/{organizerId}
method: GET
use: downstream
Expand All @@ -290,6 +344,8 @@ modules:
method: PUT
use: downstream
downstream: comments-service/comments/{commentId}
bind:
- commentId:{commentId}
auth: true

- upstream: /
Expand All @@ -304,10 +360,12 @@ modules:
downstream: comments-service/comments/{commentId}
auth: true

- upstream: /{commentId}like
- upstream: /{commentId}/like
method: POST
use: downstream
downstream: comments-service/comments/{commentId}/like
bind:
- commentId:{commentId}
auth: true

services:
Expand Down Expand Up @@ -386,6 +444,8 @@ modules:
method: POST
use: downstream
downstream: friends-service/friends/{userId}
bind:
- userId:{userId}
auth: true

- upstream: /notYet
Expand All @@ -410,6 +470,8 @@ modules:
method: POST
use: downstream
downstream: friends-service/friends/{userId}/invite
bind:
- userId:{userId}
auth: true

services:
Expand All @@ -432,13 +494,23 @@ modules:
method: PUT
use: downstream
downstream: posts-service/posts/{postId}
bind:
- postId:{postId}
auth: true

- upstream: /{postId}/state/{state}
method: PUT
use: downstream
downstream: students-service/students/{postId}/state/{state}
bind:
- postId:{postId}
- state:{state}
auth: true

- upstream: /
method: GET
use: downstream
downstream: posts-service/posts
auth: true

- upstream: /{postId}
method: DELETE
Expand All @@ -450,4 +522,4 @@ modules:
services:
posts-service:
localUrl: localhost:5013
url: posts-service
url: posts-service
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"service": "events-service"
},
"httpClient": {
"type": "fabio",
"type": "direct",
"retries": 3,
"services": {
"students": "http://localhost:5007"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace MiniSpace.Services.Events.Application.Queries
public class GetStudentEvents : IQuery<PagedResponse<IEnumerable<EventDto>>>
{
public Guid StudentId { get; set; }
public int numberOfResults { get; set; }
public int NumberOfResults { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public async Task<PagedResponse<IEnumerable<EventDto>>> HandleAsync(GetStudentEv
if (identity.IsAuthenticated && identity.Id != query.StudentId)
{
return new PagedResponse<IEnumerable<EventDto>>(Enumerable.Empty<EventDto>(),
1, query.numberOfResults, 0, 0);
1, query.NumberOfResults, 0, 0);
}

var studentEvents = await _studentsServiceClient.GetAsync(query.StudentId);
var studentEventIds = studentEvents.InterestedInEvents.Union(studentEvents.SignedUpEvents);
var studentEventIds = studentEvents.InterestedInEvents.Union(studentEvents.SignedUpEvents).ToList();

var result = await _eventRepository.BrowseAsync(1, query.numberOfResults,
var result = await _eventRepository.BrowseAsync(1, query.NumberOfResults,
string.Empty, string.Empty, DateTime.MinValue, DateTime.MinValue,
Enumerable.Empty<string>(), "asc", State.Published, studentEventIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task HandleAsync(DeleteStudent command, CancellationToken cancellat

await _studentRepository.DeleteAsync(command.StudentId);

await _messageBroker.PublishAsync(new StudentDeleted(command.StudentId));
await _messageBroker.PublishAsync(new StudentDeleted(command.StudentId, student.FullName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class StudentDto
public DateTime? DateOfBirth { get; set; }
public bool EmailNotifications { get; set; }
public bool IsBanned { get; set; }
public bool CanBeOrganizer { get; set; }
public bool IsOrganizer { get; set; }
public string State { get; set; }
public DateTime CreatedAt { get; set; }
public IEnumerable<Guid> InterestedInEvents { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MiniSpace.Services.Students.Application.Events.External.Handlers
{
public class OrganizerRightsGrantedHandler : IEventHandler<StudentShowedInterestInEvent>
public class OrganizerRightsGrantedHandler : IEventHandler<OrganizerRightsGranted>
{
private readonly IStudentRepository _studentRepository;
private readonly IEventMapper _eventMapper;
Expand All @@ -19,12 +19,12 @@ public class OrganizerRightsGrantedHandler : IEventHandler<StudentShowedInterest
_messageBroker = messageBroker;
}

public async Task HandleAsync(StudentShowedInterestInEvent @event, CancellationToken cancellationToken)
public async Task HandleAsync(OrganizerRightsGranted @event, CancellationToken cancellationToken)
{
var student = await _studentRepository.GetAsync(@event.StudentId);
var student = await _studentRepository.GetAsync(@event.UserId);
if (student is null)
{
throw new StudentNotFoundException(@event.StudentId);
throw new StudentNotFoundException(@event.UserId);
}

student.GrantOrganizerRights();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MiniSpace.Services.Students.Application.Events.External.Handlers
{
public class OrganizerRightsRevokedHandler : IEventHandler<StudentShowedInterestInEvent>
public class OrganizerRightsRevokedHandler : IEventHandler<OrganizerRightsRevoked>
{
private readonly IStudentRepository _studentRepository;
private readonly IEventMapper _eventMapper;
Expand All @@ -19,12 +19,12 @@ public class OrganizerRightsRevokedHandler : IEventHandler<StudentShowedInterest
_messageBroker = messageBroker;
}

public async Task HandleAsync(StudentShowedInterestInEvent @event, CancellationToken cancellationToken)
public async Task HandleAsync(OrganizerRightsRevoked @event, CancellationToken cancellationToken)
{
var student = await _studentRepository.GetAsync(@event.StudentId);
var student = await _studentRepository.GetAsync(@event.UserId);
if (student is null)
{
throw new StudentNotFoundException(@event.StudentId);
throw new StudentNotFoundException(@event.UserId);
}

student.RevokeOrganizerRights();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MiniSpace.Services.Students.Application.Events.External.Handlers
{
public class UserBannedHandler : IEventHandler<StudentShowedInterestInEvent>
public class UserBannedHandler : IEventHandler<UserBanned>
{
private readonly IStudentRepository _studentRepository;
private readonly IEventMapper _eventMapper;
Expand All @@ -19,12 +19,12 @@ public class UserBannedHandler : IEventHandler<StudentShowedInterestInEvent>
_messageBroker = messageBroker;
}

public async Task HandleAsync(StudentShowedInterestInEvent @event, CancellationToken cancellationToken)
public async Task HandleAsync(UserBanned @event, CancellationToken cancellationToken)
{
var student = await _studentRepository.GetAsync(@event.StudentId);
var student = await _studentRepository.GetAsync(@event.UserId);
if (student is null)
{
throw new StudentNotFoundException(@event.StudentId);
throw new StudentNotFoundException(@event.UserId);
}

student.Ban();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MiniSpace.Services.Students.Application.Events.External.Handlers
{
public class UserUnbannedHandler : IEventHandler<StudentShowedInterestInEvent>
public class UserUnbannedHandler : IEventHandler<UserUnbanned>
{
private readonly IStudentRepository _studentRepository;
private readonly IEventMapper _eventMapper;
Expand All @@ -19,12 +19,12 @@ public class UserUnbannedHandler : IEventHandler<StudentShowedInterestInEvent>
_messageBroker = messageBroker;
}

public async Task HandleAsync(StudentShowedInterestInEvent @event, CancellationToken cancellationToken)
public async Task HandleAsync(UserUnbanned @event, CancellationToken cancellationToken)
{
var student = await _studentRepository.GetAsync(@event.StudentId);
var student = await _studentRepository.GetAsync(@event.UserId);
if (student is null)
{
throw new StudentNotFoundException(@event.StudentId);
throw new StudentNotFoundException(@event.UserId);
}

student.Unban();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ namespace MiniSpace.Services.Students.Application.Events
public class StudentCreated : IEvent
{
public Guid StudentId { get; }
public string FullName { get; }

public StudentCreated(Guid studentId)
public StudentCreated(Guid studentId, string fullName)
{
StudentId = studentId;
FullName = fullName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ namespace MiniSpace.Services.Students.Application.Events
public class StudentDeleted : IEvent
{
public Guid StudentId { get; }
public string FullName { get; }

public StudentDeleted(Guid studentId)
public StudentDeleted(Guid studentId, string fullName)
{
StudentId = studentId;
FullName = fullName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ namespace MiniSpace.Services.Students.Application.Events
public class StudentStateChanged : IEvent
{
public Guid StudentId { get; }
public string FullName { get; }
public string CurrentState { get; }
public string PreviousState { get; }

public StudentStateChanged(Guid studentId, string currentState, string previousState)
public StudentStateChanged(Guid studentId, string fullName, string currentState, string previousState)
{
StudentId = studentId;
FullName = fullName;
CurrentState = currentState;
PreviousState = previousState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ namespace MiniSpace.Services.Students.Application.Events
public class StudentUpdated : IEvent
{
public Guid StudentId { get; }
public string FullName { get; }

public StudentUpdated(Guid studentId)
public StudentUpdated(Guid studentId, string fullName)
{
StudentId = studentId;
FullName = fullName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ public interface IIdentityContext
{
Guid Id { get; }
string Role { get; }
string Name { get; }
string Email { get; }
bool IsAuthenticated { get; }
bool IsAdmin { get; }
bool IsBanned { get; }
bool IsOrganizer { get; }
IDictionary<string, string> Claims { get; }
}
}
}
Loading

0 comments on commit 0661ecc

Please sign in to comment.