Skip to content

Instantly share code, notes, and snippets.

@mseemann
Last active September 4, 2021 16:18
Show Gist options
  • Save mseemann/91eaf0efb3dfb6b6a988bd18580d0fd2 to your computer and use it in GitHub Desktop.
Save mseemann/91eaf0efb3dfb6b6a988bd18580d0fd2 to your computer and use it in GitHub Desktop.
SyncToPostgresService
@Service
@Slf4j
@Transactional(propagation = Propagation.REQUIRED)
@AllArgsConstructor
public class SyncToPostgresService {
UserEntityRepository userEntityRepository;
ResumeTokenRepository resumeTokenRepository;
public void syncInASingleTx(User document, String bookmarkToken, Long tokenTimeStamp) {
log.info("syncing to db: {}, with token: {}", document, bookmarkToken);
var token = ResumeTokenEntity.builder()
.collection(ResumeTokenRepository.USER_COLLECTION)
.token(bookmarkToken)
.tokenTimeStamp(tokenTimeStamp)
.build();
var entity = UserEntity.builder()
.id(document.id())
.userName(document.userName()
.build();
userEntityRepository.save(entity);
resumeTokenRepository.save(token);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment