Skip to content

Instantly share code, notes, and snippets.

@codingtim
Created November 20, 2015 10:48
Show Gist options
  • Save codingtim/737ca0f5b3bec43d68b7 to your computer and use it in GitHub Desktop.
Save codingtim/737ca0f5b3bec43d68b7 to your computer and use it in GitHub Desktop.
start
public class EntityServiceImp implements EntityService {
private EntityRepository repository;
private ImageService imageService;
@Override
public void update(String id, UpdateData updateData) {
Entity entity = repository.find(id);
entity.setDescription(updateData.getDescription());
entity.setTitle(updateData.getTitle());
imageService.updateImage(entity, updateData);
repository.save(entity);
}
}
public class ImageServiceImpl implements ImageService {
private ImageStoreGateway imageStoreGateway;
@Override
public void updateImage(Entity entity, UpdateData updateData) {
if (updateData.getImageUrl() != null) {
ImageEntity imageEntity = new ImageEntity();
imageEntity.setImageUrl(updateData.getImageUrl());
imageStoreGateway.postImage(imageEntity);
ImageEntity previous = entity.getImage();
imageStoreGateway.deleteImage(previous);
entity.setImage(imageEntity);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment