Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public Event createEvent(@RequestBody EventRequestDTO event) {
@PostMapping("/{eventId}/register")
public ResponseEntity<String> registerParticipant(@PathVariable String eventId, @RequestBody SubscriptionRequestDTO subscriptionRequest) {
eventService.registerParticipant(eventId, subscriptionRequest.participantEmail());
return ResponseEntity.ok("Event created successfully");
return ResponseEntity.ok("Subscription confirmed successfully");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import com.kipper.eventsmicroservice.exceptions.EventNotFoundException;
import com.kipper.eventsmicroservice.repositories.EventRepository;
import com.kipper.eventsmicroservice.repositories.SubscriptionRepository;

import jakarta.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -43,6 +46,8 @@ private Boolean isEventFull(Event event){
return event.getRegisteredParticipants() >= event.getMaxParticipants();
}

// Rollback the transaction, once the EmailServiceClient throws an exception - participantEmail must be verified in SES identities.
@Transactional
public void registerParticipant(String eventId, String participantEmail) {
Event event = eventRepository.findById(eventId).orElseThrow(EventNotFoundException::new);

Expand All @@ -55,6 +60,9 @@ public void registerParticipant(String eventId, String participantEmail) {

event.setRegisteredParticipants(event.getRegisteredParticipants() + 1);

// update the new participant
eventRepository.save(event);

EmailRequestDTO emailRequest = new EmailRequestDTO(participantEmail, "Confirmação de Inscrição", "Você foi inscrito no evento com sucesso!");

emailServiceClient.sendEmail(emailRequest);
Expand Down