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
@Component | |
public class StoreHandler { | |
private final StoreManagementUseCase useCase; | |
@Autowired | |
public StoreHandler(StoreManagementUseCase useCase) { | |
this.useCase = useCase; | |
} | |
public Mono<ServerResponse> addStore(ServerRequest request) { |
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
@Configuration | |
public class StoreRouter { | |
@Bean | |
public RouterFunction<ServerResponse> routes(StoreHandler handler) { | |
return route(POST("/stores").and(accept(MediaType.APPLICATION_JSON)), handler::addStore); | |
} | |
} |
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
@Value | |
public class GeoJSONPoint { | |
String type = "Point"; | |
List<Double> coordinates; | |
} |
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
@Document(collection = "stores") | |
public class StoreEntity { | |
@Id | |
private String id; | |
private final String name; | |
private final String zipCode; | |
private final GeoJSONPoint geoJSONPoint; | |
public StoreEntity(String name, String zipCode, GeoJSONPoint geoJSONPoint) { | |
this.name = name; |
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
@Repository | |
public interface StoreRepository extends ReactiveMongoRepository<StoreEntity, String> { | |
} | |
@Repository | |
public interface ZipCodeRepository extends ReactiveMongoRepository<ZipCodeEntity, String> { | |
Mono<ZipCodeEntity> findByZipCode(String zipCode); | |
} |
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
@Component | |
public class StoreManagementDBAdapter implements StorePort, UpdateStoreCountInZipCodePort { | |
private final StoreRepository storeRepository; | |
private final ZipCodeRepository zipCodeRepository; | |
@Autowired | |
public StoreManagementDBAdapter(StoreRepository storeRepository, ZipCodeRepository zipCodeRepository) { | |
this.storeRepository = storeRepository; | |
this.zipCodeRepository = zipCodeRepository; | |
} |
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
public interface StorePort { | |
Mono<Store> addStore(Store store); | |
} | |
public interface UpdateStoreCountInZipCodePort { | |
void incrementStoreCount(String zipCode); | |
} |
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
public class Location { | |
private final String zipCode; | |
private final Double latitude; | |
private final Double longitude; | |
public Location(String zipCode, Double latitude, Double longitude) { | |
this.zipCode = zipCode; | |
this.latitude = latitude; | |
this.longitude = longitude; | |
} |
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
public class Store { | |
private String id; | |
private final String name; | |
private final Location location; | |
public Store(String name, Location location) { | |
this.name = name; | |
this.location = location; | |
} |
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
@Service | |
public class StoreService implements StoreManagementUseCase { | |
private final StorePort storePort; | |
private final UpdateStoreCountInZipCodePort updateStoreCountInZipCodePort; | |
@Autowired | |
public StoreService(StorePort storePort, UpdateStoreCountInZipCodePort updateStoreCountInZipCodePort) { | |
this.storePort = storePort; | |
this.updateStoreCountInZipCodePort = updateStoreCountInZipCodePort; | |
} |