generated from life-librarians/life-bookshelf-client
-
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.
Body: The commit introduces multiple important enhancements to the management and access of interview data. Major changes include: 1. Revised code in the InterviewController to call the new interviewFacadeService and retrieve paginated conversations and interview questions. 2. Added a custom query in ConversationRepository to retrieve paginated conversations based on interviewId. 3. Enhanced InterviewRepository with a custom query to fetch interview details along with their associated questions. 4. Implemented methods in InterviewFacadeService and InterviewQueryService to facilitate interview data retrieval. 5. Introduced InterviewMapper to map domain objects to response DTOs to fine-tune the response mechanism and enhance application efficiency. The changes aim to enhance application efficiency and the ability to scale by optimizing data retrieval and reducing the unnecessary burden on server resources during heavy load situations. Caveats: Please note: client-side changes may be required to adapt to the new paginated data retrieval APIs. References: Issue #XYZ123
- Loading branch information
Showing
7 changed files
with
121 additions
and
7 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
5 changes: 5 additions & 0 deletions
5
...in/java/com/lifelibrarians/lifebookshelf/interview/repository/ConversationRepository.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,9 +1,14 @@ | ||
package com.lifelibrarians.lifebookshelf.interview.repository; | ||
|
||
import com.lifelibrarians.lifebookshelf.interview.domain.Conversation; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
|
||
public interface ConversationRepository extends JpaRepository<Conversation, Long> { | ||
|
||
@Query("select c from Conversation c where c.interview.id = :interviewId") | ||
Page<Conversation> findAllByInterviewId(Long interviewId, Pageable pageable); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/lifelibrarians/lifebookshelf/interview/repository/InterviewRepository.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,15 @@ | ||
package com.lifelibrarians.lifebookshelf.interview.repository; | ||
|
||
import com.lifelibrarians.lifebookshelf.interview.domain.Interview; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface InterviewRepository extends JpaRepository<Interview, Long> { | ||
|
||
@Query("SELECT i FROM Interview i " | ||
+ "JOIN FETCH i.questions " | ||
+ "JOIN FETCH i.currentQuestion " | ||
+ "WHERE i.id = :interviewId") | ||
Optional<Interview> findWithQuestionsById(Long interviewId); | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/lifelibrarians/lifebookshelf/mapper/InterviewMapper.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,37 @@ | ||
package com.lifelibrarians.lifebookshelf.mapper; | ||
|
||
import com.lifelibrarians.lifebookshelf.interview.domain.Conversation; | ||
import com.lifelibrarians.lifebookshelf.interview.domain.InterviewQuestion; | ||
import com.lifelibrarians.lifebookshelf.interview.dto.response.InterviewConversationDto; | ||
import com.lifelibrarians.lifebookshelf.interview.dto.response.InterviewConversationResponseDto; | ||
import com.lifelibrarians.lifebookshelf.interview.dto.response.InterviewQuestionDto; | ||
import com.lifelibrarians.lifebookshelf.interview.dto.response.InterviewQuestionResponseDto; | ||
import java.util.List; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper(componentModel = "spring") | ||
public interface InterviewMapper { | ||
|
||
@Mapping(source = "conversation.id", target = "conversationId") | ||
InterviewConversationDto toInterviewConversationDto(Conversation conversation); | ||
|
||
@Mapping(source = "conversationDtos", target = "results") | ||
InterviewConversationResponseDto toInterviewConversationResponseDto( | ||
List<InterviewConversationDto> conversationDtos, | ||
int currentPage, | ||
int totalElements, | ||
int totalPages, | ||
boolean hasNextPage, | ||
boolean hasPreviousPage | ||
); | ||
|
||
@Mapping(source = "questionDtos", target = "results") | ||
InterviewQuestionResponseDto toInterviewQuestionResponseDto( | ||
Long currentQuestionId, | ||
List<InterviewQuestionDto> questionDtos | ||
); | ||
|
||
@Mapping(source = "interviewQuestion.id", target = "questionId") | ||
InterviewQuestionDto toInterviewQuestionDto(InterviewQuestion interviewQuestion); | ||
} |