-
Notifications
You must be signed in to change notification settings - Fork 2
MOSU-62 feat: application request, reponse 타입 변경 #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,12 @@ | |
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import life.mosu.mosuserver.domain.application.AdmissionTicketImageJpaEntity; | ||
| import life.mosu.mosuserver.domain.application.AdmissionTicketImageJpaRepository; | ||
| import life.mosu.mosuserver.domain.application.ApplicationJpaEntity; | ||
| import life.mosu.mosuserver.domain.application.ApplicationJpaRepository; | ||
| import life.mosu.mosuserver.domain.application.ApplicationSchoolJpaRepository; | ||
| import life.mosu.mosuserver.domain.applicationschool.ApplicationSchoolJpaEntity; | ||
| import life.mosu.mosuserver.domain.school.AddressJpaVO; | ||
| import life.mosu.mosuserver.domain.school.SchoolJpaEntity; | ||
| import life.mosu.mosuserver.domain.school.SchoolJpaRepository; | ||
| import life.mosu.mosuserver.global.exception.CustomRuntimeException; | ||
|
|
@@ -38,38 +36,36 @@ public class ApplicationService { | |
| // 신청 | ||
| @Transactional | ||
| public ApplicationResponse apply(Long userId, ApplicationRequest request) { | ||
| Set<ApplicationSchoolRequest> schools = request.schools(); | ||
| List<ApplicationSchoolJpaEntity> schoolEntities = new ArrayList<>(); | ||
| Set<ApplicationSchoolRequest> schoolRequests = request.schools(); | ||
| List<ApplicationSchoolJpaEntity> savedEntities = new ArrayList<>(); | ||
|
|
||
| Set<Long> schoolIds = schools.stream() | ||
| .map(ApplicationSchoolRequest::schoolId) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| if (applicationSchoolJpaRepository.existsByUserIdAndSchoolIdIn(userId, schoolIds)) { | ||
| throw new CustomRuntimeException(ErrorCode.APPLICATION_SCHOOL_ALREADY_APPLIED); | ||
| } | ||
|
|
||
| ApplicationJpaEntity application = request.toEntity(userId); | ||
| ApplicationJpaEntity applicationJpaEntity = applicationJpaRepository.save(application); | ||
| Long applicationId = applicationJpaEntity.getId(); | ||
| ApplicationJpaEntity application = applicationJpaRepository.save(request.toEntity(userId)); | ||
| Long applicationId = application.getId(); | ||
|
|
||
| admissionTicketImageJpaRepository.save( | ||
| createAdmissionTicketImageIfPresent(request.admissionTicket(), applicationId)); | ||
|
|
||
| schools.forEach(applicationSchoolRequest -> { | ||
| SchoolJpaEntity school = schoolJpaRepository.findById( | ||
| applicationSchoolRequest.schoolId()) | ||
| for (ApplicationSchoolRequest schoolRequest : schoolRequests) { | ||
| Long schoolId = schoolJpaRepository.findBySchoolNameAndAreaAndExamDate( | ||
| schoolRequest.schoolName(), | ||
| schoolRequest.validatedArea(schoolRequest.area()), | ||
| schoolRequest.examDate()) | ||
| .orElseThrow(() -> new CustomRuntimeException(ErrorCode.SCHOOL_NOT_FOUND)) | ||
| .getId(); | ||
|
|
||
| if (applicationSchoolJpaRepository.existsByUserIdAndSchoolId(userId, schoolId)) { | ||
| throw new CustomRuntimeException(ErrorCode.APPLICATION_SCHOOL_ALREADY_APPLIED); | ||
| } | ||
|
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check for existing applications is performed after retrieving the if (applicationSchoolJpaRepository.existsByUserIdAndSchoolId(
userId, schoolRequest.schoolName(), schoolRequest.area(), schoolRequest.examDate())) {
throw new CustomRuntimeException(ErrorCode.APPLICATION_SCHOOL_ALREADY_APPLIED);
} |
||
|
|
||
| SchoolJpaEntity school = schoolJpaRepository.findById(schoolId) | ||
| .orElseThrow(() -> new CustomRuntimeException(ErrorCode.SCHOOL_NOT_FOUND)); | ||
|
|
||
| AddressJpaVO address = school.getAddress(); | ||
| ApplicationSchoolJpaEntity applicationSchoolJpaEntity = applicationSchoolRequest.toEntity( | ||
| userId, applicationId, address); | ||
| ApplicationSchoolJpaEntity saved = applicationSchoolJpaRepository.save( | ||
| applicationSchoolJpaEntity); | ||
| schoolEntities.add(saved); | ||
| }); | ||
| ApplicationSchoolJpaEntity applicationSchool = schoolRequest.toEntity(userId, | ||
| applicationId, school); | ||
| savedEntities.add(applicationSchoolJpaRepository.save(applicationSchool)); | ||
| } | ||
|
Comment on lines
+48
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainOptimize database calls and improve error handling. The refactored logic has several issues that impact performance and maintainability:
Apply this optimization to eliminate the redundant database call: for (ApplicationSchoolRequest schoolRequest : schoolRequests) {
- Long schoolId = schoolJpaRepository.findBySchoolNameAndAreaAndExamDate(
+ SchoolJpaEntity school = schoolJpaRepository.findBySchoolNameAndAreaAndExamDate(
schoolRequest.schoolName(),
schoolRequest.validatedArea(schoolRequest.area()),
schoolRequest.examDate())
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.SCHOOL_NOT_FOUND))
- .getId();
+ ;
- if (applicationSchoolJpaRepository.existsByUserIdAndSchoolId(userId, schoolId)) {
+ if (applicationSchoolJpaRepository.existsByUserIdAndSchoolId(userId, school.getId())) {
throw new CustomRuntimeException(ErrorCode.APPLICATION_SCHOOL_ALREADY_APPLIED);
}
- SchoolJpaEntity school = schoolJpaRepository.findById(schoolId)
- .orElseThrow(() -> new CustomRuntimeException(ErrorCode.SCHOOL_NOT_FOUND));
ApplicationSchoolJpaEntity applicationSchool = schoolRequest.toEntity(userId,
applicationId, school);
savedEntities.add(applicationSchoolJpaRepository.save(applicationSchool));
}Run this script to verify the school lookup method exists and returns the expected type: 🏁 Script executed: #!/bin/bash
# Description: Verify the school repository method signature and return type
# Search for the findBySchoolNameAndAreaAndExamDate method definition
ast-grep --pattern 'findBySchoolNameAndAreaAndExamDate($$$) {
$$$
}'
# Also search for the method signature in interface definitions
rg -A 3 "findBySchoolNameAndAreaAndExamDate"Length of output: 1077 Optimize ApplicationService school lookup and eliminate redundant call Verified that • File:
for (ApplicationSchoolRequest schoolRequest : schoolRequests) {
- Long schoolId = schoolJpaRepository.findBySchoolNameAndAreaAndExamDate(
+ SchoolJpaEntity school = schoolJpaRepository.findBySchoolNameAndAreaAndExamDate(
schoolRequest.schoolName(),
schoolRequest.validatedArea(schoolRequest.area()),
schoolRequest.examDate())
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.SCHOOL_NOT_FOUND))
- .getId();
+
if (applicationSchoolJpaRepository.existsByUserIdAndSchoolId(userId, school.getId())) {
throw new CustomRuntimeException(ErrorCode.APPLICATION_SCHOOL_ALREADY_APPLIED);
}
- SchoolJpaEntity school = schoolJpaRepository.findById(schoolId)
- .orElseThrow(() -> new CustomRuntimeException(ErrorCode.SCHOOL_NOT_FOUND));
ApplicationSchoolJpaEntity applicationSchool = schoolRequest.toEntity(userId,
applicationId, school);
savedEntities.add(applicationSchoolJpaRepository.save(applicationSchool));
}
🤖 Prompt for AI Agents |
||
|
|
||
| return ApplicationResponse.of(applicationId, schoolEntities); | ||
| return ApplicationResponse.of(applicationId, savedEntities); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,13 @@ | ||
| package life.mosu.mosuserver.domain.application; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import life.mosu.mosuserver.domain.applicationschool.ApplicationSchoolJpaEntity; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface ApplicationSchoolJpaRepository extends | ||
| JpaRepository<ApplicationSchoolJpaEntity, Long> { | ||
|
|
||
|
|
||
| boolean existsByUserIdAndSchoolIdIn(Long userId, Collection<Long> schoolIds); | ||
| boolean existsByUserIdAndSchoolId(Long userId, Long schoolId); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConsider performance implications of individual existence checks. The change from Consider:
🏁 Script executed: #!/bin/bash
# Check how this method is being used in the service layer
rg -A 5 -B 5 "existsByUserIdAndSchoolId" --type javaLength of output: 2979 Batch existence checks and guard against race conditions Switching from a single bulk query to per-school • In 🤖 Prompt for AI Agents |
||
|
|
||
| List<ApplicationSchoolJpaEntity> findAllByApplicationId(Long applicationId); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,7 @@ | |
| public enum Area { | ||
| DAECHI("대치"), | ||
| MOKDONG("목동"), | ||
| DAEGU("대구"); | ||
|
|
||
| NOWON("노원"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent ❓ Verification inconclusiveVerify data migration for the Area enum change. The change from
🏁 Script executed: #!/bin/bash
# Check for any references to DAEGU in the codebase
rg -i "DAEGU" --type java
# Check for any database migration files
fd -e sql -e xml migrationLength of output: 54 Add a database migration for the Area enum change Your enum update replaces DAEGU with NOWON but there are no existing migration scripts to handle this. Without one, any stored records with
🤖 Prompt for AI Agents |
||
| private final String areaName; | ||
|
|
||
| Area(String areaName) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| package life.mosu.mosuserver.domain.school; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface SchoolJpaRepository extends JpaRepository<SchoolJpaEntity, Long> { | ||
|
|
||
| Optional<SchoolJpaEntity> findBySchoolNameAndAreaAndExamDate(String schoolName, Area area, | ||
| LocalDate examDate); | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConsider database indexing for the new query method. The new
🏁 Script executed: #!/bin/bash
# Check for database migration files that might contain index creation
rg -A 10 -B 10 "school_name.*area.*exam_date|exam_date.*area.*school_name" --type sql
# Look for any existing index definitions
rg -i "index.*school" --type sqlLength of output: 420 #!/bin/bash
# Locate the SchoolJpaEntity to inspect JPA @Table index definitions
entity_file=$(find src -type f -name "SchoolJpaEntity.java" | head -n 1)
if [[ -n "$entity_file" ]]; then
echo "Inspecting entity file: $entity_file"
rg -A3 "@Table" -n "$entity_file"
rg -i "@Index" -n "$entity_file"
else
echo "SchoolJpaEntity.java not found in src/"
fi
# List database migration/changelog files
echo
echo "Migration files under src/main/resources/db/:"
find src/main/resources/db/ -type f | grep -E "\.(sql|xml|yml|yaml)$" || echo " (none found)"
# Search migrations for index creation statements
echo
echo "Searching for explicit CREATE INDEX statements in migrations:"
rg -i "create\s\+index" -n src/main/resources/db/ || echo " (no CREATE INDEX found)"🏁 Script executed: #!/bin/bash
# Locate the JPA entity to check @Table/@Index annotations
entity_file=$(find src -type f -name "SchoolJpaEntity.java" | head -n 1)
if [[ -n "$entity_file" ]]; then
echo ">>> Inspecting $entity_file for table/index annotations"
rg -A3 "@Table" -n "$entity_file" || echo " (no @Table annotation found)"
rg -n "@Index" -n "$entity_file" || echo " (no @Index annotation found)"
else
echo "ERROR: SchoolJpaEntity.java not found under src/"
fi
echo
# List all migration/changelog files in resources
echo ">>> Listing migration files under src/main/resources"
find src/main/resources -type f | grep -E "\.(sql|xml|yml|yaml)$" || echo " (no migration files found)"
echo
# Search migrations for explicit CREATE INDEX statements
echo ">>> Searching migrations for CREATE INDEX"
rg -i "create\s+index" -n src/main/resources || echo " (no CREATE INDEX statements found)"Length of output: 1396 Add composite database index for the new query
🤖 Prompt for AI Agents |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you're querying the
schoolJpaRepositoryto find a school by name, area, and exam date, and then immediately extracting the ID. Consider creating a method that directly retrieves the school ID based on these criteria to avoid fetching the entire entity when only the ID is needed. This could improve performance, especially if theSchoolJpaEntitycontains a lot of data.