-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 어드민에서 출신 대학을 관리하는 기능 추가 #725
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
Open
whqtker
wants to merge
7
commits into
develop
Choose a base branch
from
feat/632-manage-home-univ-admin
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
af1f3a5
feat: ErrorCode 작성
whqtker c21f04c
feat: 레포지토리 메서드 구현
whqtker fdf946a
feat: DTO 작성
whqtker d487ea5
feat: 도메인 메서드 작성
whqtker d46318b
feat: 서비스 메서드 구현
whqtker 68da7d8
feat: 컨트롤러 작성
whqtker ebd6094
test: 테스트 코드 작성
whqtker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...om/example/solidconnection/admin/university/controller/AdminHomeUniversityController.java
This file contains hidden or 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,61 @@ | ||
| package com.example.solidconnection.admin.university.controller; | ||
|
|
||
| import com.example.solidconnection.admin.university.dto.AdminHomeUniversityCreateRequest; | ||
| import com.example.solidconnection.admin.university.dto.AdminHomeUniversityResponse; | ||
| import com.example.solidconnection.admin.university.dto.AdminHomeUniversityUpdateRequest; | ||
| import com.example.solidconnection.admin.university.service.AdminHomeUniversityService; | ||
| import jakarta.validation.Valid; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @RequestMapping("/admin/home-universities") | ||
| @RestController | ||
| public class AdminHomeUniversityController { | ||
|
|
||
| private final AdminHomeUniversityService adminHomeUniversityService; | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<List<AdminHomeUniversityResponse>> getHomeUniversities() { | ||
| return ResponseEntity.ok(adminHomeUniversityService.getAllHomeUniversities()); | ||
| } | ||
|
|
||
| @GetMapping("/{home-university-id}") | ||
| public ResponseEntity<AdminHomeUniversityResponse> getHomeUniversity( | ||
| @PathVariable("home-university-id") Long homeUniversityId | ||
| ) { | ||
| return ResponseEntity.ok(adminHomeUniversityService.getHomeUniversity(homeUniversityId)); | ||
| } | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<AdminHomeUniversityResponse> createHomeUniversity( | ||
| @Valid @RequestBody AdminHomeUniversityCreateRequest request | ||
| ) { | ||
| return ResponseEntity.ok(adminHomeUniversityService.createHomeUniversity(request)); | ||
| } | ||
|
|
||
| @PutMapping("/{home-university-id}") | ||
| public ResponseEntity<AdminHomeUniversityResponse> updateHomeUniversity( | ||
| @PathVariable("home-university-id") Long homeUniversityId, | ||
| @Valid @RequestBody AdminHomeUniversityUpdateRequest request | ||
| ) { | ||
| return ResponseEntity.ok(adminHomeUniversityService.updateHomeUniversity(homeUniversityId, request)); | ||
| } | ||
|
|
||
| @DeleteMapping("/{home-university-id}") | ||
| public ResponseEntity<Void> deleteHomeUniversity( | ||
| @PathVariable("home-university-id") Long homeUniversityId | ||
| ) { | ||
| adminHomeUniversityService.deleteHomeUniversity(homeUniversityId); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...va/com/example/solidconnection/admin/university/dto/AdminHomeUniversityCreateRequest.java
This file contains hidden or 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,12 @@ | ||
| package com.example.solidconnection.admin.university.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record AdminHomeUniversityCreateRequest( | ||
| @NotBlank(message = "협정 대학명은 필수입니다") | ||
| @Size(max = 100, message = "협정 대학명은 100자 이하여야 합니다") | ||
| String name | ||
| ) { | ||
|
|
||
| } |
16 changes: 16 additions & 0 deletions
16
...in/java/com/example/solidconnection/admin/university/dto/AdminHomeUniversityResponse.java
This file contains hidden or 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,16 @@ | ||
| package com.example.solidconnection.admin.university.dto; | ||
|
|
||
| import com.example.solidconnection.university.domain.HomeUniversity; | ||
|
|
||
| public record AdminHomeUniversityResponse( | ||
| Long id, | ||
| String name | ||
| ) { | ||
|
|
||
| public static AdminHomeUniversityResponse from(HomeUniversity homeUniversity) { | ||
| return new AdminHomeUniversityResponse( | ||
| homeUniversity.getId(), | ||
| homeUniversity.getName() | ||
| ); | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
...va/com/example/solidconnection/admin/university/dto/AdminHomeUniversityUpdateRequest.java
This file contains hidden or 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,12 @@ | ||
| package com.example.solidconnection.admin.university.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record AdminHomeUniversityUpdateRequest( | ||
| @NotBlank(message = "협정 대학명은 필수입니다") | ||
| @Size(max = 100, message = "협정 대학명은 100자 이하여야 합니다") | ||
| String name | ||
| ) { | ||
|
|
||
| } |
104 changes: 104 additions & 0 deletions
104
...java/com/example/solidconnection/admin/university/service/AdminHomeUniversityService.java
This file contains hidden or 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,104 @@ | ||
| package com.example.solidconnection.admin.university.service; | ||
|
|
||
| import static com.example.solidconnection.common.exception.ErrorCode.HOME_UNIVERSITY_ALREADY_EXISTS; | ||
| import static com.example.solidconnection.common.exception.ErrorCode.HOME_UNIVERSITY_HAS_REFERENCES; | ||
| import static com.example.solidconnection.common.exception.ErrorCode.HOME_UNIVERSITY_NOT_FOUND; | ||
|
|
||
| import com.example.solidconnection.admin.university.dto.AdminHomeUniversityCreateRequest; | ||
| import com.example.solidconnection.admin.university.dto.AdminHomeUniversityResponse; | ||
| import com.example.solidconnection.admin.university.dto.AdminHomeUniversityUpdateRequest; | ||
| import com.example.solidconnection.cache.annotation.DefaultCacheOut; | ||
| import com.example.solidconnection.common.exception.CustomException; | ||
| import com.example.solidconnection.siteuser.repository.SiteUserRepository; | ||
| import com.example.solidconnection.university.domain.HomeUniversity; | ||
| import com.example.solidconnection.university.repository.HomeUniversityRepository; | ||
| import com.example.solidconnection.university.repository.UnivApplyInfoRepository; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class AdminHomeUniversityService { | ||
|
|
||
| private final HomeUniversityRepository homeUniversityRepository; | ||
| private final UnivApplyInfoRepository univApplyInfoRepository; | ||
| private final SiteUserRepository siteUserRepository; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<AdminHomeUniversityResponse> getAllHomeUniversities() { | ||
| return homeUniversityRepository.findAll().stream() | ||
| .map(AdminHomeUniversityResponse::from) | ||
| .toList(); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public AdminHomeUniversityResponse getHomeUniversity(Long id) { | ||
| HomeUniversity homeUniversity = homeUniversityRepository.findById(id) | ||
| .orElseThrow(() -> new CustomException(HOME_UNIVERSITY_NOT_FOUND)); | ||
| return AdminHomeUniversityResponse.from(homeUniversity); | ||
| } | ||
|
|
||
| @Transactional | ||
| @DefaultCacheOut( | ||
| key = {"univApplyInfoTextSearch", "university:recommend:general"}, | ||
| cacheManager = "customCacheManager", | ||
| prefix = true | ||
| ) | ||
| public AdminHomeUniversityResponse createHomeUniversity(AdminHomeUniversityCreateRequest request) { | ||
| validateNameNotExists(request.name()); | ||
| HomeUniversity homeUniversity = new HomeUniversity(null, request.name()); | ||
| return AdminHomeUniversityResponse.from(homeUniversityRepository.save(homeUniversity)); | ||
| } | ||
|
|
||
| @Transactional | ||
| @DefaultCacheOut( | ||
| key = {"univApplyInfoTextSearch", "university:recommend:general"}, | ||
| cacheManager = "customCacheManager", | ||
| prefix = true | ||
| ) | ||
| public AdminHomeUniversityResponse updateHomeUniversity(Long id, AdminHomeUniversityUpdateRequest request) { | ||
| HomeUniversity homeUniversity = homeUniversityRepository.findById(id) | ||
| .orElseThrow(() -> new CustomException(HOME_UNIVERSITY_NOT_FOUND)); | ||
| validateNameNotDuplicated(request.name(), id); | ||
| homeUniversity.update(request.name()); | ||
| return AdminHomeUniversityResponse.from(homeUniversity); | ||
| } | ||
|
|
||
| @Transactional | ||
| @DefaultCacheOut( | ||
| key = {"univApplyInfoTextSearch", "university:recommend:general"}, | ||
| cacheManager = "customCacheManager", | ||
| prefix = true | ||
| ) | ||
| public void deleteHomeUniversity(Long id) { | ||
| HomeUniversity homeUniversity = homeUniversityRepository.findById(id) | ||
| .orElseThrow(() -> new CustomException(HOME_UNIVERSITY_NOT_FOUND)); | ||
| validateNoReferences(id); | ||
| homeUniversityRepository.delete(homeUniversity); | ||
| } | ||
|
|
||
| private void validateNameNotExists(String name) { | ||
| homeUniversityRepository.findByName(name) | ||
| .ifPresent(existing -> { | ||
| throw new CustomException(HOME_UNIVERSITY_ALREADY_EXISTS); | ||
| }); | ||
| } | ||
|
Comment on lines
+82
to
+87
Contributor
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. 이제 private 함수는 맨 밑으로 보내게 바뀌었나보군요! |
||
|
|
||
| private void validateNameNotDuplicated(String name, Long excludeId) { | ||
| homeUniversityRepository.findByName(name) | ||
| .ifPresent(existing -> { | ||
| if (!existing.getId().equals(excludeId)) { | ||
| throw new CustomException(HOME_UNIVERSITY_ALREADY_EXISTS); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void validateNoReferences(Long id) { | ||
| if (univApplyInfoRepository.existsByHomeUniversityId(id) | ||
| || siteUserRepository.existsByHomeUniversityId(id)) { | ||
| throw new CustomException(HOME_UNIVERSITY_HAS_REFERENCES); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이런 건 null이될 수 없으니 long이 낫지 않나요? 머쓱하지만 오랜만에 pr봅니다..