Skip to content

Commit

Permalink
fix: 리크루트 오류 수정
Browse files Browse the repository at this point in the history
fix: 리크루트 목록조회 category null 처리
fix: 리크루트 등록 시  question 빈값 처리
fix: 리크루트 질문 등록 예외처리 로직 수정
fix: 사용자 참여중 리크루트 조회시 로그인 유저는 항상 볼수있도록 수정
fix: 리크루트 참여 목록 조회시 로그인 id적용되도록 수정
fix: 질문이 없는 리크루트 신청 조회를 위한 left join 변경 및 생성자를 이용한 projection 관련 버그 수정
fix: 리크루트 신청 프로젝션 방식 변경
fix: 취소된 리크루트 신청 조회되지 않도록 수정
fix: 내가 참여한 리크루트 조회 쿼리 오류 수정 and절 -> or절로 수정
fix: 리크루트 신청 수락시 current number 수정되도록 오류 수정
fix: 리크루트 참여 조회 시 상태 상관없이 조회 가능하도록 수정
fix: 리크루트 신청자가 없어도, 모집파트가 출력되도록 수정
fix: 리크루트 덧글 등록시 수정일이 변하지 않도록 수정
  • Loading branch information
khs960616 committed Oct 15, 2023
1 parent 12488b8 commit 510a9c0
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public EnvelopeResponse<GetRecruitsResDto> getMemberJoinedRecruits(GetMemberJoi
@GetMapping("/applied")
public EnvelopeResponse<GetMemberAppliedRecruitsResDto> getMemberAppliedRecruits(GetMemberAppliedRecruitsReqDto recruitsReqDto, @Authentication AuthenticatedMember memberInfo) {
return EnvelopeResponse.<GetMemberAppliedRecruitsResDto>builder()
.data(recruitService.getMemberAppliedRecruits(recruitsReqDto, 1L))
.data(recruitService.getMemberAppliedRecruits(recruitsReqDto, memberInfo.getMemberId()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.util.StringUtils;

@Getter
@NoArgsConstructor
@AllArgsConstructor
Expand Down Expand Up @@ -68,7 +70,9 @@ public Recruit to() {
private void setRecruitQuestions (Recruit recruit) {
if(questions == null) return;

List<RecruitQuestion> recruitQuestions = questions.stream().map((question)-> RecruitQuestion.builder()
List<RecruitQuestion> recruitQuestions = questions.stream()
.filter(StringUtils::hasText)
.map((question)-> RecruitQuestion.builder()
.recruit(recruit)
.content(question)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Slice<Recruit> findRecruitByGetRecruitsReqDto(GetRecruitsReqDto dto, Page

// recruit types limitation
List<String> recruitTypes = dto.getRecruitTypes();
if(dto.getCategory().toUpperCase().equals(Category.PROJECT.name()) && recruitTypes!=null && !recruitTypes.isEmpty()) {
if(dto.getCategory() != null && dto.getCategory().toUpperCase().equals(Category.PROJECT.name()) && recruitTypes!=null && !recruitTypes.isEmpty()) {
String metaDataType = MetaDataType.RECRUIT_TYPE.name();
List<MetaData> containRecruitTypes = recruitTypes.stream()
.map(recruitType->metaDataConsumer.getMetaData(metaDataType, recruitType))
Expand Down Expand Up @@ -121,8 +121,7 @@ public Slice<Recruit> findMemberJoinRecruitWithCursorAndPageable(Long memberId,
List<Recruit> recruits = jpaQueryFactory.selectFrom(recruit)
.innerJoin(recruit.member, member)
.where(recruitIdLtThanCursor(cursor),
recruit.id.in(memberJoinRecruitIds),
recruit.member.id.eq(memberId),
recruit.id.in(memberJoinRecruitIds).or(recruit.member.id.eq(memberId)),
categoryEq)
.limit(pageable.getPageSize()+1)
.orderBy(recruit.id.desc())
Expand Down Expand Up @@ -153,7 +152,7 @@ public Slice<AppliedRecruit> findMemberAppliedRecruits(Long memberId, Long curso
BooleanExpression matchStatusEq = (matchStatus == null) ? null : recruitApplication.matchStatus.eq(MatchStatus.valueOf(matchStatus.toUpperCase()));

List<AppliedRecruit> recruits = jpaQueryFactory.select(
Projections.fields(
Projections.constructor(
AppliedRecruit.class,
recruit,
recruitApplication.matchStatus,
Expand All @@ -166,7 +165,8 @@ public Slice<AppliedRecruit> findMemberAppliedRecruits(Long memberId, Long curso
.where(recruitIdLtThanCursor(cursor),
recruitApplication.member.id.eq(memberId),
categoryEq,
matchStatusEq)
matchStatusEq,
recruitApplication.matchStatus.notIn(MatchStatus.CANCEL))
.limit(pageable.getPageSize() + 1)
.orderBy(recruitApplication.id.desc())
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public void expiredRecruit(Long recruitId, Long memberId) {
public GetRecruitsResDto getMemberJoinRecruits(GetMemberJoinRecruitsReqDto recruitsReqDto, Long loginMemberId) {
Long memberId = recruitsReqDto.getMemberId();
Member member = memberRepository.findById(memberId).orElseThrow(()->new ResourceNotFoundException(GlobalErrorInfo.NOT_FOUND));
if(!member.getPublicProfile()) {

if(!memberId.equals(loginMemberId) && !member.getPublicProfile()) {
throw new MemberException(MemberErrorInfo.MEMBER_PROFILE_SECRET);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public GetRecruitApplicationsResDto(Recruit recruit, List<RecruitApplicationElem
this.category = recruit.getCategory().name();
this.recruitId = recruit.getId();
this.recruitApplications = new HashMap<>();

recruit.getLimitations().forEach(recruitLimitation ->
this.recruitApplications.put(recruitLimitation.getType().getName(), new ArrayList<>()));

recruitApplications.sort((r1, r2)->{
if(r1.getLiked().equals(r2.getLiked())) {
return r1.getRecruitApplicationId().compareTo(r2.getRecruitApplicationId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public RecruitApplicationElement findTopByRecruitIdAndMemberId(Long recruitId, L
try {
return jpaQueryFactory.select(
Projections
.fields(
.constructor(
RecruitApplicationElement.class,
recruit.id,
recruitApplication.id,
recruitApplication.type,
recruitApplication.matchStatus,
member,
recruitQuestionReply.content,
Expand All @@ -42,9 +43,9 @@ public RecruitApplicationElement findTopByRecruitIdAndMemberId(Long recruitId, L
.from(recruitApplication)
.innerJoin(recruitApplication.member, member)
.innerJoin(recruitApplication.recruit, recruit)
.join(recruitQuestion).on(recruitQuestion.recruit.id.eq(recruit.id))
.join(recruitQuestionReply).on(recruitQuestionReply.question.id.eq(recruitQuestion.id))
.where(recruit.id.eq(recruitId), member.id.eq(memberId), recruitApplication.matchStatus.eq(MatchStatus.PENDING))
.leftJoin(recruitQuestion).on(recruitQuestion.recruit.id.eq(recruit.id))
.leftJoin(recruitQuestionReply).on(recruitQuestionReply.question.id.eq(recruitQuestion.id))
.where(recruit.id.eq(recruitId), member.id.eq(memberId))
.orderBy(recruitApplication.id.desc())
.limit(1)
.fetchOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface RecruitApplicationRepository extends JpaRepository<RecruitAppli
"inner join r.member as m " +
"left outer join recruit_question_reply as rp on r.id = rp.application.id " +
"left outer join rp.question as rq " +
"where r.id = :recruitApplicationId and r.recruit.member.id = :registerId and r.matchStatus = com.ssafy.ssafsound.domain.recruitapplication.domain.MatchStatus.PENDING")
"where r.id = :recruitApplicationId and r.recruit.member.id = :registerId")
RecruitApplicationElement findByRecruitApplicationIdAndRegisterId(Long recruitApplicationId, Long registerId);

@Query("SELECT ra FROM recruit_application ra join fetch ra.recruit as r join fetch ra.member where r.id in (:recruitId) and ra.matchStatus = com.ssafy.ssafsound.domain.recruitapplication.domain.MatchStatus.DONE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public PatchRecruitApplicationStatusResDto saveRecruitApplication(Long recruitId
metaDataConsumer.getMetaData(MetaDataType.RECRUIT_TYPE.name(), recruitType));
List<RecruitQuestionReply> participantAnswers = makeRecruitQuestionReplies(postRecruitApplicationReqDto, recruit, recruitApplication);
recruitApplicationRepository.save(recruitApplication);
recruitQuestionReplyRepository.saveAll(participantAnswers);

if(participantAnswers.size() != 0) {
recruitQuestionReplyRepository.saveAll(participantAnswers);
}
return new PatchRecruitApplicationStatusResDto(recruitApplication.getId(), MatchStatus.PENDING.name());
}

Expand All @@ -75,7 +78,8 @@ public PatchRecruitApplicationStatusResDto approveRecruitApplicationByRegister(L
RecruitApplication recruitApplication = recruitApplicationRepository.findByIdFetchRecruitWriter(recruitApplicationId)
.orElseThrow(() -> new ResourceNotFoundException(GlobalErrorInfo.NOT_FOUND));

getNotFullRecruitLimitation(recruitApplication.getRecruit(), recruitApplication.getType());
RecruitLimitation recruitLimitation = getNotFullRecruitLimitation(recruitApplication.getRecruit(), recruitApplication.getType());
recruitLimitation.increaseCurrentNumber();
return changeRecruitApplicationState(recruitApplication, memberId, status,
(entity, mid) -> {
boolean isNotRegister = !entity.getRecruit().getMember().getId().equals(mid);
Expand Down Expand Up @@ -143,7 +147,11 @@ public PostRecruitApplicationLikeResDto toggleRecruitApplicationLike(Long recrui

@Transactional(readOnly = true)
public GetRecruitApplicationDetailResDto getRecruitApplicationByIdAndRegisterId(Long recruitApplicationId, Long registerId) {
return new GetRecruitApplicationDetailResDto(recruitApplicationRepository.findByRecruitApplicationIdAndRegisterId(recruitApplicationId, registerId));
RecruitApplicationElement recruitApplicationElement = recruitApplicationRepository.findByRecruitApplicationIdAndRegisterId(recruitApplicationId, registerId);
if(recruitApplicationElement == null) {
throw new ResourceNotFoundException(GlobalErrorInfo.NOT_FOUND);
}
return new GetRecruitApplicationDetailResDto(recruitApplicationElement);
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -211,7 +219,7 @@ private List<RecruitQuestionReply> makeRecruitQuestionReplies(PostRecruitApplic
List<String> answers = dto.getContents();

int len = recruitQuestion.size();
if(answers.size() != len) {
if(len!=0 && answers.size() != len) {
throw new RecruitException(RecruitErrorInfo.NOT_SAME_LENGTH_RECRUIT_QUESTION_ANSWER);
}

Expand All @@ -224,7 +232,7 @@ private List<RecruitQuestionReply> makeRecruitQuestionReplies(PostRecruitApplic
RecruitQuestionReply.builder()
.application(recruitApplication)
.question(recruitQuestion.get(i))
.content(dto.getContents().get(i))
.content(answers.get(i))
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ssafy.ssafsound.domain.recruitcomment.domain.RecruitComment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

Expand All @@ -12,4 +13,10 @@ public interface RecruitCommentRepository extends JpaRepository<RecruitComment,

@Query("select r from recruit_comment r left join fetch r.member as m where r.recruit.id = :recruitId")
List<RecruitComment> findByRecruitIdFetchJoinMemberAndReplies(Long recruitId);
}

@Modifying
@Query(value = "update recruit_comment " +
"set comment_group =:id " +
"where recruit_comment_id = :id", nativeQuery = true)
void updateCommentGroup(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ public class RecruitCommentService {
public PostRecruitCommentResDto saveRecruitComment(Long recruitId, AuthenticatedMember userInfo, PostRecruitCommentReqDto dto) {
RecruitComment recruitComment = dto.toEntity();
Member writer = memberRepository.findById(userInfo.getMemberId()).orElseThrow(()->new ResourceNotFoundException(GlobalErrorInfo.NOT_FOUND));
RecruitComment commentGroup = (dto.getCommentGroup() == -1) ? recruitComment : recruitCommentRepository.getReferenceById(dto.getCommentGroup());

recruitComment.setCommentGroup(commentGroup);
if(dto.getCommentGroup() != -1) {
recruitComment.setCommentGroup(recruitCommentRepository.getReferenceById(dto.getCommentGroup()));
}
recruitComment.setRecruit(recruitRepository.getReferenceById(recruitId));
recruitComment.setWriter(writer);
recruitCommentRepository.save(recruitComment);

Long commentGroupId = dto.getCommentGroup();
if(commentGroupId == -1) {
recruitCommentRepository.updateCommentGroup(recruitComment.getId());
}
return PostRecruitCommentResDto.from(recruitComment);
}

Expand Down

0 comments on commit 510a9c0

Please sign in to comment.