Skip to content

Commit

Permalink
feat(be:FSADT1-500): adding last endpoint
Browse files Browse the repository at this point in the history
- added unregistered clients endpoint
  • Loading branch information
Paulo Gomes da Cruz Junior committed Jan 13, 2023
1 parent ed6dbac commit 80d026b
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public record OrgBookResultListResponse(
@Schema(description = "The list of named results")
List<OrgBookNameDto> results
) {
public boolean empty(){
return results == null || results.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ca.bc.gov.app.handlers;

import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder;
import static org.springdoc.core.fn.builders.arrayschema.Builder.arraySchemaBuilder;
import static org.springdoc.core.fn.builders.content.Builder.contentBuilder;
import static org.springdoc.core.fn.builders.schema.Builder.schemaBuilder;

import ca.bc.gov.app.dto.ClientPublicViewDto;
import ca.bc.gov.app.service.ForestClientService;
import ca.bc.gov.app.util.HandlerUtil;
import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.fn.builders.operation.Builder;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ResponseStatusException;
import reactor.core.publisher.Mono;

@Component
@RequiredArgsConstructor
@Slf4j
public class ForestClientUnregisteredHandler implements BaseHandler {

private final ForestClientService service;
@Override
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
return ServerResponse
.ok()
.body(service.getUnregisteredCompanies(), ClientPublicViewDto.class)
.doOnError(ResponseStatusException.class, HandlerUtil.handleStatusResponse())
.doOnError(HandlerUtil.handleError());
}

@Override
public Consumer<Builder> documentation(String tag) {
return ops -> ops.tag(tag)
.description("List all clients that are unregistered")
.beanClass(ForestClientUnregisteredHandler.class)
.beanMethod("handle")
.operationId("handle")
.response(
responseBuilder()
.responseCode("200")
.description("Found")
.content(
contentBuilder()
.array(
arraySchemaBuilder()
.schema(
schemaBuilder()
.name("ClientInformation")
.implementation(ClientPublicViewDto.class)
)
)
.mediaType(MediaType.APPLICATION_JSON_VALUE)
)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ca.bc.gov.app.service;

import static java.util.function.Predicate.not;

import ca.bc.gov.app.dto.ClientPublicViewDto;
import ca.bc.gov.app.dto.FirstNationBandVidationDto;
import ca.bc.gov.app.dto.OrgBookResultListResponse;
Expand Down Expand Up @@ -48,6 +50,7 @@ public Flux<ClientPublicViewDto> getClientDoingBusiness() {
.findAll()
.flatMap(entity ->
findByClientName(entity.getDoingBusinessAsName())
.filter(not(OrgBookResultListResponse::empty))
.map(orgBookResponse ->
new ClientPublicViewDto(
entity.getClientNumber(),
Expand All @@ -58,7 +61,47 @@ public Flux<ClientPublicViewDto> getClientDoingBusiness() {
null,
null,
orgBookResponse.results().get(0).value()
//TODO: This need to be validated
)
)
.switchIfEmpty(
Mono
.just(
new ClientPublicViewDto(
entity.getClientNumber(),
null,
entity.getDoingBusinessAsName(),
null,
null,
null,
null,
null
)
)
)
);
}

public Flux<ClientPublicViewDto> getUnregisteredCompanies() {
return
forestClientRepository
.findAll()
.flatMap(entity ->
findByClientName(entity.getClientName())
.filter(not(OrgBookResultListResponse::empty))
.map(orgBookResponse ->
new ClientPublicViewDto(
entity.getClientNumber(),
StringUtils
.equals(
orgBookResponse.results().get(0).value(),
entity.getClientName()
) ? orgBookResponse.results().get(0).topicSourceId() : null,
entity.getClientName(),
null,
null,
null,
null,
orgBookResponse.results().get(0).value()
)
)
);
Expand Down

0 comments on commit 80d026b

Please sign in to comment.