feat: Averages update in Temperatures service

This commit is contained in:
Piotr Dec 2024-07-18 19:27:26 +02:00
parent 770ccf63a5
commit 1afff3819b
Signed by: stawros
GPG key ID: F89F27AD8F881A91

View file

@ -2,7 +2,10 @@ package eu.ztsh.lfr.core.impl;
import eu.ztsh.lfr.core.TemperaturesService; import eu.ztsh.lfr.core.TemperaturesService;
import eu.ztsh.lfr.model.Average; import eu.ztsh.lfr.model.Average;
import eu.ztsh.lfr.model.Averages;
import eu.ztsh.lfr.model.events.FileProcessedEvent;
import jakarta.annotation.Nonnull; import jakarta.annotation.Nonnull;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -10,10 +13,19 @@ import java.util.List;
@Service @Service
public class TemperaturesServiceImpl implements TemperaturesService { public class TemperaturesServiceImpl implements TemperaturesService {
private Averages averages;
@Nonnull @Nonnull
@Override @Override
public List<Average> getTemperaturesFor(String city) { public List<Average> getTemperaturesFor(String city) {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@EventListener(FileProcessedEvent.class)
public void updateTemperatures(FileProcessedEvent event) {
synchronized (this) {
averages = event.averages();
}
}
} }