-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/recruit
- Loading branch information
Showing
19 changed files
with
439 additions
and
310 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
17 changes: 17 additions & 0 deletions
17
src/main/java/umc/kkijuk/server/introduce/controller/response/FindIntroduceResponse.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,17 @@ | ||
package umc.kkijuk.server.introduce.controller.response; | ||
|
||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class FindIntroduceResponse { | ||
private Long introId; | ||
private String title; | ||
private String content; | ||
private LocalDate createdDate; | ||
} |
17 changes: 17 additions & 0 deletions
17
...ain/java/umc/kkijuk/server/introduce/controller/response/FindMasterIntroduceResponse.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,17 @@ | ||
package umc.kkijuk.server.introduce.controller.response; | ||
|
||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class FindMasterIntroduceResponse { | ||
private Long masterIntroId; | ||
private String title; | ||
private String content; | ||
private LocalDate createdDate; | ||
} |
11 changes: 0 additions & 11 deletions
11
src/main/java/umc/kkijuk/server/introduce/domain/MasterIntroduceRepository.java
This file was deleted.
Oops, something went wrong.
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
18 changes: 18 additions & 0 deletions
18
src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.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 umc.kkijuk.server.introduce.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import umc.kkijuk.server.introduce.domain.MasterIntroduce; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface MasterIntroduceRepository extends JpaRepository<MasterIntroduce, Long> { | ||
Optional<MasterIntroduce> findByMemberId(Long memberId); | ||
@Query("SELECT m FROM MasterIntroduce m " + | ||
"JOIN m.masterQuestion mq " + | ||
"WHERE m.memberId = :memberId AND mq.content LIKE %:keyword%") | ||
List<MasterIntroduce> searchMasterIntroduceByKeywordForMember(String keyword, Long memberId); | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
...duce/domain/MasterQuestionRepository.java → .../repository/MasterQuestionRepository.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,7 @@ | ||
package umc.kkijuk.server.introduce.domain; | ||
package umc.kkijuk.server.introduce.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import umc.kkijuk.server.introduce.domain.MasterQuestion; | ||
|
||
public interface MasterQuestionRepository extends JpaRepository<MasterQuestion, Long> { | ||
} |
3 changes: 2 additions & 1 deletion
3
.../introduce/domain/QuestionRepository.java → ...roduce/repository/QuestionRepository.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
176 changes: 11 additions & 165 deletions
176
src/main/java/umc/kkijuk/server/introduce/service/IntroduceService.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,172 +1,18 @@ | ||
package umc.kkijuk.server.introduce.service; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import umc.kkijuk.server.common.domian.exception.IntroFoundException; | ||
import umc.kkijuk.server.common.domian.exception.IntroOwnerMismatchException; | ||
import umc.kkijuk.server.common.domian.exception.RecruitOwnerMismatchException; | ||
import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException; | ||
import umc.kkijuk.server.introduce.controller.response.IntroduceListResponse; | ||
import umc.kkijuk.server.introduce.controller.response.IntroduceResponse; | ||
import umc.kkijuk.server.introduce.domain.*; | ||
import umc.kkijuk.server.introduce.dto.*; | ||
import umc.kkijuk.server.introduce.controller.response.*; | ||
import umc.kkijuk.server.introduce.dto.IntroduceReqDto; | ||
import umc.kkijuk.server.member.domain.Member; | ||
import umc.kkijuk.server.recruit.infrastructure.RecruitEntity; | ||
import umc.kkijuk.server.recruit.infrastructure.RecruitJpaRepository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class IntroduceService { | ||
public interface IntroduceService { | ||
|
||
private final IntroduceRepository introduceRepository; | ||
private final RecruitJpaRepository recruitJpaRepository; | ||
private final QuestionRepository questionRepository; | ||
|
||
@Transactional | ||
public IntroduceResponse saveIntro(Member requestMember, Long recruitId, IntroduceReqDto introduceReqDto){ | ||
RecruitEntity recruit=recruitJpaRepository.findById(recruitId) | ||
.orElseThrow(()-> new ResourceNotFoundException("recruit ", recruitId)); | ||
if (introduceRepository.findByRecruitId(recruitId).isPresent()) { | ||
throw new IntroFoundException("이미 자기소개서가 존재합니다"); | ||
} | ||
|
||
List<Question> questions = introduceReqDto.getQuestionList().stream() | ||
.map(dto -> new Question(dto.getTitle(), dto.getContent(), dto.getNumber())) | ||
.collect(Collectors.toList()); | ||
|
||
Introduce introduce=Introduce.builder() | ||
.memberId(requestMember.getId()) | ||
.recruit(recruit) | ||
.questions(questions) | ||
.state(introduceReqDto.getState()) | ||
.build(); | ||
|
||
introduceRepository.save(introduce); | ||
/*List<String> introduceList=getIntroduceTitles();*/ | ||
return new IntroduceResponse(introduce, introduceReqDto.getQuestionList()/*,introduceList*/); | ||
} | ||
|
||
@Transactional | ||
public IntroduceResponse getIntro(Member requestMember, Long introId){ | ||
Introduce introduce=introduceRepository.findById(introId) | ||
.orElseThrow(()-> new ResourceNotFoundException("introduce ", introId)); | ||
if (!introduce.getMemberId().equals(requestMember.getId())) { | ||
throw new IntroOwnerMismatchException(); | ||
} | ||
|
||
List<QuestionDto> questionList = introduce.getQuestions() | ||
.stream() | ||
.map(question -> new QuestionDto(question.getTitle(), question.getContent(), question.getNumber())) | ||
.collect(Collectors.toList()); | ||
|
||
/*List<String> introduceList=getIntroduceTitles();*/ | ||
|
||
return new IntroduceResponse(introduce, questionList/*, introduceList*/); | ||
} | ||
|
||
@Transactional | ||
public List<IntroduceListResponse> getIntroList(Member requestMember){ | ||
List<Introduce> introduces = introduceRepository.findAllByMemberId(requestMember.getId()) | ||
.orElseThrow(IntroOwnerMismatchException::new); | ||
|
||
return introduces.stream() | ||
.map(IntroduceListResponse::new) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Transactional | ||
public IntroduceResponse updateIntro(Member requestMember, Long introId, IntroduceReqDto introduceReqDto) throws Exception{ | ||
Introduce introduce=introduceRepository.findById(introId) | ||
.orElseThrow(()-> new ResourceNotFoundException("introduce ", introId)); | ||
|
||
if (!introduce.getMemberId().equals(requestMember.getId())) { | ||
throw new IntroOwnerMismatchException(); | ||
} | ||
|
||
introduce.update(introduceReqDto.getState()); | ||
|
||
List<Question> existingQuestions = introduce.getQuestions(); | ||
Map<Integer, Question> existingQuestionsMap = existingQuestions.stream() | ||
.collect(Collectors.toMap(Question::getNumber, q -> q)); | ||
|
||
List<QuestionDto> questionDtos = introduceReqDto.getQuestionList(); | ||
List<Question> updatedQuestions = new ArrayList<>(); | ||
|
||
for (QuestionDto questionDto : questionDtos) { | ||
Integer number = questionDto.getNumber(); | ||
Question existingQuestion = existingQuestionsMap.get(number); | ||
|
||
if (existingQuestion != null) { | ||
existingQuestion.update(questionDto.getTitle(), questionDto.getContent()); | ||
updatedQuestions.add(existingQuestion); | ||
} else { | ||
Question newQuestion = new Question(); | ||
newQuestion.setTitle(questionDto.getTitle()); | ||
newQuestion.setContent(questionDto.getContent()); | ||
newQuestion.setNumber(questionDto.getNumber()); | ||
newQuestion.setIntroduce(introduce); | ||
updatedQuestions.add(newQuestion); | ||
} | ||
} | ||
|
||
List<Question> toRemove = existingQuestions.stream() | ||
.filter(q -> !questionDtos.stream() | ||
.anyMatch(dto -> dto.getNumber() == q.getNumber())) | ||
.collect(Collectors.toList()); | ||
|
||
toRemove.forEach(question -> { | ||
introduce.getQuestions().remove(question); | ||
questionRepository.delete(question); | ||
}); | ||
|
||
introduce.getQuestions().clear(); | ||
introduce.getQuestions().addAll(updatedQuestions); | ||
|
||
introduceRepository.save(introduce); | ||
|
||
List<QuestionDto> responseQuestionList = introduce.getQuestions().stream() | ||
.map(question -> QuestionDto.builder() | ||
.title(question.getTitle()) | ||
.content(question.getContent()) | ||
.number(question.getNumber()) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
|
||
return IntroduceResponse.builder() | ||
.introduce(introduce) | ||
.questionList(responseQuestionList) | ||
.build(); | ||
} | ||
|
||
|
||
@Transactional | ||
public Long deleteIntro(Member requestMember, Long introId){ | ||
Introduce introduce=introduceRepository.findById(introId) | ||
.orElseThrow(()-> new ResourceNotFoundException("introduce ", introId)); | ||
if (!introduce.getMemberId().equals(requestMember.getId())) { | ||
throw new IntroOwnerMismatchException(); | ||
} | ||
|
||
introduceRepository.delete(introduce); | ||
|
||
return introduce.getId(); | ||
} | ||
|
||
/* @Transactional | ||
public List<String> getIntroduceTitles() { | ||
// Fetch all Introduce entities | ||
List<Introduce> introduces = introduceRepository.findAll(); | ||
// Map Introduce entities to Recruit titles | ||
return introduces.stream() | ||
.map(introduce -> recruitJpaRepository.findById(introduce.getRecruit().toModel().getId())) // Get the Recruit entity | ||
.filter(Optional::isPresent) // Filter out any empty results | ||
.map(opt -> opt.get().toModel().getTitle()) // Get the title of the Recruit | ||
.collect(Collectors.toList()); // Collect titles into a List | ||
}*/ | ||
IntroduceResponse saveIntro(Member requestMember, Long recruitId, IntroduceReqDto introduceReqDto); | ||
IntroduceResponse getIntro(Member requestMember, Long introId); | ||
List<IntroduceListResponse> getIntroList(Member requestMember); | ||
IntroduceResponse updateIntro(Member requestMember, Long introId, IntroduceReqDto introduceReqDto) throws Exception; | ||
Long deleteIntro(Member requestMember, Long introId); | ||
Map<String, Object> searchIntroduceAndMasterByKeyword(String keyword, Member requestMember); | ||
} |
Oops, something went wrong.