-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
519 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
import com.petclinic.visits.visitsservicenew.DataLayer.Status; | ||
import com.petclinic.visits.visitsservicenew.DataLayer.VisitRepo; | ||
import com.petclinic.visits.visitsservicenew.DomainClientLayer.*; | ||
import com.petclinic.visits.visitsservicenew.DomainClientLayer.Auth.AuthServiceClient; | ||
import com.petclinic.visits.visitsservicenew.DomainClientLayer.Auth.UserDetails; | ||
import com.petclinic.visits.visitsservicenew.DomainClientLayer.Mailing.Mail; | ||
import com.petclinic.visits.visitsservicenew.DomainClientLayer.Mailing.MailService; | ||
import com.petclinic.visits.visitsservicenew.Exceptions.BadRequestException; | ||
import com.petclinic.visits.visitsservicenew.Exceptions.DuplicateTimeException; | ||
import com.petclinic.visits.visitsservicenew.Exceptions.NotFoundException; | ||
|
@@ -15,6 +19,8 @@ | |
import reactor.core.publisher.Mono; | ||
import java.time.LocalDateTime; | ||
|
||
import static java.lang.String.format; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
|
@@ -24,6 +30,8 @@ public class VisitServiceImpl implements VisitService { | |
private final PetsClient petsClient; | ||
private final EntityDtoUtil entityDtoUtil; | ||
|
||
private final AuthServiceClient authServiceClient; | ||
private final MailService mailService; | ||
@Override | ||
public Flux<VisitResponseDTO> getAllVisits() { | ||
return repo.findAll().flatMap(visit -> entityDtoUtil.toVisitResponseDTO(visit)); | ||
|
@@ -77,11 +85,20 @@ public Mono<VisitResponseDTO> addVisit(Mono<VisitRequestDTO> visitRequestDTOMono | |
.then(validatePetId(visitRequestDTO.getPetId())) | ||
.then(validateVetId(visitRequestDTO.getPractitionerId())) | ||
.then(Mono.just(visitRequestDTO)) | ||
.doOnNext(s->{ | ||
|
||
authServiceClient.getUserById(visitRequestDTO.getJwtToken(), visitRequestDTO.getOwnerId()).subscribe(user->mailService.sendMail(generateVisitRequestEmail(user, visitRequestDTO.getPetId(), visitRequestDTO.getVisitDate()))); | ||
|
||
// Mono<UserDetails> user = getUserById(auth, ownerId); | ||
// try{ | ||
// simpleJavaMailClient.sendMail(emailBuilder("[email protected]")); | ||
// }catch(Exception e){System.out.println("Email failed to send: "+e.getMessage());} | ||
}) | ||
) | ||
.doOnNext(v -> System.out.println("Request Date: " + v.getVisitDate())) // Debugging | ||
// .doOnNext(v -> System.out.println("Request Date: " + v.getVisitDate())) // Debugging | ||
.map(visitRequestDTO -> entityDtoUtil.toVisitEntity(visitRequestDTO)) | ||
.doOnNext(x -> x.setVisitId(entityDtoUtil.generateVisitIdString())) | ||
.doOnNext(v -> System.out.println("Entity Date: " + v.getVisitDate())) // Debugging | ||
// .doOnNext(x -> x.setVisitId(entityDtoUtil.generateVisitIdString())) | ||
// .doOnNext(v -> System.out.println("Entity Date: " + v.getVisitDate())) // Debugging | ||
.flatMap(visit -> | ||
repo.findByVisitDateAndPractitionerId(visit.getVisitDate(), visit.getPractitionerId()) // FindVisits method in repository | ||
.collectList() | ||
|
@@ -210,4 +227,57 @@ else if (dto.getStatus() != Status.UPCOMING){ | |
return Mono.just(dto); | ||
} | ||
} | ||
|
||
private Mail generateVisitRequestEmail(UserDetails user, String petName, LocalDateTime visitDate) { | ||
return Mail.builder() | ||
.message( | ||
format(""" | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Email Verification</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
.container { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
background-color: #fff; | ||
border-radius: 5px; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | ||
} | ||
h1 { | ||
color: #333; | ||
} | ||
p { | ||
color: #555; | ||
} | ||
a { | ||
color: #007BFF; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Dear %s,</h1> | ||
<h3>We have received a request to schedule a visit for one of your pet: %s at the following date and time: %s.</h3> | ||
\s | ||
<p>If you do not wish to create an account, please disregard this email.</p> | ||
\s | ||
<p>Thank you for choosing Pet Clinic.</p> | ||
</div> | ||
</body> | ||
</html> | ||
""", user.getUsername(), petName, visitDate.toString())) | ||
.subject("PetClinic Visit request") | ||
.to(user.getEmail()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.