feat: expose account identity and eligibility boundary
This commit is contained in:
+5
@@ -1,9 +1,14 @@
|
||||
package com.lab.labtimesheet.feature.account.repository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.lab.labtimesheet.feature.account.model.InternshipStatus;
|
||||
import com.lab.labtimesheet.feature.account.model.entity.InternProfile;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface InternProfileRepository extends JpaRepository<InternProfile, Long> {
|
||||
boolean existsByUserIdAndInternshipStatus(Long userId, InternshipStatus status);
|
||||
|
||||
boolean existsByUserIdAndInternshipStatusAndInternshipStartDateLessThanEqualAndInternshipEndDateGreaterThanEqual(
|
||||
Long userId, InternshipStatus status, LocalDate latestStartDate, LocalDate earliestEndDate);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.lab.labtimesheet.feature.account.service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.lab.labtimesheet.feature.account.model.AccountStatus;
|
||||
import com.lab.labtimesheet.feature.account.model.GlobalRole;
|
||||
import com.lab.labtimesheet.feature.account.model.InternshipStatus;
|
||||
@@ -42,6 +44,20 @@ public class AccountService {
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public boolean isEligibleIntern(long userId, LocalDate workDate) {
|
||||
if (workDate == null) {
|
||||
throw new IllegalArgumentException("Work date is required");
|
||||
}
|
||||
return users.findById(userId)
|
||||
.filter(user -> user.getGlobalRole() == GlobalRole.INTERN)
|
||||
.filter(user -> user.getAccountStatus() == AccountStatus.ACTIVE)
|
||||
.filter(user -> internProfiles
|
||||
.existsByUserIdAndInternshipStatusAndInternshipStartDateLessThanEqualAndInternshipEndDateGreaterThanEqual(
|
||||
user.getId(), InternshipStatus.ACTIVE, workDate, workDate))
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public AccountIdentity requireEligibleIntern(long userId) {
|
||||
if (!isEligibleIntern(userId)) {
|
||||
|
||||
Reference in New Issue
Block a user