1 package org.oxerr.viagogo.client.rescu.impl.inventory; 2 3 import static jakarta.ws.rs.core.Response.Status.NOT_FOUND; 4 5 import java.io.IOException; 6 import java.time.Instant; 7 import java.util.Optional; 8 9 import org.oxerr.viagogo.client.inventory.SellerListingService; 10 import org.oxerr.viagogo.client.rescu.resource.ViagogoException; 11 import org.oxerr.viagogo.client.rescu.resource.inventory.SellerListingResource; 12 import org.oxerr.viagogo.model.request.inventory.CreateSellerListingForRequestedEventRequest; 13 import org.oxerr.viagogo.model.request.inventory.CreateSellerListingRequest; 14 import org.oxerr.viagogo.model.request.inventory.SellerListingRequest; 15 import org.oxerr.viagogo.model.response.PagedResource; 16 import org.oxerr.viagogo.model.response.inventory.SellerListing; 17 18 import si.mazi.rescu.HttpStatusIOException; 19 20 public class SellerListingServiceImpl implements SellerListingService { 21 22 private final SellerListingResource sellerListingsResource; 23 24 public SellerListingServiceImpl(SellerListingResource sellerListingsResource) { 25 this.sellerListingsResource = sellerListingsResource; 26 } 27 28 @Override 29 public Optional<SellerListing> getSellerListing(Long listingId) throws IOException { 30 try { 31 return Optional.ofNullable(this.sellerListingsResource.getSellerListing(listingId)); 32 } catch (ViagogoException | HttpStatusIOException e) { 33 if (e.getHttpStatusCode() == NOT_FOUND.getStatusCode()) { 34 return Optional.empty(); 35 } else { 36 throw e; 37 } 38 } 39 } 40 41 @Override 42 public PagedResource<SellerListing> getSellerListingsRecentUpdates(Instant updatedSince) throws IOException { 43 return this.sellerListingsResource.getSellerListingsRecentUpdates(updatedSince); 44 } 45 46 @Override 47 public PagedResource<SellerListing> getSellerListings(SellerListingRequest sellerListingRequest) throws IOException { 48 return this.sellerListingsResource.getSellerListings( 49 sellerListingRequest.getEventId(), 50 sellerListingRequest.getRequestedEventId(), 51 sellerListingRequest.getPage(), 52 sellerListingRequest.getPageSize(), 53 sellerListingRequest.getUpdatedSince(), 54 sellerListingRequest.getSort() 55 ); 56 } 57 58 @Override 59 public SellerListing createListingForRequestedEvent(CreateSellerListingForRequestedEventRequest createSellerListingForRequestedEventRequest) throws IOException { 60 return this.sellerListingsResource.createListingForRequestedEvent(createSellerListingForRequestedEventRequest); 61 } 62 63 @Override 64 public SellerListing createListing(Long eventId, CreateSellerListingRequest createSellerListingRequest) throws IOException { 65 return this.sellerListingsResource.createListing(eventId, createSellerListingRequest); 66 } 67 68 @Override 69 public Optional<SellerListing> getSellerListingByExternalId(String externalListingId) throws IOException { 70 try { 71 return Optional.ofNullable(this.sellerListingsResource.getSellerListingByExternalId(externalListingId)); 72 } catch (ViagogoException | HttpStatusIOException e) { 73 if (e.getHttpStatusCode() == NOT_FOUND.getStatusCode()) { 74 return Optional.empty(); 75 } else { 76 throw e; 77 } 78 } 79 } 80 81 @Override 82 public void deleteListingByExternalListingId(String externalId) throws IOException { 83 try { 84 this.sellerListingsResource.deleteListingByExternalListingId(externalId); 85 } catch (ViagogoException | HttpStatusIOException e) { 86 if (e.getHttpStatusCode() != NOT_FOUND.getStatusCode()) { 87 throw e; 88 } 89 } 90 } 91 92 }