Initial commit - 2
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
package ru.kayashov.bar.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.kayashov.bar.model.entity.ParserEntity;
|
||||
import ru.kayashov.bar.repository.ParserEntityRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ParserQueueService {
|
||||
|
||||
private final ParserEntityRepository repository;
|
||||
|
||||
public Long getIngredientOffset() {
|
||||
return getEntity().getIngredientId();
|
||||
}
|
||||
|
||||
public Long getCocktailOffset() {
|
||||
return getEntity().getCocktailId();
|
||||
}
|
||||
|
||||
public void setStepIngredients(long id, int step) {
|
||||
ParserEntity entity = getEntity();
|
||||
entity.setIngredientId(id);
|
||||
entity.setIngredientError(entity.getIngredientError() + step);
|
||||
repository.save(entity);
|
||||
}
|
||||
|
||||
public void setStepCocktails(long id, int step) {
|
||||
ParserEntity entity = getEntity();
|
||||
entity.setCocktailId(id);
|
||||
entity.setCocktailError(entity.getCocktailError() + step);
|
||||
repository.save(entity);
|
||||
}
|
||||
|
||||
private ParserEntity getEntity() {
|
||||
List<ParserEntity> entities = repository.findAll();
|
||||
if(entities.isEmpty()) {
|
||||
ParserEntity entity = getNewEntity();
|
||||
return repository.save(entity);
|
||||
}
|
||||
return entities.get(0);
|
||||
}
|
||||
|
||||
private ParserEntity getNewEntity() {
|
||||
ParserEntity entity = new ParserEntity();
|
||||
entity.setIngredientId(1L);
|
||||
entity.setCocktailId(1L);
|
||||
entity.setCocktailError(0L);
|
||||
entity.setCocktailError(0L);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user