Commit 81d7ace5 authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-568 | clean up logic

parent 2f0b01c7
......@@ -32,7 +32,7 @@ public class MeController {
@Secured(RoleString.USER)
public Response<UserData> userData() {
StatUser user = UserSessionHolder.getLoggedInUser();
return user == null ? null : of(new UserData(user.getFullName(), getRoles(user.getAuthorities()), user.getSeenTheNews() ? true : null));
return user == null ? null : of(new UserData(user.getFullName(), getRoles(user.getAuthorities()), user.getSeenTheNews() ? null : true));
}
@PatchMapping(path = "/news")
......
......@@ -14,5 +14,5 @@ import java.util.List;
public class UserData {
private String username;
private List<String> roles;
private Boolean seenTheNews;
private Boolean showNews;
}
......@@ -6,6 +6,7 @@ import ee.stat.dashboard.model.user.user.AppUserSession;
import ee.stat.dashboard.repository.UserRepository;
import ee.stat.dashboard.service.user.dto.UserNewsDto;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -36,8 +37,10 @@ public class UserService {
public void seenTheNews(UserNewsDto userNewsDto) {
AppUser user = userRepository.findById(userNewsDto.getId()).orElseThrow(RuntimeException::new);
user.setSeenTheNews(true);
userRepository.save(user);
if (!user.isSeenTheNews()) {
user.setSeenTheNews(BooleanUtils.isTrue(userNewsDto.getSeenTheNews()));
userRepository.save(user);
}
}
private AppUser getOrSaveNewUser(TaraDataDto dto) {
......
......@@ -7,5 +7,5 @@ import lombok.Setter;
@Setter
public class UserNewsDto {
private Long id;
private Boolean seenNews;
private Boolean seenTheNews;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment