Skip to content

Commit

Permalink
Fix #530
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGuancheDarias committed Feb 16, 2024
1 parent 320df8d commit e92e057
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ public ActiveTimeSpecial activate(Integer timeSpecialId) {
newActive.setActivationDate(new Date());
newActive.setExpiringDate(computeExpiringDate(timeSpecial.getDuration()));
newActive.setState(TimeSpecialStateEnum.ACTIVE);
definePendingTime(newActive);
newActive.setTimeSpecial(timeSpecial);
var user = userSessionService.findLoggedInWithDetails();
newActive.setUser(user);
Expand Down Expand Up @@ -218,7 +217,6 @@ public Class<ActiveTimeSpecialDto> getDtoClass() {

@Override
public ActiveTimeSpecial onFind(ActiveTimeSpecial activeTimeSpecial) {
definePendingTime(activeTimeSpecial);
return activeTimeSpecial;
}

Expand Down Expand Up @@ -293,16 +291,6 @@ private Date computeExpiringDate(Long time) {
return new Date(difference);
}

private void definePendingTime(ActiveTimeSpecial activeTimeSpecial) {
if (activeTimeSpecial != null) {
if (activeTimeSpecial.getState() == TimeSpecialStateEnum.ACTIVE) {
activeTimeSpecial.setPendingTime(activeTimeSpecial.getExpiringDate().getTime() - new Date().getTime());
} else {
activeTimeSpecial.setPendingTime(activeTimeSpecial.getReadyDate().getTime() - new Date().getTime());
}
}
}

private Long resolveTaskId(ScheduledTask task) {
if (task.getContent() instanceof Double doubleValue) {
return doubleValue.longValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ActiveTimeSpecialDto implements DtoFromEntity<ActiveTimeSpecial> {
private TimeSpecialStateEnum state;
private Date activationDate;
private Date expiringDate;
private Long pendingTime;
private Long pendingMillis;
private Date readyDate;

@Override
Expand All @@ -33,8 +33,20 @@ public void dtoFromEntity(ActiveTimeSpecial entity) {
state = entity.getState();
activationDate = entity.getActivationDate();
expiringDate = entity.getExpiringDate();
pendingTime = entity.getPendingTime();
readyDate = entity.getReadyDate();
calculatePendingMillis();
timeSpecial = entity.getTimeSpecial().getId();
}

/**
* Calculates the pending millis, is a public method because maybe it has to be recalculated
* on cache results by @{@link com.kevinguanchedarias.taggablecache.aspect.TaggableCacheable}
*/
public void calculatePendingMillis() {
if (state == TimeSpecialStateEnum.ACTIVE) {
pendingMillis = (expiringDate.getTime() - new Date().getTime());
} else {
pendingMillis = (readyDate.getTime() - new Date().getTime());
}
}
}
3 changes: 2 additions & 1 deletion game-frontend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ v0.11.5 (latest)
* __Improvememnt:__ [Allow to know that a mission is invisible to the mission sender user #532](https://github.com/KevinGuancheDarias/owge/issues/532)
* __Fix:__ [In Neon the gather reports don't show properly the resources, they have free width and height #523](https://github.com/KevinGuancheDarias/owge/issues/523)
* __Improvememnt:__ [Add button to mark all messages as read #514](https://github.com/KevinGuancheDarias/owge/issues/514)
* __Fix:__ [Deployment to non owned planet, and then EB mission to other planet, and them from that planet deploy to other non owned planet, would bug the deploy mission #541](https://github.com/KevinGuancheDarias/owge/issues/541)
* __Fix:__ [Deployment to non owned planet, and then EB mission to other planet, and them from that planet deploy to other non owned planet, would bug the deploy mission #541](https://github.com/KevinGuancheDarias/owge/issues/541)
* __Fix:__ [When you force sync the time special's countdown gets weird #530](https://github.com/KevinGuancheDarias/owge/issues/530)

v0.11.4 (2024-02-08 05:39)
==================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.ApplicationScope;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

Expand Down Expand Up @@ -70,8 +72,19 @@ public RestCrudConfigBuilder<Integer, TimeSpecial, TimeSpecialRepository, TimeSp
@Override
public Map<String, Function<UserStorage, Object>> findSyncHandlers() {
return SyncHandlerBuilder.create()
.withHandler("time_special_change", activeTimeSpecialBo::findByUserWithCurrentStatus)
.withHandler("time_special_change", user -> {
var retVal = activeTimeSpecialBo.findByUserWithCurrentStatus(user);
recomputeDates(retVal);
return retVal;
})
.build();
}

private void recomputeDates(List<TimeSpecialDto> timeSpecialDtoList) {
timeSpecialDtoList.stream()
.map(TimeSpecialDto::getActiveTimeSpecialDto)
.filter(Objects::nonNull)
.forEach(ActiveTimeSpecialDto::calculatePendingMillis);
}

}

0 comments on commit e92e057

Please sign in to comment.