Permalink
Browse files

changes during validation for parameters

  • Loading branch information...
dgkncelik committed May 22, 2018
1 parent 5ea7758 commit ec6f9173625ffc284953118fc7eb69a6195f7b90
@@ -78,6 +78,7 @@
*/
Component getComponentById(Long id);
Component getComponentByOwner(Participant owner);
/**
* delete a component
*
@@ -142,6 +142,17 @@ public Component getComponentById(Long id){
/**
* {@inheritDoc}
*/
@Override
public Component getComponentByOwner(Participant owner){
Assert.notNull(owner, "Owner participant cannot be null");
if(!icalService.getComponentByOwner(owner).isPresent()){
throw new NotFound("No component found for participant: " + owner.getUserName());
}
return icalService.getComponentByOwner(owner).get();
}
@Override
public void deleteComponentById(Long id){
Assert.notNull(id, "Id must not be null!");
@@ -43,18 +43,24 @@ public Response createComponent(@RequestParam(value = "user_name") String userNa
return new Response(0,"created");
}
@ApiOperation(value = "Get component with id = {component_id}")
@ApiOperation(value = "Get component with id or components owner username = {component_key}")
@ApiResponses({
@ApiResponse(code = 200, message = "Successfully get component with id = {component_id}", response = ComponentResponse.class),
@ApiResponse(code = 400, message = "Bad request", response = ErrorResponse.class),
@ApiResponse(code = 401, message = "Unauthorized request", response = ErrorResponse.class),
@ApiResponse(code = 403, message = "Forbidden", response = ErrorResponse.class),
@ApiResponse(code = 404, message = "No component found with id = {component_id}", response = ErrorResponse.class),
})
@GetMapping(value = "/{component_id}", produces = "application/json")
@GetMapping(value = "/{component_key}", produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public ComponentResponse getComponent(@PathVariable(value = "component_id")Long componentId){
return new ComponentResponse(0,null,calendarManagerService.getComponentById(componentId));
public ComponentResponse getComponent(@PathVariable(value = "component_key")String componentKey){
Long componentIdLong;
try {
componentIdLong = Long.parseLong(componentKey);
return new ComponentResponse(0,null,calendarManagerService.getComponentById(componentIdLong));
}catch (Exception e){
return new ComponentResponse(0,null,calendarManagerService.getComponentByOwner(calendarManagerService.getParticipantByUserName(componentKey)));
}
}
@ApiOperation(value = "Update component with id = {component_id}")
@@ -11,5 +11,5 @@
@Repository
public interface ComponentRepository extends JpaRepository<Component, Long> {
Optional<Component> findById(Long Id);
List<Component> findByOwner(Participant owner);
Optional<Component> findByOwner(Participant owner);
}
@@ -26,6 +26,7 @@
*/
Optional<Component> getComponentById(Long id);
Optional<Component> getComponentByOwner(Participant owner);
/**
* saves given component
*
@@ -89,6 +89,12 @@ public Component createComponentForParticipant(ComponentType componentType, Part
/**
* {@inheritDoc}
*/
@Override
public Optional<Component> getComponentByOwner(Participant owner){
return componentRepository.findByOwner(owner);
}
@Override
public void saveComponent(Component component){
componentRepository.save(component);

0 comments on commit ec6f917

Please sign in to comment.