-
Notifications
You must be signed in to change notification settings - Fork 297
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
1 parent
7024d9a
commit 1eb6786
Showing
16 changed files
with
357 additions
and
39 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
src/main/java/de/tum/cit/aet/artemis/atlas/repository/CourseLearnerProfileRepository.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,31 @@ | ||
package de.tum.cit.aet.artemis.atlas.repository; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.profile.CourseLearnerProfile; | ||
import de.tum.cit.aet.artemis.core.domain.Course; | ||
import de.tum.cit.aet.artemis.core.domain.User; | ||
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Repository | ||
public interface CourseLearnerProfileRepository extends ArtemisJpaRepository<CourseLearnerProfile, Long> { | ||
|
||
@Transactional // ok because of delete | ||
@Modifying | ||
@Query(""" | ||
DELETE FROM CourseLearnerProfile clp | ||
WHERE clp.course = :course AND clp.learnerProfile.user = :user | ||
""") | ||
void deleteByCourseAndUser(Course course, User user); | ||
|
||
@Transactional // ok because of delete | ||
@Modifying | ||
void deleteAllByCourse(Course couese); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/de/tum/cit/aet/artemis/atlas/repository/LearnerProfileRepository.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,29 @@ | ||
package de.tum.cit.aet.artemis.atlas.repository; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.profile.LearnerProfile; | ||
import de.tum.cit.aet.artemis.core.domain.User; | ||
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Repository | ||
public interface LearnerProfileRepository extends ArtemisJpaRepository<LearnerProfile, Long> { | ||
|
||
Optional<LearnerProfile> findByUser(User user); | ||
|
||
default LearnerProfile findByUserElseThrow(User user) { | ||
return getValueElseThrow(findByUser(user)); | ||
} | ||
|
||
@Transactional // ok because of delete | ||
@Modifying | ||
void deleteByUser(User user); | ||
} |
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
60 changes: 60 additions & 0 deletions
60
src/main/java/de/tum/cit/aet/artemis/atlas/service/profile/CourseLearnerProfileService.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,60 @@ | ||
package de.tum.cit.aet.artemis.atlas.service.profile; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.profile.CourseLearnerProfile; | ||
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.Course; | ||
import de.tum.cit.aet.artemis.core.domain.User; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Service | ||
public class CourseLearnerProfileService { | ||
|
||
private final CourseLearnerProfileRepository courseLearnerProfileRepository; | ||
|
||
private final LearnerProfileRepository learnerProfileRepository; | ||
|
||
public CourseLearnerProfileService(CourseLearnerProfileRepository courseLearnerProfileRepository, LearnerProfileService learnerProfileService, | ||
LearnerProfileRepository learnerProfileRepository) { | ||
this.courseLearnerProfileRepository = courseLearnerProfileRepository; | ||
this.learnerProfileRepository = learnerProfileRepository; | ||
} | ||
|
||
public void createCourseLearnerProfile(Course course, User user) { | ||
var courseProfile = new CourseLearnerProfile(); | ||
courseProfile.setCourse(course); | ||
|
||
var learnerProfile = learnerProfileRepository.findByUserElseThrow(user); | ||
courseProfile.setLearnerProfile(learnerProfile); | ||
|
||
courseLearnerProfileRepository.save(courseProfile); | ||
} | ||
|
||
public void createCourseLearnerProfiles(Course course, Set<User> users) { | ||
Set<CourseLearnerProfile> courseProfiles = users.stream().map(user -> { | ||
var courseProfile = new CourseLearnerProfile(); | ||
courseProfile.setCourse(course); | ||
courseProfile.setLearnerProfile(user.getLearnerProfile()); | ||
|
||
return courseProfile; | ||
}).collect(Collectors.toSet()); | ||
|
||
courseLearnerProfileRepository.saveAll(courseProfiles); | ||
} | ||
|
||
public void deleteCourseLearnerProfile(Course course, User user) { | ||
courseLearnerProfileRepository.deleteByCourseAndUser(course, user); | ||
} | ||
|
||
public void deleteAllForCourse(Course course) { | ||
courseLearnerProfileRepository.deleteAllByCourse(course); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/de/tum/cit/aet/artemis/atlas/service/profile/LearnerProfileService.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,31 @@ | ||
package de.tum.cit.aet.artemis.atlas.service.profile; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.profile.LearnerProfile; | ||
import de.tum.cit.aet.artemis.atlas.repository.LearnerProfileRepository; | ||
import de.tum.cit.aet.artemis.core.domain.User; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Service | ||
public class LearnerProfileService { | ||
|
||
private final LearnerProfileRepository learnerProfileRepository; | ||
|
||
public LearnerProfileService(LearnerProfileRepository learnerProfileRepository) { | ||
this.learnerProfileRepository = learnerProfileRepository; | ||
} | ||
|
||
public LearnerProfile createProfile(User user) { | ||
var profile = new LearnerProfile(); | ||
profile.setUser(user); | ||
return learnerProfileRepository.save(profile); | ||
} | ||
|
||
public void deleteProfile(User user) { | ||
learnerProfileRepository.deleteByUser(user); | ||
} | ||
} |
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
Oops, something went wrong.