Skip to content

Commit

Permalink
Merge pull request #111 from Hanaro-trip-together-bank/feature/trip-r…
Browse files Browse the repository at this point in the history
…eply

fix: 댓글 CUD 관련 teamMemberIdx에서 memberIdx로 수정
  • Loading branch information
mummhy0811 authored Jun 4, 2024
2 parents 8d1190d + ce57841 commit 233f2e4
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.hanaro.triptogether.teamMember.dto.response.TeamMembersResDto;

import java.util.List;
import java.util.Optional;

public interface TeamMemberService {
// 모임원 전체 출력
Expand Down Expand Up @@ -47,4 +48,7 @@ public interface TeamMemberService {

// 팀멤버idx로 팀멤버 검색
TeamMember checkIsMyTeamByTeamMemberIdx(Long team_member_idx);

//memberId와 teamId로 팀멤버 검색
TeamMember findTeamMemberByMemberIdxAndTeamIdx(Long memberId, Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -204,4 +205,13 @@ public TeamMember checkIsMyTeamByTeamMemberIdx(Long team_member_idx) {
return teamMemberRepository.findById(team_member_idx)
.orElseThrow(() -> new ApiException(ExceptionEnum.INVALID_TEAM_MEMBER));
}

@Override
public TeamMember findTeamMemberByMemberIdxAndTeamIdx(Long memberIdx, Long teamIdx) {
Optional<TeamMember> teamMember = teamMemberRepository.findTeamMemberByMember_MemberIdxAndTeam_TeamIdx(memberIdx, teamIdx);
if(teamMember.isEmpty()) {
throw new ApiException(ExceptionEnum.INVALID_TEAM_MEMBER);
}
return teamMember.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
@Getter
@Builder
public class TripReplyDeleteReqDto {
private Long teamMemberIdx;
private Long memberIdx;
private Long tripReplyIdx;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@Builder
public class TripReplyReqDto {
private Long teamMemberIdx;
private Long memberIdx;
private String tripReplyContent;

public TripReply toEntity(TripPlace tripPlace, TeamMember teamMember, String trip_reply_content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Getter
@Builder
public class TripReplyUpdateReqDto {
private Long teamMemberIdx;
private Long memberIdx;
private Long tripReplyIdx;
private String tripReplyContent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,30 @@ public class TripReplyService {
@Transactional
public void createReply(Long trip_place_idx, TripReplyReqDto dto) {
TripPlace tripplace = tripPlaceService.checkTripPlaceExists(trip_place_idx);

TeamMember teamMember = validateAndReturn(trip_place_idx, dto.getTeamMemberIdx());

TeamMember teamMember =validateAndReturn(trip_place_idx, tripplace.getTrip().getTeam().getTeamIdx(), dto.getMemberIdx());
tripReplyRepository.save(dto.toEntity(tripplace, teamMember, dto.getTripReplyContent()));
}
@Transactional
public void updateReply(Long trip_place_idx, TripReplyUpdateReqDto dto) {
tripPlaceService.checkTripPlaceExists(trip_place_idx);

validateAndReturn(trip_place_idx, dto.getTeamMemberIdx());
TripPlace tripplace = tripPlaceService.checkTripPlaceExists(trip_place_idx);
validateAndReturn(trip_place_idx, tripplace.getTrip().getTeam().getTeamIdx(), dto.getMemberIdx());

TripReply tripReply = checkTripReplyExist(dto.getTripReplyIdx());
checkSameMember(tripReply.getTeamMember().getTeamMemberIdx(),dto.getTeamMemberIdx());
checkSameMember(tripReply.getTeamMember().getTeamMemberIdx(),dto.getMemberIdx());

tripReply.update(dto.getTripReplyContent());
}

@Transactional
public void deleteReply(Long trip_place_idx, TripReplyDeleteReqDto dto) {
tripPlaceService.checkTripPlaceExists(trip_place_idx);

validateAndReturn(trip_place_idx, dto.getTeamMemberIdx());
TripPlace tripplace = tripPlaceService.checkTripPlaceExists(trip_place_idx);
validateAndReturn(trip_place_idx, tripplace.getTrip().getTeam().getTeamIdx(), dto.getMemberIdx());

TripReply tripReply = checkTripReplyExist(dto.getTripReplyIdx());
checkSameMember(tripReply.getTeamMember().getTeamMemberIdx(),dto.getTeamMemberIdx());
checkSameMember(tripReply.getTeamMember().getTeamMemberIdx(),dto.getMemberIdx());

tripReplyRepository.deleteById(dto.getTripReplyIdx());
}
Expand Down Expand Up @@ -90,9 +89,9 @@ private void checkSameMember(Long m1, Long m2){
}
}

TeamMember validateAndReturn(Long trip_place_idx, Long team_member_idx) {
TeamMember teamMember = teamMemberService.findTeamMemberByTeamMemberIdx(team_member_idx);
validateTeam( trip_place_idx, teamMember.getTeam().getTeamIdx());
TeamMember validateAndReturn(Long tripPlaceIdx,Long teamIdx, Long memberIdx) {
TeamMember teamMember = teamMemberService.findTeamMemberByMemberIdxAndTeamIdx(memberIdx, teamIdx);
validateTeam( tripPlaceIdx, teamMember.getTeam().getTeamIdx());
validateTeamMember( teamMember.getTeamMemberIdx());
return teamMember;
}
Expand All @@ -101,7 +100,7 @@ private void validateTeam(Long trip_place_idx, Long teamIdx){
//place의 팀과 teamMember의 팀이 일치하지 않는 경우
if(!Objects.equals(tripPlaceService.findTeamIdByTripPlaceIdx(trip_place_idx), teamIdx)){
throw new ApiException(ExceptionEnum.TRIP_INFO_NOT_MATCH);
};
}
}

private void validateTeamMember(Long team_member_idx) {
Expand Down
Loading

0 comments on commit 233f2e4

Please sign in to comment.