Skip to content

Commit

Permalink
prepare for courseService imports
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlxs committed Dec 30, 2024
1 parent 639ffd8 commit e45d62e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.unistuttgart.iste.meitrex.assignment_service.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.graphql.client.GraphQlClient;
import org.springframework.graphql.client.HttpGraphQlClient;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class CourseServiceClientConfiguration {

@Value("${course_service.url}")
private String courseServiceUrl;

@Bean
public CourseServiceClient courseServiceClient() {
final WebClient webClient = WebClient.builder().baseUrl(courseServiceUrl).build();
final GraphQlClient graphQlClient = HttpGraphQlClient.builder(webClient).build();
return new CourseServiceClient(graphQlClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class UserServiceClientConfiguration {
private String userServiceUrl;

@Bean
public GraphQlClient userServiceClient() {
public UserServiceClient userServiceClient() {
final WebClient webClient = WebClient.builder().baseUrl(userServiceUrl).build();
return HttpGraphQlClient.builder(webClient).build();
final GraphQlClient graphQlClient = HttpGraphQlClient.builder(webClient).build();
return new UserServiceClient(graphQlClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.unistuttgart.iste.meitrex.assignment_service.exception.ExternalPlatformConnectionException;
import de.unistuttgart.iste.meitrex.assignment_service.exception.ManualMappingRequiredException;
import de.unistuttgart.iste.meitrex.user_service.exception.UserServiceConnectionException;
import de.unistuttgart.iste.meitrex.course_service.exception.CourseServiceConnectionException;
import de.unistuttgart.iste.meitrex.assignment_service.persistence.entity.*;
import de.unistuttgart.iste.meitrex.assignment_service.persistence.mapper.AssignmentMapper;
import de.unistuttgart.iste.meitrex.assignment_service.persistence.repository.GradingRepository;
Expand Down Expand Up @@ -103,7 +104,7 @@ public void importGradingsForAssignment(final UUID assignmentId, final LoggedInU
final List<UserInfo> meitrexStudentInfoList;
try {
meitrexStudentInfoList = getMeitrexStudentInfoList();
} catch (UserServiceConnectionException e){
} catch (UserServiceConnectionException | CourseServiceConnectionException e){
throw new RuntimeException(e); // wrapping exception
// return; TODO return or throw wrapped exception?
}
Expand Down Expand Up @@ -349,12 +350,10 @@ private JSONObject getExternalStudentInfo(final String externalStudentId) throws
return new JSONObject(body);
}

private List<UserInfo> getMeitrexStudentInfoList() throws UserServiceConnectionException, CourseServiceConnectionException {

// TODO this whole thing should be in userService rather than here
private List<UserInfo> getMeitrexStudentInfoList() throws UserServiceConnectionException {

final List<UUID> userIds = courseServiceClient.queryUserIds(); // TODO needs to be queried from course service

final List<CourseMembership> userMemberships = courseServiceClient.queryMembershipsInCourse();
List<UUID> userIds = userMemberships.stream().map(CourseMembership::getUserId).toList();
final List<UserInfo> meitrexStudentInfoList = userServiceClient.queryUserInfos(userIds);

return meitrexStudentInfoList;
Expand Down Expand Up @@ -383,7 +382,7 @@ public List<String> saveStudentMappings(final UUID courseId, final List<StudentM
final List<UserInfo> meitrexStudentInfoList;
try {
meitrexStudentInfoList = getMeitrexStudentInfoList();
} catch (UserServiceConnectionException e){
} catch (UserServiceConnectionException | CourseServiceConnectionException e){
throw new RuntimeException(e); // wrapping exception
// return null; TODO return null or throw wrapped exception?
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ server.max-http-request-header-size=64000
# enable probing used by kubernetes
management.endpoint.health.probes.enabled=true
management.health.livenessstate.enabled=true
management.health.readinessState.enabled=true
management.health.readinessState.enabled=true

# URLs for course and user service
course_service.url=http://localhost:2001/graphql
user_service.url=http://localhost:5001/graphql

0 comments on commit e45d62e

Please sign in to comment.