-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from mju-likelion/feature/introduce-get-studen…
…tid-api-#20 Feature/#20 특정 학번 자기소개서 조회 api 개발
- Loading branch information
Showing
15 changed files
with
214 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.mjulikelion.baker.config; | ||
|
||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableCaching | ||
public class CacheConfig { | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/mjulikelion/baker/constant/RegexPatterns.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,5 @@ | ||
package org.mjulikelion.baker.constant; | ||
|
||
public class RegexPatterns { | ||
public static final String APPLICATION_STUDENT_ID_PATTERN = "^60\\d{6}$";//60으로 시작하고 그 뒤로 숫자 6개인 문자열 | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/org/mjulikelion/baker/controller/IntroduceController.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,31 @@ | ||
package org.mjulikelion.baker.controller; | ||
|
||
import static org.mjulikelion.baker.constant.RegexPatterns.APPLICATION_STUDENT_ID_PATTERN; | ||
|
||
import jakarta.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import org.mjulikelion.baker.dto.response.ResponseDto; | ||
import org.mjulikelion.baker.dto.response.introduce.IntroduceGetResponseData; | ||
import org.mjulikelion.baker.service.introduce.IntroduceQueryService; | ||
import org.springframework.cache.annotation.Cacheable; | ||
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 | ||
@AllArgsConstructor | ||
@RequestMapping("introduce") | ||
public class IntroduceController { | ||
private final IntroduceQueryService introduceQueryService; | ||
|
||
@GetMapping() | ||
@Cacheable(value = "applicationByStudentId", key = "#studentId") | ||
public ResponseEntity<ResponseDto<IntroduceGetResponseData>> getStudentIntroduce( | ||
@RequestParam(value = "studentId") | ||
@Pattern(regexp = APPLICATION_STUDENT_ID_PATTERN, message = "학번이 형식에 맞지 않습니다.") String studentId | ||
) { | ||
return this.introduceQueryService.getStudentIntroduce(studentId); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/mjulikelion/baker/dto/response/introduce/IntroduceGetResponseData.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,15 @@ | ||
package org.mjulikelion.baker.dto.response.introduce; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import org.mjulikelion.baker.model.Part; | ||
import org.mjulikelion.baker.vo.IntroduceDetailVO; | ||
|
||
@Builder | ||
public class IntroduceGetResponseData { | ||
@JsonProperty | ||
private final Part part; | ||
@JsonProperty | ||
private final List<IntroduceDetailVO> introduceDetailVOList; | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/mjulikelion/baker/exception/ApplicationIntroduceNotFoundException.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,9 @@ | ||
package org.mjulikelion.baker.exception; | ||
|
||
import org.mjulikelion.baker.errorcode.ErrorCode; | ||
|
||
public class ApplicationIntroduceNotFoundException extends CustomException { | ||
public ApplicationIntroduceNotFoundException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/mjulikelion/baker/exception/ApplicationNotFoundException.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,9 @@ | ||
package org.mjulikelion.baker.exception; | ||
|
||
import org.mjulikelion.baker.errorcode.ErrorCode; | ||
|
||
public class ApplicationNotFoundException extends CustomException { | ||
public ApplicationNotFoundException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
src/main/java/org/mjulikelion/baker/repository/ApplicationIntroduceRepository.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,8 +1,10 @@ | ||
package org.mjulikelion.baker.repository; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import org.mjulikelion.baker.model.ApplicationIntroduce; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ApplicationIntroduceRepository extends JpaRepository<ApplicationIntroduce, UUID> { | ||
List<ApplicationIntroduce> findByApplicationId(UUID applicationId); | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/mjulikelion/baker/service/introduce/IntroduceQueryService.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,9 @@ | ||
package org.mjulikelion.baker.service.introduce; | ||
|
||
import org.mjulikelion.baker.dto.response.ResponseDto; | ||
import org.mjulikelion.baker.dto.response.introduce.IntroduceGetResponseData; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public interface IntroduceQueryService { | ||
ResponseEntity<ResponseDto<IntroduceGetResponseData>> getStudentIntroduce(String studentId); | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/org/mjulikelion/baker/service/introduce/IntroduceQueryServiceImpl.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,82 @@ | ||
package org.mjulikelion.baker.service.introduce; | ||
|
||
import static org.mjulikelion.baker.errorcode.ErrorCode.APPLICATION_INTRODUCE_NOT_FOUND_ERROR; | ||
import static org.mjulikelion.baker.errorcode.ErrorCode.APPLICATION_NOT_FOUND_ERROR; | ||
|
||
import java.util.Comparator; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
import lombok.AllArgsConstructor; | ||
import org.mjulikelion.baker.dto.response.ResponseDto; | ||
import org.mjulikelion.baker.dto.response.introduce.IntroduceGetResponseData; | ||
import org.mjulikelion.baker.exception.ApplicationIntroduceNotFoundException; | ||
import org.mjulikelion.baker.exception.ApplicationNotFoundException; | ||
import org.mjulikelion.baker.model.Application; | ||
import org.mjulikelion.baker.model.ApplicationIntroduce; | ||
import org.mjulikelion.baker.model.Introduce; | ||
import org.mjulikelion.baker.repository.ApplicationIntroduceRepository; | ||
import org.mjulikelion.baker.repository.ApplicationRepository; | ||
import org.mjulikelion.baker.vo.IntroduceDetailVO; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
public class IntroduceQueryServiceImpl implements IntroduceQueryService { | ||
private final ApplicationRepository applicationRepository; | ||
private final ApplicationIntroduceRepository applicationIntroduceRepository; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public ResponseEntity<ResponseDto<IntroduceGetResponseData>> getStudentIntroduce(String studentId) { | ||
Application application = this.findApplicationByStudentId(studentId); | ||
List<ApplicationIntroduce> applicationIntroduceList = this.findApplicationIntroduces(application.getId()); | ||
List<IntroduceDetailVO> introduceDetailVOList = this.buildIntroduceDetailVOList(applicationIntroduceList); | ||
|
||
IntroduceGetResponseData introduceGetResponseData = IntroduceGetResponseData.builder() | ||
.introduceDetailVOList(introduceDetailVOList) | ||
.part(application.getPart()) | ||
.build(); | ||
|
||
return ResponseEntity.ok(ResponseDto.res(HttpStatus.OK, "OK", introduceGetResponseData)); | ||
} | ||
|
||
private Application findApplicationByStudentId(String studentId) { | ||
return this.applicationRepository.findByStudentId(studentId) | ||
.orElseThrow(() -> new ApplicationNotFoundException(APPLICATION_NOT_FOUND_ERROR)); | ||
} | ||
|
||
private List<ApplicationIntroduce> findApplicationIntroduces(UUID applicationId) { | ||
List<ApplicationIntroduce> applicationIntroduceList = this.applicationIntroduceRepository.findByApplicationId( | ||
applicationId); | ||
if (applicationIntroduceList.isEmpty()) { | ||
throw new ApplicationIntroduceNotFoundException(APPLICATION_INTRODUCE_NOT_FOUND_ERROR); | ||
} | ||
return applicationIntroduceList; | ||
} | ||
|
||
private List<IntroduceDetailVO> buildIntroduceDetailVOList(List<ApplicationIntroduce> applicationIntroduceList) { | ||
Map<Introduce, String> introduceMap = applicationIntroduceList.stream() | ||
.sorted(Comparator.comparingInt(a -> a.getIntroduce().getSequence())) | ||
.collect(Collectors.toMap( | ||
ApplicationIntroduce::getIntroduce, | ||
ApplicationIntroduce::getContent, | ||
(a, b) -> b, | ||
LinkedHashMap::new | ||
)); | ||
|
||
return introduceMap.keySet().stream() | ||
.map(introduce -> IntroduceDetailVO.builder() | ||
.sequence(introduce.getSequence()) | ||
.title(introduce.getTitle()) | ||
.content(introduceMap.get(introduce)) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
src/main/java/org/mjulikelion/baker/vo/IntroduceDetailVO.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,14 @@ | ||
package org.mjulikelion.baker.vo; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public class IntroduceDetailVO { | ||
@JsonProperty | ||
private final int sequence; | ||
@JsonProperty | ||
private final String title; | ||
@JsonProperty | ||
private final String content; | ||
} |