Skip to content

Instantly share code, notes, and snippets.

package com.minikube.sample.rest.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* Created By Gorantla, Eresh on 13/Jan/2020
**/
package com.minikube.sample.rest.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicInteger;
/**
package com.minikube.sample.rest.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicInteger;
package com.minikube.sample.rest.controller;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
/**
* Created by Eresh Gorantla on 09/May/2019
**/
package com.eresh.spring.persistence.repository;
import com.eresh.spring.persistence.entity.Author;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
package com.eresh.spring.persistence.entity;
import lombok.Data;
import org.springframework.data.mongodb.core.index.TextIndexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* Created By Gorantla, Eresh on 12/Dec/2019
**/
package com.eresh.spring.persistence.entity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedBy;
public Mono<WSAuthorResponse> findAuthors(Integer offset, Integer limit) {
WSAuthorResponse result = new WSAuthorResponse();
return authorRepository.count()
.map(totalElements -> {
result.setTotalElements(totalElements);
return totalElements;
})
.flatMapMany(el -> authorRepository.retrieveAllAuthors(PageRequest.of(offset, limit)))
.collectList()
.map(data -> {
public Mono<Author> saveAuthor(Author author) {
if (StringUtils.isNotBlank(author.getId())) {
return authorRepository.findByIdAndDeleteIsFalse(author.getId())
.switchIfEmpty(Mono.error(new Exception("No Author found with Id: " + author.getId())))
.doOnSuccess(author1 -> {
author1 = updateAuthor(author, author1);
authorRepository.save(author1)
.subscribe();
});
}
package com.eresh.spring.rest;
import com.eresh.spring.persistence.entity.Author;
import com.eresh.spring.persistence.repository.AuthorRepository;
import com.eresh.spring.rest.ws.WSAuthorResponse;
import com.eresh.spring.service.AuthorService;
import reactor.core.publisher.Mono;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;