Initial commit - 2

This commit is contained in:
Kayashov.SM
2025-03-12 18:05:06 +04:00
parent b6d8a3cebd
commit 05ef7ab789
36 changed files with 21 additions and 476 deletions

View File

@@ -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;
}
}