-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from MrSebastian/extends-graphql-task-with-ass…
…ignee Extends graphql task with assignee
- Loading branch information
Showing
9 changed files
with
113 additions
and
10 deletions.
There are no files selected for viewing
31 changes: 25 additions & 6 deletions
31
backend/src/main/java/de/mrsebastian/todoappdemo/backend/graphql/PostController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
package de.mrsebastian.todoappdemo.backend.graphql; | ||
|
||
import de.mrsebastian.todoappdemo.backend.person.rest.PersonDTO; | ||
import de.mrsebastian.todoappdemo.backend.graphql.types.Person; | ||
import de.mrsebastian.todoappdemo.backend.graphql.types.Task; | ||
import de.mrsebastian.todoappdemo.backend.graphql.types.TaskOfPerson; | ||
import de.mrsebastian.todoappdemo.backend.graphql.types.TypeMapper; | ||
import de.mrsebastian.todoappdemo.backend.person.service.PersonService; | ||
import de.mrsebastian.todoappdemo.backend.task.rest.TaskDTO; | ||
import de.mrsebastian.todoappdemo.backend.task.service.TaskService; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.graphql.data.method.annotation.QueryMapping; | ||
import org.springframework.graphql.data.method.annotation.SchemaMapping; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class PostController { | ||
|
||
private final TaskService taskService; | ||
|
||
private final PersonService personService; | ||
|
||
private final TypeMapper typeMapper; | ||
|
||
@QueryMapping | ||
public List<TaskDTO> getTasks() { | ||
return taskService.getTasks(); | ||
public List<Task> getTasks() { | ||
return taskService.getTasks().stream().map(taskDTO -> typeMapper.taskDtoToTaskType(taskDTO, null)).toList(); | ||
} | ||
|
||
@QueryMapping | ||
public List<PersonDTO> getPersons() { | ||
return personService.getPersonen(); | ||
public List<Person> getPersons() { | ||
return personService.getPersonen().stream().map(typeMapper::personDtoToPersonType).toList(); | ||
} | ||
|
||
@SchemaMapping | ||
public List<TaskOfPerson> tasks(Person person) { | ||
log.atDebug().log("collection tasks of person with id > {}", person.id()); | ||
|
||
if (person.id() == null) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return taskService.getTaskWithAssignee(person.id()).stream().map(typeMapper::taskDtoToTaskOfPersonType).toList(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/de/mrsebastian/todoappdemo/backend/graphql/types/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.mrsebastian.todoappdemo.backend.graphql.types; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.util.UUID; | ||
|
||
public record Person(@NotNull UUID id, String firstname, String lastname, @NotNull String email) { | ||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/de/mrsebastian/todoappdemo/backend/graphql/types/Task.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package de.mrsebastian.todoappdemo.backend.graphql.types; | ||
|
||
import de.mrsebastian.todoappdemo.backend.person.dataaccess.entity.Person; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.util.UUID; | ||
|
||
public record Task(@NotNull UUID id, @NotNull String title, @NotNull String description, String dueDate, | ||
Person creator, UUID assigneeId, Person assignee) { | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/de/mrsebastian/todoappdemo/backend/graphql/types/TaskOfPerson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package de.mrsebastian.todoappdemo.backend.graphql.types; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.util.UUID; | ||
|
||
public record TaskOfPerson(@NotNull UUID id, @NotNull String title, @NotNull String description, String dueDate, | ||
UUID creatorId, UUID assigneeId) { | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/de/mrsebastian/todoappdemo/backend/graphql/types/TypeMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package de.mrsebastian.todoappdemo.backend.graphql.types; | ||
|
||
import de.mrsebastian.todoappdemo.backend.person.rest.PersonDTO; | ||
import de.mrsebastian.todoappdemo.backend.task.rest.TaskDTO; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper | ||
public interface TypeMapper { | ||
|
||
Person personDtoToPersonType(PersonDTO personDTO); | ||
|
||
@Mapping(target = "id", source = "taskDTO.id") | ||
Task taskDtoToTaskType(TaskDTO taskDTO, PersonDTO assignee); | ||
|
||
@Mapping(target = "creatorId", source = "creator.id") | ||
TaskOfPerson taskDtoToTaskOfPersonType(TaskDTO taskDTO); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters