-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] #77 - 학교, 학과 검색 API 구현
- Loading branch information
Showing
24 changed files
with
180 additions
and
23 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
3 changes: 3 additions & 0 deletions
3
src/main/java/org/sopt/seonyakServer/domain/member/dto/SendCodeRequest.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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package org.sopt.seonyakServer.domain.member.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record SendCodeRequest( | ||
@NotBlank(message = "전화번호는 공백일 수 없습니다.") | ||
String phoneNumber | ||
) { | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/sopt/seonyakServer/domain/member/dto/VerifyCodeRequest.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package org.sopt.seonyakServer.domain.member.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record VerifyCodeRequest( | ||
@NotBlank(message = "전화번호는 공백일 수 없습니다.") | ||
String phoneNumber, | ||
|
||
@NotBlank(message = "인증번호는 공백일 수 없습니다.") | ||
String verificationCode | ||
) { | ||
} |
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
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
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
Empty file.
35 changes: 35 additions & 0 deletions
35
src/main/java/org/sopt/seonyakServer/domain/university/controller/UnivController.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,35 @@ | ||
package org.sopt.seonyakServer.domain.university.controller; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.seonyakServer.domain.university.dto.SearchDeptResponse; | ||
import org.sopt.seonyakServer.domain.university.dto.SearchUnivResponse; | ||
import org.sopt.seonyakServer.domain.university.service.UnivService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/search") | ||
public class UnivController { | ||
|
||
private final UnivService univService; | ||
|
||
@GetMapping("/univ") | ||
public ResponseEntity<SearchUnivResponse> searchUniv( | ||
@RequestParam final String univName | ||
) { | ||
return ResponseEntity.ok(univService.searchUniv(univName)); | ||
} | ||
|
||
@GetMapping("/dept") | ||
public ResponseEntity<List<SearchDeptResponse>> searchDept( | ||
@RequestParam final String univName, | ||
@RequestParam final String deptName | ||
) { | ||
return ResponseEntity.ok(univService.searchDept(univName, deptName)); | ||
} | ||
} |
Empty file.
16 changes: 16 additions & 0 deletions
16
src/main/java/org/sopt/seonyakServer/domain/university/dto/SearchDeptResponse.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,16 @@ | ||
package org.sopt.seonyakServer.domain.university.dto; | ||
|
||
public record SearchDeptResponse( | ||
String deptName, | ||
boolean isClosed | ||
) { | ||
public static SearchDeptResponse of( | ||
final String deptName, | ||
final boolean isClosed | ||
) { | ||
return new SearchDeptResponse( | ||
deptName, | ||
isClosed | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/sopt/seonyakServer/domain/university/dto/SearchUnivResponse.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,11 @@ | ||
package org.sopt.seonyakServer.domain.university.dto; | ||
|
||
import java.util.List; | ||
|
||
public record SearchUnivResponse( | ||
List<String> univSearchResult | ||
) { | ||
public static SearchUnivResponse of(final List<String> univSearchResult) { | ||
return new SearchUnivResponse(univSearchResult); | ||
} | ||
} |
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
Empty file.
20 changes: 20 additions & 0 deletions
20
src/main/java/org/sopt/seonyakServer/domain/university/repository/DeptRepository.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,20 @@ | ||
package org.sopt.seonyakServer.domain.university.repository; | ||
|
||
import java.util.List; | ||
import org.sopt.seonyakServer.domain.university.model.Department; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface DeptRepository extends JpaRepository<Department, Long> { | ||
|
||
@Query("SELECT d " | ||
+ "FROM Department d " | ||
+ "WHERE d.university.univName = :univName " | ||
+ "AND d.deptName " | ||
+ "LIKE %:deptName%") | ||
List<Department> findByUnivIdAndDeptNameContaining( | ||
@Param("univName") String univName, | ||
@Param("deptName") String deptName | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/sopt/seonyakServer/domain/university/repository/UnivRepository.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,18 @@ | ||
package org.sopt.seonyakServer.domain.university.repository; | ||
|
||
import java.util.List; | ||
import org.sopt.seonyakServer.domain.university.model.University; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface UnivRepository extends JpaRepository<University, Long> { | ||
|
||
@Query("SELECT u.univName " | ||
+ "FROM University u " | ||
+ "WHERE u.univName " | ||
+ "LIKE %:univNamePart%") | ||
List<String> findByUnivNameContaining(@Param("univNamePart") String univNamePart); | ||
|
||
boolean existsByUnivName(String UnivName); | ||
} |
Empty file.
47 changes: 47 additions & 0 deletions
47
src/main/java/org/sopt/seonyakServer/domain/university/service/UnivService.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,47 @@ | ||
package org.sopt.seonyakServer.domain.university.service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.seonyakServer.domain.university.dto.SearchDeptResponse; | ||
import org.sopt.seonyakServer.domain.university.dto.SearchUnivResponse; | ||
import org.sopt.seonyakServer.domain.university.model.Department; | ||
import org.sopt.seonyakServer.domain.university.repository.DeptRepository; | ||
import org.sopt.seonyakServer.domain.university.repository.UnivRepository; | ||
import org.sopt.seonyakServer.global.exception.enums.ErrorType; | ||
import org.sopt.seonyakServer.global.exception.model.CustomException; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UnivService { | ||
|
||
private final UnivRepository univRepository; | ||
private final DeptRepository deptRepository; | ||
|
||
public SearchUnivResponse searchUniv(final String univNamePart) { | ||
if (univNamePart == null || univNamePart.trim().isEmpty()) { | ||
return SearchUnivResponse.of(List.of()); | ||
} | ||
|
||
return SearchUnivResponse.of(univRepository.findByUnivNameContaining(univNamePart)); | ||
} | ||
|
||
public List<SearchDeptResponse> searchDept( | ||
final String univName, | ||
final String deptName | ||
) { | ||
if (!univRepository.existsByUnivName(univName)) { | ||
throw new CustomException(ErrorType.INVALID_UNIV_NAME_ERROR); | ||
} | ||
|
||
List<Department> departments = deptRepository.findByUnivIdAndDeptNameContaining(univName, deptName); | ||
|
||
return departments.stream() | ||
.map(department -> SearchDeptResponse.of( | ||
department.getDeptName(), | ||
department.isClosed()) | ||
) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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
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