Skip to content

Commit

Permalink
Reduced size of badge and when new vet is created, badge is created too
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-cal committed Oct 9, 2023
1 parent 735192f commit ab01ab8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h5 class="mb-3">Availabilities</h5>
<a style="text-decoration: none;"><span
class="info v{{$ctrl.badge.vetId}}" ng-mouseenter="$ctrl.show($event,$ctrl.badge.vetId)"
ng-mouseleave="$ctrl.hide($event,$ctrl.badge.vetId)">
<img alt="Badge preview" src="data:image/*;base64, {{$ctrl.badge.resourceBase64}}" width="150" height="150" class="image1">
<img alt="Badge preview" src="data:image/*;base64, {{$ctrl.badge.resourceBase64}}" width="100" height="100" class="image1">
</span></a>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VetDTO> getAll() {
Expand All @@ -52,7 +62,20 @@ public Mono<VetDTO> insertVet(Mono<VetDTO> 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);
}

Expand Down Expand Up @@ -110,6 +133,15 @@ public Mono<Void> 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());
}
}



}

0 comments on commit ab01ab8

Please sign in to comment.