Skip to content

Commit

Permalink
Merge pull request #2418 from objectcomputing/feature-2410/remove-rea…
Browse files Browse the repository at this point in the history
…ctive-code

remove unnecessary reactive code
  • Loading branch information
mkimberlin authored May 28, 2024
2 parents 1017cf8 + c270147 commit f7b2fae
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ public LocalLoginController(Authenticator authenticator,

@View("login")
@Get
public Mono<Map<String, String>> login() {
return Mono.just(Collections.emptyMap());
public Map<String, String> login() {
return Collections.emptyMap();
}

@ExecuteOn(TaskExecutors.BLOCKING)
@Consumes({MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON})
@Post
public Mono<Object> auth(HttpRequest<?> request, String email, String role) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
import io.micronaut.http.uri.UriBuilder;
import io.micronaut.scheduling.TaskExecutors;
import io.micronaut.scheduling.annotation.ExecuteOn;
import io.micronaut.security.annotation.Secured;
Expand All @@ -21,15 +23,16 @@
import java.util.Set;
import java.util.UUID;

@Controller("/services/agenda-items")
@Controller(AgendaItemController.PATH)
@ExecuteOn(TaskExecutors.BLOCKING)
@Secured(SecurityRule.IS_AUTHENTICATED)
@Tag(name = "agenda-items")
public class AgendaItemController {
class AgendaItemController {
public static final String PATH = "/services/agenda-items";

private final AgendaItemServices agendaItemServices;

public AgendaItemController(AgendaItemServices agendaItemServices) {
AgendaItemController(AgendaItemServices agendaItemServices) {
this.agendaItemServices = agendaItemServices;
}

Expand All @@ -41,10 +44,11 @@ public AgendaItemController(AgendaItemServices agendaItemServices) {
*/
@Post("/")
@RequiredPermission(Permission.CAN_CREATE_CHECKINS)
public Mono<HttpResponse<AgendaItem>> createAgendaItem(@Body @Valid AgendaItemCreateDTO agendaItem, HttpRequest<?> request) {
return Mono.fromCallable(() -> agendaItemServices.save(new AgendaItem(agendaItem.getCheckinid(), agendaItem.getCreatedbyid(), agendaItem.getDescription())))
.map(createAgendaItem -> HttpResponse.created(createAgendaItem)
.headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getPath(), createAgendaItem.getId())))));
HttpResponse<AgendaItem> createAgendaItem(@Body @Valid AgendaItemCreateDTO agendaItem) {
AgendaItem createAgendaItem = agendaItemServices.save(new AgendaItem(agendaItem.getCheckinid(), agendaItem.getCreatedbyid(), agendaItem.getDescription()));
URI location = UriBuilder.of(PATH).path(createAgendaItem.getId().toString()).build();
return HttpResponse.created(createAgendaItem)
.headers(headers -> headers.location(location));
}

/**
Expand All @@ -55,14 +59,14 @@ public Mono<HttpResponse<AgendaItem>> createAgendaItem(@Body @Valid AgendaItemCr
*/
@Put("/")
@RequiredPermission(Permission.CAN_UPDATE_CHECKINS)
public Mono<HttpResponse<AgendaItem>> updateAgendaItem(@Body @Valid AgendaItem agendaItem, HttpRequest<?> request) {
HttpResponse<?> updateAgendaItem(@Body @Valid AgendaItem agendaItem) {
if (agendaItem == null) {
return Mono.just(HttpResponse.ok());
return HttpResponse.ok();
}
return Mono.fromCallable(() -> agendaItemServices.update(agendaItem))
.map(updatedAgendaItem ->
HttpResponse.ok(updatedAgendaItem)
.headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getPath(), updatedAgendaItem.getId())))));
AgendaItem updatedAgendaItem = agendaItemServices.update(agendaItem);
URI location = UriBuilder.of(PATH).path(updatedAgendaItem.getId().toString()).build();
return HttpResponse.ok(updatedAgendaItem)
.headers(headers -> headers.location(location));
}

/**
Expand All @@ -74,9 +78,8 @@ public Mono<HttpResponse<AgendaItem>> updateAgendaItem(@Body @Valid AgendaItem a
*/
@Get("/{?checkinid,createdbyid}")
@RequiredPermission(Permission.CAN_VIEW_CHECKINS)
public Mono<HttpResponse<Set<AgendaItem>>> findAgendaItems(@Nullable UUID checkinid, @Nullable UUID createdbyid) {
return Mono.fromCallable(() -> agendaItemServices.findByFields(checkinid, createdbyid))
.map(HttpResponse::ok);
Set<AgendaItem> findAgendaItems(@Nullable UUID checkinid, @Nullable UUID createdbyid) {
return agendaItemServices.findByFields(checkinid, createdbyid);
}

/**
Expand All @@ -87,11 +90,12 @@ public Mono<HttpResponse<Set<AgendaItem>>> findAgendaItems(@Nullable UUID checki
*/
@Get("/{id}")
@RequiredPermission(Permission.CAN_VIEW_CHECKINS)
public Mono<HttpResponse<AgendaItem>> readAgendaItem(UUID id) {
return Mono.fromCallable(() -> agendaItemServices.read(id))
.switchIfEmpty(Mono.error(new NotFoundException("No agenda item for UUID")))
.map(HttpResponse::ok);

AgendaItem readAgendaItem(UUID id) {
AgendaItem read = agendaItemServices.read(id);
if (read == null) {
throw new NotFoundException("No agenda item for UUID");
}
return read;
}

/**
Expand All @@ -100,8 +104,8 @@ public Mono<HttpResponse<AgendaItem>> readAgendaItem(UUID id) {
* @param id, id of {@link AgendaItem} to delete
*/
@Delete("/{id}")
public Mono<HttpResponse<?>> deleteAgendaItem(UUID id) {
return Mono.fromRunnable(() -> agendaItemServices.delete(id))
.thenReturn(HttpResponse.ok());
@Status(HttpStatus.OK)
void deleteAgendaItem(UUID id) {
agendaItemServices.delete(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
import io.micronaut.http.uri.UriBuilder;
import io.micronaut.scheduling.TaskExecutors;
import io.micronaut.scheduling.annotation.ExecuteOn;
import io.micronaut.security.annotation.Secured;
Expand All @@ -19,19 +21,18 @@
import java.util.Set;
import java.util.UUID;

@Controller("/services/checkin-documents")
@Controller(CheckinDocumentController.PATH)
@ExecuteOn(TaskExecutors.BLOCKING)
@Secured({RoleType.Constants.ADMIN_ROLE, RoleType.Constants.PDL_ROLE})
@Tag(name = "checkin documents")
public class CheckinDocumentController {
class CheckinDocumentController {
public static final String PATH = "/services/checkin-documents";
private final CheckinDocumentServices checkinDocumentService;

public CheckinDocumentController(CheckinDocumentServices checkinDocumentService){
CheckinDocumentController(CheckinDocumentServices checkinDocumentService){
this.checkinDocumentService = checkinDocumentService;
}


/**
* Find CheckinDocument(s) based on checkinsId
*
Expand All @@ -41,9 +42,8 @@ public CheckinDocumentController(CheckinDocumentServices checkinDocumentService)

@Get("/{?checkinsId}")
@RequiredPermission(Permission.CAN_VIEW_CHECKIN_DOCUMENT)
public Mono<HttpResponse<Set<CheckinDocument>>> findCheckinDocument(@Nullable UUID checkinsId) {
return Mono.fromCallable(() -> checkinDocumentService.read(checkinsId))
.map(HttpResponse::ok);
Set<CheckinDocument> findCheckinDocument(@Nullable UUID checkinsId) {
return checkinDocumentService.read(checkinsId);
}

/**
Expand All @@ -55,11 +55,10 @@ public Mono<HttpResponse<Set<CheckinDocument>>> findCheckinDocument(@Nullable UU

@Post
@RequiredPermission(Permission.CAN_CREATE_CHECKIN_DOCUMENT)
public Mono<HttpResponse<CheckinDocument>> createCheckinDocument(@Body @Valid CheckinDocumentCreateDTO checkinDocument,
HttpRequest<?> request) {
return Mono.fromCallable(() -> checkinDocumentService.save(new CheckinDocument(checkinDocument.getCheckinsId(),checkinDocument.getUploadDocId())))
.map(createdCheckinDocument -> HttpResponse.created(createdCheckinDocument)
.headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getPath(), createdCheckinDocument.getId())))));
HttpResponse<CheckinDocument> createCheckinDocument(@Body @Valid CheckinDocumentCreateDTO checkinDocument) {
CheckinDocument createdCheckinDocument = checkinDocumentService.save(new CheckinDocument(checkinDocument.getCheckinsId(), checkinDocument.getUploadDocId()));
URI location = UriBuilder.of(PATH).path(createdCheckinDocument.getId().toString()).build();
return HttpResponse.created(createdCheckinDocument, location);
}

/**
Expand All @@ -70,27 +69,26 @@ public Mono<HttpResponse<CheckinDocument>> createCheckinDocument(@Body @Valid Ch
*/
@Put
@RequiredPermission(Permission.CAN_UPDATE_CHECKIN_DOCUMENT)
public Mono<HttpResponse<CheckinDocument>> update(@Body @Valid CheckinDocument checkinDocument, HttpRequest<?> request) {
HttpResponse<?> update(@Body @Valid CheckinDocument checkinDocument) {
if (checkinDocument == null) {
return Mono.just(HttpResponse.ok());
return HttpResponse.ok();
}
return Mono.fromCallable(() -> checkinDocumentService.update(checkinDocument))
.map(updatedCheckinDocument -> HttpResponse.ok(updatedCheckinDocument)
.headers(headers -> headers.location(URI.create(String.format("%s/%s", request.getPath(), updatedCheckinDocument.getId())))));
CheckinDocument updatedCheckinDocument = checkinDocumentService.update(checkinDocument);
URI location = UriBuilder.of(PATH).path(updatedCheckinDocument.getId().toString()).build();
return HttpResponse.ok(updatedCheckinDocument)
.headers(headers -> headers.location(location));

}

/**
* Delete a CheckinDocument
*
* @param checkinsId, id of the checkins record you wish to delete
* @return {@link HttpResponse<>}
*/
@Delete("/{checkinsId}")
@RequiredPermission(Permission.CAN_DELETE_CHECKIN_DOCUMENT)
public Mono<HttpResponse<?>> delete(UUID checkinsId) {
return Mono.fromRunnable(() -> checkinDocumentService.deleteByCheckinId(checkinsId))
.thenReturn(HttpResponse.noContent());

@Status(HttpStatus.NO_CONTENT)
void delete(UUID checkinsId) {
checkinDocumentService.deleteByCheckinId(checkinsId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.objectcomputing.checkins.services.permissions.Permission;
import com.objectcomputing.checkins.services.permissions.RequiredPermission;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.MutableHttpResponse;
Expand All @@ -23,19 +24,16 @@
import java.io.File;
import java.util.concurrent.ExecutorService;

@Controller("/services/reports/member")
@Controller(MemberProfileReportController.PATH)
@ExecuteOn(TaskExecutors.BLOCKING)
@Secured(SecurityRule.IS_AUTHENTICATED)
public class MemberProfileReportController {

class MemberProfileReportController {
public static final String PATH = "/services/reports/member";
private static final Logger LOG = LoggerFactory.getLogger(com.objectcomputing.checkins.services.memberprofile.MemberProfileController.class);
private final MemberProfileReportServices memberProfileReportServices;
private final Scheduler ioScheduler;

public MemberProfileReportController(MemberProfileReportServices memberProfileReportServices,
@Named(TaskExecutors.IO) ExecutorService ioExecutorService) {
MemberProfileReportController(MemberProfileReportServices memberProfileReportServices) {
this.memberProfileReportServices = memberProfileReportServices;
this.ioScheduler = Schedulers.fromExecutorService(ioExecutorService);
}

/**
Expand All @@ -45,17 +43,16 @@ public MemberProfileReportController(MemberProfileReportServices memberProfileRe
*/
@Post(produces = MediaType.TEXT_CSV)
@RequiredPermission(Permission.CAN_VIEW_PROFILE_REPORT)
public Mono<MutableHttpResponse<File>> getCsvFile(@Nullable @Body MemberProfileReportQueryDTO dto) {
return Mono.defer(() -> Mono.just(memberProfileReportServices.generateFile(dto)))
.subscribeOn(ioScheduler)
.map(file -> HttpResponse
.ok(file)
.header("Content-Disposition", String.format("attachment; filename=%s", file.getName())))
.onErrorResume(error -> {
LOG.error("Something went terribly wrong during export... ", error);
return Mono.just(HttpResponse.serverError());
});
HttpResponse<File> getCsvFile(@Nullable @Body MemberProfileReportQueryDTO dto) {
try {
File file = memberProfileReportServices.generateFile(dto);
return HttpResponse
.ok(file)
.header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=%s", file.getName()));
} catch (Exception error) {
LOG.error("Something went terribly wrong during export... ", error);
return HttpResponse.serverError();
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
import io.micronaut.http.uri.UriBuilder;
import io.micronaut.scheduling.TaskExecutors;
import io.micronaut.scheduling.annotation.ExecuteOn;
import io.micronaut.security.annotation.Secured;
Expand All @@ -20,15 +21,16 @@
import java.util.Set;
import java.util.UUID;

@Controller("/services/private-notes")
@Controller(PrivateNoteController.PATH)
@ExecuteOn(TaskExecutors.BLOCKING)
@Secured(SecurityRule.IS_AUTHENTICATED)
@Tag(name = "private-notes")
public class PrivateNoteController {
class PrivateNoteController {
public static final String PATH = "/services/private-notes";

private final PrivateNoteServices privateNoteServices;

public PrivateNoteController(PrivateNoteServices privateNoteServices) {
PrivateNoteController(PrivateNoteServices privateNoteServices) {
this.privateNoteServices = privateNoteServices;
}

Expand All @@ -41,13 +43,11 @@ public PrivateNoteController(PrivateNoteServices privateNoteServices) {
*/
@Post
@RequiredPermission(Permission.CAN_CREATE_PRIVATE_NOTE)
public Mono<HttpResponse<PrivateNote>> createPrivateNote(@Body @Valid PrivateNoteCreateDTO privateNote, HttpRequest<?> request) {
return Mono.fromCallable(() -> privateNoteServices.save(new PrivateNote(privateNote.getCheckinid(),
privateNote.getCreatedbyid(), privateNote.getDescription())))
.map(createPrivateNote -> HttpResponse.created(createPrivateNote)
.headers(headers -> headers.location(
URI.create(String.format("%s/%s", request.getPath(), createPrivateNote.getId())))));

HttpResponse<PrivateNote> createPrivateNote(@Body @Valid PrivateNoteCreateDTO privateNote, HttpRequest<?> request) {
PrivateNote createPrivateNote = privateNoteServices.save(new PrivateNote(privateNote.getCheckinid(), privateNote.getCreatedbyid(), privateNote.getDescription()));
URI location = UriBuilder.of(PATH).path(createPrivateNote.getId().toString()).build();
return HttpResponse.created(createPrivateNote)
.headers(headers -> headers.location(location));
}

/**
Expand All @@ -59,15 +59,14 @@ public Mono<HttpResponse<PrivateNote>> createPrivateNote(@Body @Valid PrivateNot
*/
@Put
@RequiredPermission(Permission.CAN_UPDATE_PRIVATE_NOTE)
public Mono<HttpResponse<PrivateNote>> updatePrivateNote(@Body @Valid PrivateNote privateNote, HttpRequest<?> request) {
HttpResponse<PrivateNote> updatePrivateNote(@Body @Valid PrivateNote privateNote, HttpRequest<?> request) {
if (privateNote == null) {
return Mono.just(HttpResponse.ok());
return HttpResponse.ok();
}
return Mono.fromCallable(() -> privateNoteServices.update(privateNote))
.map(updatePrivateNote ->
HttpResponse.ok(updatePrivateNote)
.headers(headers -> headers.location(
URI.create(String.format("%s/%s", request.getPath(), updatePrivateNote.getId())))));
PrivateNote updatePrivateNote = privateNoteServices.update(privateNote);
URI location = UriBuilder.of(PATH).path(updatePrivateNote.getId().toString()).build();
return HttpResponse.ok(updatePrivateNote)
.headers(headers -> headers.location(location));
}

/**
Expand All @@ -79,9 +78,9 @@ public Mono<HttpResponse<PrivateNote>> updatePrivateNote(@Body @Valid PrivateNot
*/
@Get("/{?checkinid,createdbyid}")
@RequiredPermission(Permission.CAN_VIEW_PRIVATE_NOTE)
public Mono<Set<PrivateNote>> findPrivateNote(@Nullable UUID checkinid,
public Set<PrivateNote> findPrivateNote(@Nullable UUID checkinid,
@Nullable UUID createdbyid) {
return Mono.fromCallable(() -> privateNoteServices.findByFields(checkinid, createdbyid));
return privateNoteServices.findByFields(checkinid, createdbyid);
}

/**
Expand All @@ -92,15 +91,11 @@ public Mono<Set<PrivateNote>> findPrivateNote(@Nullable UUID checkinid,
*/
@Get("/{id}")
@RequiredPermission(Permission.CAN_VIEW_PRIVATE_NOTE)
public Mono<HttpResponse<PrivateNote>> readPrivateNote(UUID id) {
return Mono.fromCallable(() -> {
PrivateNote result = privateNoteServices.read(id);
if (result == null) {
throw new NotFoundException("No private note for UUID");
}
return result;
}).map(HttpResponse::ok);

public PrivateNote readPrivateNote(UUID id) {
PrivateNote result = privateNoteServices.read(id);
if (result == null) {
throw new NotFoundException("No private note for UUID");
}
return result;
}

}
Loading

0 comments on commit f7b2fae

Please sign in to comment.