Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesStoehr committed Nov 11, 2024
1 parent 21c6624 commit 38f43be
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public CourseLearnerProfileService(CourseLearnerProfileRepository courseLearnerP
this.learnerProfileRepository = learnerProfileRepository;
}

/**
* Create a course learner profile for a user and saves it in the database
*
* @param course the course for which the profile is created
* @param user the user for which the profile is created
*/
public void createCourseLearnerProfile(Course course, User user) {
var courseProfile = new CourseLearnerProfile();
courseProfile.setCourse(course);
Expand All @@ -38,6 +44,12 @@ public void createCourseLearnerProfile(Course course, User user) {
courseLearnerProfileRepository.save(courseProfile);
}

/**
* Create course learner profiles for a set of users and saves them in the database.
*
* @param course the course for which the profiles are created
* @param users the users for which the profiles are created with eagerly loaded learner profiles
*/
public void createCourseLearnerProfiles(Course course, Set<User> users) {
Set<CourseLearnerProfile> courseProfiles = users.stream().map(user -> {
var courseProfile = new CourseLearnerProfile();
Expand All @@ -50,10 +62,21 @@ public void createCourseLearnerProfiles(Course course, Set<User> users) {
courseLearnerProfileRepository.saveAll(courseProfiles);
}

/**
* Delete a course learner profile for a user
*
* @param course the course for which the profile is deleted
* @param user the user for which the profile is deleted
*/
public void deleteCourseLearnerProfile(Course course, User user) {
courseLearnerProfileRepository.deleteByCourseAndUser(course, user);
}

/**
* Delete all course learner profiles for a course
*
* @param course the course for which the profiles are deleted
*/
public void deleteAllForCourse(Course course) {
courseLearnerProfileRepository.deleteAllByCourse(course);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.stereotype.Service;

import de.tum.cit.aet.artemis.atlas.domain.profile.LearnerProfile;
import de.tum.cit.aet.artemis.atlas.repository.CourseLearnerProfileRepository;
import de.tum.cit.aet.artemis.atlas.repository.LearnerProfileRepository;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.core.repository.UserRepository;
Expand All @@ -17,23 +16,30 @@ public class LearnerProfileService {

private final LearnerProfileRepository learnerProfileRepository;

private final CourseLearnerProfileRepository courseLearnerProfileRepository;

private final UserRepository userRepository;

public LearnerProfileService(LearnerProfileRepository learnerProfileRepository, CourseLearnerProfileRepository courseLearnerProfileRepository, UserRepository userRepository) {
public LearnerProfileService(LearnerProfileRepository learnerProfileRepository, UserRepository userRepository) {
this.learnerProfileRepository = learnerProfileRepository;
this.courseLearnerProfileRepository = courseLearnerProfileRepository;
this.userRepository = userRepository;
}

/**
* Create a learner profile for a user and saves it in the database
*
* @param user the user for which the profile is created
*/
public void createProfile(User user) {
var profile = new LearnerProfile();
profile.setUser(user);
user.setLearnerProfile(profile);
userRepository.save(user);
}

/**
* Delete the learner profile of a user
*
* @param user the user for which the profile is deleted
*/
public void deleteProfile(User user) {
learnerProfileRepository.deleteByUser(user);
}
Expand Down

0 comments on commit 38f43be

Please sign in to comment.