-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CompetencyRepositoryService with default methods of CompetencyRep…
…ository
- Loading branch information
Showing
5 changed files
with
65 additions
and
12 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
29 changes: 29 additions & 0 deletions
29
...ain/java/de/tum/cit/aet/artemis/atlas/service/competency/CompetencyRepositoryService.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.service.competency; | ||
|
||
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.competency.Competency; | ||
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository; | ||
import de.tum.cit.aet.artemis.core.service.AbstractRepositoryService; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Service | ||
public class CompetencyRepositoryService extends AbstractRepositoryService { | ||
|
||
private final CompetencyRepository competencyRepository; | ||
|
||
public CompetencyRepositoryService(CompetencyRepository competencyRepository) { | ||
this.competencyRepository = competencyRepository; | ||
} | ||
|
||
public Competency findByIdWithLectureUnitsAndExercisesElseThrow(long competencyId) { | ||
return getValueElseThrow(competencyRepository.findByIdWithLectureUnitsAndExercises(competencyId), competencyId); | ||
} | ||
|
||
public Competency findByIdWithLectureUnitsElseThrow(long competencyId) { | ||
return getValueElseThrow(competencyRepository.findByIdWithLectureUnits(competencyId), competencyId); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/de/tum/cit/aet/artemis/core/service/AbstractRepositoryService.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,24 @@ | ||
package de.tum.cit.aet.artemis.core.service; | ||
|
||
import java.util.Optional; | ||
|
||
import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException; | ||
|
||
public abstract class AbstractRepositoryService { | ||
|
||
public <U> U getValueElseThrow(Optional<U> optional) { | ||
if (optional.isEmpty()) { | ||
throw new EntityNotFoundException(optional.getClass().getName()); // ToDo: Check validity of optional anme | ||
} | ||
|
||
return optional.get(); | ||
} | ||
|
||
public <U> U getValueElseThrow(Optional<U> optional, long id) { | ||
if (optional.isEmpty()) { | ||
throw new EntityNotFoundException(optional.getClass().getName(), id); // ToDo: Check validity of optional anme | ||
} | ||
|
||
return optional.get(); | ||
} | ||
} |