diff --git a/api-gateway/src/main/resources/static/scripts/vet-details/vet-details.template.html b/api-gateway/src/main/resources/static/scripts/vet-details/vet-details.template.html
index d63cefb0eb..79a9d956c8 100644
--- a/api-gateway/src/main/resources/static/scripts/vet-details/vet-details.template.html
+++ b/api-gateway/src/main/resources/static/scripts/vet-details/vet-details.template.html
@@ -71,7 +71,7 @@
Availabilities
-
+
diff --git a/vet-service/src/main/java/com/petclinic/vet/servicelayer/VetServiceImpl.java b/vet-service/src/main/java/com/petclinic/vet/servicelayer/VetServiceImpl.java
index 6d815b87dd..ea9b36affa 100644
--- a/vet-service/src/main/java/com/petclinic/vet/servicelayer/VetServiceImpl.java
+++ b/vet-service/src/main/java/com/petclinic/vet/servicelayer/VetServiceImpl.java
@@ -11,21 +11,31 @@
* Ticket: feat(VVS-CPC-553): add veterinarian
*/
+import com.petclinic.vet.dataaccesslayer.Vet;
import com.petclinic.vet.dataaccesslayer.VetRepository;
+import com.petclinic.vet.dataaccesslayer.badges.Badge;
+import com.petclinic.vet.dataaccesslayer.badges.BadgeRepository;
+import com.petclinic.vet.dataaccesslayer.badges.BadgeTitle;
import com.petclinic.vet.exceptions.InvalidInputException;
import com.petclinic.vet.exceptions.NotFoundException;
import com.petclinic.vet.util.EntityDtoUtil;
import lombok.RequiredArgsConstructor;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
+import org.springframework.util.StreamUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
+import java.io.IOException;
+import java.time.LocalDate;
+
@Service
@RequiredArgsConstructor
public class VetServiceImpl implements VetService {
private final VetRepository vetRepository;
+ private final BadgeRepository badgeRepository;
@Override
public Flux getAll() {
@@ -52,7 +62,20 @@ public Mono insertVet(Mono vetDTOMono) {
return Mono.just(requestDTO);
})
.map(vetDTO -> EntityDtoUtil.toEntity(vetDTO))
- .flatMap((vetRepository::save))
+ .flatMap(newVet -> {
+ Badge badge = Badge.builder()
+ .vetId(newVet.getVetId())
+ .badgeTitle(BadgeTitle.VALUED)
+ .badgeDate(String.valueOf(LocalDate.now().getYear()))
+ .data(loadBadgeImage("images/empty_food_bowl.png"))
+ .build();
+
+ //combine results of two Mono operations, creating a Tuple2
+ //extract vet from it
+ return badgeRepository.save(badge)
+ .zipWith(vetRepository.save(newVet))
+ .map(tuple -> tuple.getT2());
+ })
.map(EntityDtoUtil::toDTO);
}
@@ -110,6 +133,15 @@ public Mono deleteVetByVetId(String vetId) {
.flatMap(vetRepository::delete);
}
+ private byte[] loadBadgeImage(String imagePath) {
+ try {
+ ClassPathResource cpr = new ClassPathResource(imagePath);
+ return StreamUtils.copyToByteArray(cpr.getInputStream());
+ } catch (IOException io) {
+ throw new InvalidInputException("Picture does not exist: " + io.getMessage());
+ }
+ }
+
}