Skip to content

Commit

Permalink
feat(app): check if user can acceed to live masterclass
Browse files Browse the repository at this point in the history
  • Loading branch information
chukitipok committed Jul 5, 2022
1 parent 965c450 commit 76c18e0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,14 @@ public ResponseEntity<Collection<EventResponse>> retrieveMyEvents(UUID id) {
return ResponseEntity.badRequest().build();
}
}

public ResponseEntity<?> participate(AttendMasterClassRequest request) {
var useCase = new AttendMasterclass(events);
var canAttend = useCase.attendMasterclass(request);

var response =
(canAttend) ? ResponseEntity.ok() : ResponseEntity.badRequest();

return response.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fr.sweetiez.api.core.events.use_case.streaming;

import java.util.UUID;

public record AttendMasterClassRequest(UUID eventID, String participantID) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.sweetiez.api.core.events.use_case.streaming;

import fr.sweetiez.api.core.events.events.streaming_event.StreamingEvents;

public class AttendMasterclass {

private final StreamingEvents streamingEvents;

public AttendMasterclass(StreamingEvents streamingEvents) {
this.streamingEvents = streamingEvents;
}

public boolean attendMasterclass(AttendMasterClassRequest request) {
var canAttend = false;
var optionalEvent = streamingEvents.findById(request.eventID());

if (optionalEvent.isPresent()) {
var subscribersID = optionalEvent.get()
.subscribers()
.stream()
.map(customer -> customer.id().value())
.toList();

if (subscribersID.contains(request.participantID())) {
canAttend = true;
}
}

return canAttend;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fr.sweetiez.api.adapter.delivery.event.StreamingEventEndPoints;
import fr.sweetiez.api.core.events.events.streaming_event.StreamingEvent;
import fr.sweetiez.api.core.events.use_case.streaming.AttendMasterClassRequest;
import fr.sweetiez.api.core.events.use_case.streaming.models.requests.CreateStreamingEventRequestDTO;
import fr.sweetiez.api.core.events.use_case.streaming.models.requests.RescheduleEventRequest;
import fr.sweetiez.api.core.events.use_case.streaming.models.requests.SubscribeEventRequest;
Expand Down Expand Up @@ -61,4 +62,9 @@ public ResponseEntity<Collection<EventResponse>> retrieveAllPublished() {
public ResponseEntity<Collection<EventAdminResponse>> retrieveAll() {
return endPoints.retrieveAll();
}

@PostMapping("/events/participate")
public ResponseEntity<?> canAttendMasterclass(@RequestBody AttendMasterClassRequest request) {
return endPoints.participate(request);
}
}

0 comments on commit 76c18e0

Please sign in to comment.