src/main/java/br/eng/joaofaro/taskmanager/repository/service/TaskService.java
/**
     * <p>Method responsible to find <code>tasks</code> by id</p>
     * @param id - task id
     * @return - Task object
     * @throws TaskManagerException - throws a exception to handle result
     * @throws TaskNotFoundException - throws a exception to handle result
     */
Method responsible to find tasks by id
@param id - task id
@return - Task object
@throws TaskManagerException - throws a exception to handle result
@throws TaskNotFoundException - throws a exception to handle result
Method responsible to find tasks by id @param id - task id @return - Task object @throws TaskManagerException - throws a exception to handle result @throws TaskNotFoundException - throws a exception to handle result
public Task findById(Long id) throws TaskManagerException, TaskNotFoundException {
        log.info("Searching task by id: {}", id);
        try {
            Optional<Task> task = repository.findById(id);
            if (task.isPresent()) {
                log.info("Task has been found");
                return task.get();
            }else {
                log.warn("Tasks not found");
                throw new TaskNotFoundException("Tasks not found in database");
            }
        }catch (Exception e) {
            if (e instanceof TaskNotFoundException) {
                log.warn("Tasks not found in database");
                throw new TaskNotFoundException("Tasks not found in database: "+ e.getMessage());
            }else {
                log.error("Error when trying to find task in database: {}", e.getMessage());
                throw new TaskManagerException("Error when trying to find task in database: "+ e.getMessage());
            }
        }
    }
public Task findById ( Long id ) throws TaskManagerException , TaskNotFoundException { log . info ( "Searching task by id: {}" , id ) ; try { Optional < Task > task = repository . findById ( id ) ; if ( task . isPresent ( ) ) { log . info ( "Task has been found" ) ; return task . get ( ) ; } else { log . warn ( "Tasks not found" ) ; throw new TaskNotFoundException ( "Tasks not found in database" ) ; } } catch ( Exception e ) { if ( e instanceof TaskNotFoundException ) { log . warn ( "Tasks not found in database" ) ; throw new TaskNotFoundException ( "Tasks not found in database: " + e . getMessage ( ) ) ; } else { log . error ( "Error when trying to find task in database: {}" , e . getMessage ( ) ) ; throw new TaskManagerException ( "Error when trying to find task in database: " + e . getMessage ( ) ) ; } } }
<p>Method responsible to find <code>tasks</code> by id</p>
 @param id - task id
 @return - Task object
 @throws TaskManagerException - throws a exception to handle result
 @throws TaskNotFoundException - throws a exception to handle result
<p > Method responsible to find <code > tasks< / code > by id< / p > @param id - task id @return - Task object @throws TaskManagerException - throws a exception to handle result @throws TaskNotFoundException - throws a exception to handle result