Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
184 additions
and
35 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/de/code_freak/codefreak/config/GraphQLConfiguration.kt
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.code_freak.codefreak.config | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter | ||
import javax.servlet.Filter | ||
|
||
@Configuration | ||
class GraphQLConfiguration { | ||
|
||
/** | ||
* Enable JPA lazy loading for GraphQL DTOs | ||
*/ | ||
@Bean | ||
fun openFilter(): Filter { | ||
return OpenEntityManagerInViewFilter() | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
src/main/kotlin/de/code_freak/codefreak/graphql/AssignmentApi.kt
This file was deleted.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/de/code_freak/codefreak/graphql/ServiceAccess.kt
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,16 @@ | ||
package de.code_freak.codefreak.graphql | ||
|
||
import de.code_freak.codefreak.service.BaseService | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.context.ApplicationContext | ||
import org.springframework.stereotype.Component | ||
import kotlin.reflect.KClass | ||
|
||
@Component | ||
class ServiceAccess { | ||
|
||
@Autowired | ||
private lateinit var applicationContext: ApplicationContext | ||
|
||
fun <T : BaseService> getService(type: KClass<T>): T = applicationContext.getBean(type.java) | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/de/code_freak/codefreak/graphql/api/AnswerApi.kt
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,25 @@ | ||
package de.code_freak.codefreak.graphql.api | ||
|
||
import com.expediagroup.graphql.annotations.GraphQLID | ||
import com.expediagroup.graphql.annotations.GraphQLIgnore | ||
import com.expediagroup.graphql.annotations.GraphQLName | ||
import de.code_freak.codefreak.entity.Answer | ||
import de.code_freak.codefreak.graphql.ServiceAccess | ||
import de.code_freak.codefreak.service.evaluation.EvaluationService | ||
import de.code_freak.codefreak.util.orNull | ||
|
||
@GraphQLName("Answer") | ||
class AnswerDto(@GraphQLIgnore val entity: Answer, @GraphQLIgnore val serviceAccess: ServiceAccess) { | ||
|
||
@GraphQLID | ||
val id = entity.id | ||
val submission by lazy { SubmissionDto(entity.submission, serviceAccess) } | ||
val task by lazy { TaskDto(entity.task, serviceAccess) } | ||
|
||
val latestEvaluation by lazy { | ||
serviceAccess.getService(EvaluationService::class) | ||
.getLatestEvaluation(id) | ||
.map { EvaluationDto(it, serviceAccess) } | ||
.orNull() | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/de/code_freak/codefreak/graphql/api/AssignmentApi.kt
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,56 @@ | ||
package de.code_freak.codefreak.graphql.api | ||
|
||
import com.expediagroup.graphql.annotations.GraphQLID | ||
import com.expediagroup.graphql.annotations.GraphQLIgnore | ||
import com.expediagroup.graphql.annotations.GraphQLName | ||
import com.expediagroup.graphql.spring.operations.Query | ||
import de.code_freak.codefreak.auth.Authority | ||
import de.code_freak.codefreak.auth.Role | ||
import de.code_freak.codefreak.entity.Assignment | ||
import de.code_freak.codefreak.graphql.ServiceAccess | ||
import de.code_freak.codefreak.service.AssignmentService | ||
import de.code_freak.codefreak.service.SubmissionService | ||
import de.code_freak.codefreak.util.FrontendUtil | ||
import graphql.schema.DataFetchingEnvironment | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.security.access.annotation.Secured | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@GraphQLName("Assignment") | ||
class AssignmentDto(@GraphQLIgnore val entity: Assignment, @GraphQLIgnore val serviceAccess: ServiceAccess) { | ||
|
||
@GraphQLID | ||
val id = entity.id | ||
val title = entity.title | ||
val owner by lazy { UserDto(entity.owner) } | ||
val deadline = entity.deadline | ||
val closed = entity.closed | ||
val tasks by lazy { entity.tasks.map { TaskDto(it, serviceAccess) } } | ||
|
||
val submissions by lazy { | ||
serviceAccess.getService(SubmissionService::class) | ||
.findSubmissionsOfAssignment(id) | ||
.map { SubmissionDto(it, serviceAccess) } | ||
} | ||
} | ||
|
||
@Component | ||
class AssignmentQuery : Query { | ||
|
||
@Autowired | ||
private lateinit var serviceAccess: ServiceAccess | ||
|
||
@Transactional | ||
@Secured(Authority.ROLE_STUDENT) | ||
fun assignments(env: DataFetchingEnvironment): List<AssignmentDto> { | ||
val assignmentService = serviceAccess.getService(AssignmentService::class) | ||
val user = FrontendUtil.getCurrentUser() | ||
val assignments = if (user.authorities.contains(Role.TEACHER)) { | ||
assignmentService.findAllAssignments() | ||
} else { | ||
assignmentService.findAllAssignmentsForUser(user.entity.id) | ||
} | ||
return assignments.map { AssignmentDto(it, serviceAccess) } | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...e/code_freak/codefreak/graphql/AuthApi.kt → ...de_freak/codefreak/graphql/api/AuthApi.kt
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
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/de/code_freak/codefreak/graphql/api/EvaluationApi.kt
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,25 @@ | ||
package de.code_freak.codefreak.graphql.api | ||
|
||
import com.expediagroup.graphql.annotations.GraphQLID | ||
import com.expediagroup.graphql.annotations.GraphQLIgnore | ||
import com.expediagroup.graphql.annotations.GraphQLName | ||
import de.code_freak.codefreak.entity.Evaluation | ||
import de.code_freak.codefreak.entity.EvaluationResult | ||
import de.code_freak.codefreak.graphql.ServiceAccess | ||
|
||
@GraphQLName("Evaluation") | ||
class EvaluationDto(@GraphQLIgnore val entity: Evaluation, @GraphQLIgnore val serviceAccess: ServiceAccess) { | ||
|
||
@GraphQLID | ||
val id = entity.id | ||
val answer by lazy { AnswerDto(entity.answer, serviceAccess) } | ||
val createdAt = entity.createdAt | ||
val results by lazy { entity.results.map { EvaluationResultDto(it) } } | ||
} | ||
|
||
@GraphQLName("EvaluationResult") | ||
class EvaluationResultDto(@GraphQLIgnore val entity: EvaluationResult) { | ||
val runnerName = entity.runnerName | ||
val position = entity.position | ||
val error = entity.error | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/de/code_freak/codefreak/graphql/api/SubmissionApi.kt
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,17 @@ | ||
package de.code_freak.codefreak.graphql.api | ||
|
||
import com.expediagroup.graphql.annotations.GraphQLID | ||
import com.expediagroup.graphql.annotations.GraphQLIgnore | ||
import com.expediagroup.graphql.annotations.GraphQLName | ||
import de.code_freak.codefreak.entity.Submission | ||
import de.code_freak.codefreak.graphql.ServiceAccess | ||
|
||
@GraphQLName("Submission") | ||
class SubmissionDto(@GraphQLIgnore val entity: Submission, @GraphQLIgnore val serviceAccess: ServiceAccess) { | ||
|
||
@GraphQLID | ||
val id = entity.id | ||
val user by lazy { UserDto(entity.user) } | ||
val assignment by lazy { AssignmentDto(entity.assignment, serviceAccess) } | ||
val answers by lazy { entity.answers.map { AnswerDto(it, serviceAccess) } } | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/de/code_freak/codefreak/graphql/api/TaskApi.kt
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.code_freak.codefreak.graphql.api | ||
|
||
import com.expediagroup.graphql.annotations.GraphQLID | ||
import com.expediagroup.graphql.annotations.GraphQLIgnore | ||
import com.expediagroup.graphql.annotations.GraphQLName | ||
import de.code_freak.codefreak.entity.Task | ||
import de.code_freak.codefreak.graphql.ServiceAccess | ||
|
||
@GraphQLName("Task") | ||
class TaskDto(@GraphQLIgnore val entity: Task, @GraphQLIgnore val serviceAccess: ServiceAccess) { | ||
|
||
@GraphQLID | ||
val id = entity.id | ||
val title = entity.title | ||
val position = entity.position | ||
val body = entity.body | ||
val assignment by lazy { AssignmentDto(entity.assignment, serviceAccess) } | ||
} |
2 changes: 1 addition & 1 deletion
2
...e/code_freak/codefreak/graphql/UserApi.kt → ...de_freak/codefreak/graphql/api/UserApi.kt
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