Creates all missing handlers, and routes for teams
This commit is contained in:
@@ -1,4 +1,26 @@
|
||||
package net.szymonsawicki.reactivetimesheetapp.web;
|
||||
|
||||
import net.szymonsawicki.reactivetimesheetapp.web.handler.TeamHandlers;
|
||||
import net.szymonsawicki.reactivetimesheetapp.web.handler.TimeEntryHandlers;
|
||||
import net.szymonsawicki.reactivetimesheetapp.web.handler.UserHandlers;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.server.RequestPredicates;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.RouterFunctions;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
@Configuration
|
||||
public class Routing {
|
||||
@Bean
|
||||
public RouterFunction<ServerResponse> routingFunction(TeamHandlers teamHandlers, TimeEntryHandlers timeEntryHandlers, UserHandlers userHandlers) {
|
||||
return RouterFunctions.nest(
|
||||
RequestPredicates.path("/teams/"
|
||||
), RouterFunctions.route(RequestPredicates.GET("/{name}")
|
||||
.and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), teamHandlers::findByName)
|
||||
.andRoute(RequestPredicates.GET("/id/{id}").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), teamHandlers::findById)
|
||||
.andRoute(RequestPredicates.POST("/").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), teamHandlers::addTeam)
|
||||
.andRoute(RequestPredicates.DELETE("/{id}").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), teamHandlers::deleteTeam));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package net.szymonsawicki.reactivetimesheetapp.web.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.szymonsawicki.reactivetimesheetapp.application.service.TeamService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TeamHandler {
|
||||
private final TeamService teamService;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package net.szymonsawicki.reactivetimesheetapp.web.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.szymonsawicki.reactivetimesheetapp.application.service.TeamService;
|
||||
import net.szymonsawicki.reactivetimesheetapp.domain.team.dto.CreateTeamDto;
|
||||
import net.szymonsawicki.reactivetimesheetapp.web.config.GlobalRoutingHandler;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TeamHandlers {
|
||||
private final TeamService teamService;
|
||||
|
||||
public Mono<ServerResponse> findById(ServerRequest serverRequest) {
|
||||
var teamId = serverRequest.pathVariable("id");
|
||||
return GlobalRoutingHandler.doRequest(teamService.findById(teamId), HttpStatus.OK);
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> findByName(ServerRequest serverRequest) {
|
||||
var teamName = serverRequest.pathVariable("name");
|
||||
return GlobalRoutingHandler.doRequest(teamService.findByName(teamName), HttpStatus.OK);
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> addTeam(ServerRequest serverRequest) {
|
||||
var createTeamDtoMono = serverRequest.bodyToMono(CreateTeamDto.class);
|
||||
return GlobalRoutingHandler.doRequest(teamService.addTeam(createTeamDtoMono), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> deleteTeam(ServerRequest serverRequest) {
|
||||
var teamId = serverRequest.pathVariable("id");
|
||||
return GlobalRoutingHandler.doRequest(teamService.deleteTeam(teamId), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package net.szymonsawicki.reactivetimesheetapp.web.handler;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.szymonsawicki.reactivetimesheetapp.application.service.TimeEntryService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TimeEntryHandler {
|
||||
private final TimeEntryService timeEntryService;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.szymonsawicki.reactivetimesheetapp.web.handler;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.szymonsawicki.reactivetimesheetapp.application.service.TimeEntryService;
|
||||
import net.szymonsawicki.reactivetimesheetapp.domain.time_entry.dto.CreateTimeEntryDto;
|
||||
import net.szymonsawicki.reactivetimesheetapp.web.config.GlobalRoutingHandler;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TimeEntryHandlers {
|
||||
private final TimeEntryService timeEntryService;
|
||||
|
||||
public Mono<ServerResponse> addTimeEntry(ServerRequest serverRequest) {
|
||||
var createTimeEntryDtoMono = serverRequest.bodyToMono(CreateTimeEntryDto.class);
|
||||
return GlobalRoutingHandler.doRequest(timeEntryService.addTimeEntry(createTimeEntryDtoMono), HttpStatus.CREATED);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class UserHandler {
|
||||
public class UserHandlers {
|
||||
private final UserService userService;
|
||||
|
||||
public Mono<ServerResponse> findById(ServerRequest serverRequest) {
|
||||
@@ -27,8 +27,8 @@ public class UserHandler {
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> createUser(ServerRequest serverRequest) {
|
||||
var createUsertDtoMono = serverRequest.bodyToMono(CreateUserDto.class);
|
||||
return GlobalRoutingHandler.doRequest(userService.addUser(createUsertDtoMono), HttpStatus.CREATED);
|
||||
var createUserDtoMono = serverRequest.bodyToMono(CreateUserDto.class);
|
||||
return GlobalRoutingHandler.doRequest(userService.addUser(createUserDtoMono), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> deleteUser(ServerRequest serverRequest) {
|
||||
Reference in New Issue
Block a user