diff --git a/src/main/java/com/hanaro/triptogether/exception/ExceptionEnum.java b/src/main/java/com/hanaro/triptogether/exception/ExceptionEnum.java index 02d83a1..9860e24 100644 --- a/src/main/java/com/hanaro/triptogether/exception/ExceptionEnum.java +++ b/src/main/java/com/hanaro/triptogether/exception/ExceptionEnum.java @@ -11,6 +11,7 @@ public enum ExceptionEnum { // ----team TEAM_NOT_FOUND(HttpStatus.BAD_REQUEST,"TEAM_NOT_FOUND","해당하는 모임이 없습니다."), + TEAM_AND_TRIP_NOT_MATCH(HttpStatus.BAD_REQUEST,"TEAM_AND_TRIP_NOT_MATCH","팀 정보와 여행 정보가 일치하지 않습니다."), //---------team member TEAM_MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST, "TEAM_MEMBER_NOT_FOUND","해당하는 팀원IDX가 없습니다."), diff --git a/src/main/java/com/hanaro/triptogether/team/controller/TeamController.java b/src/main/java/com/hanaro/triptogether/team/controller/TeamController.java index 5166a6a..d73599a 100644 --- a/src/main/java/com/hanaro/triptogether/team/controller/TeamController.java +++ b/src/main/java/com/hanaro/triptogether/team/controller/TeamController.java @@ -56,4 +56,10 @@ public String generateInviteLink(@RequestBody InviteTeamReqDto inviteTeamReqDto) public InviteTeamResDto inviteTeam(@RequestParam String inviter, @RequestParam Long teamNo) { return teamService.inviteTeam(inviter, teamNo); } + + //여행 즐겨찾기 + @PutMapping("/team/preference") + public void updateTeamPreference(@RequestBody UpdateTeamPreferenceReqDto dto) { + teamService.updateTeamPreference(dto); + } } diff --git a/src/main/java/com/hanaro/triptogether/team/domain/Team.java b/src/main/java/com/hanaro/triptogether/team/domain/Team.java index 8511db0..33603c7 100644 --- a/src/main/java/com/hanaro/triptogether/team/domain/Team.java +++ b/src/main/java/com/hanaro/triptogether/team/domain/Team.java @@ -4,6 +4,7 @@ import com.hanaro.triptogether.enumeration.PreferenceType; import com.hanaro.triptogether.enumeration.TeamType; import com.hanaro.triptogether.member.domain.Member; +import com.hanaro.triptogether.trip.domain.Trip; import jakarta.persistence.*; import java.time.LocalDateTime; import lombok.*; @@ -34,7 +35,11 @@ public class Team { private PreferenceType preferenceType; private String teamNotice; - private Long preferTrip; + + + @OneToOne + @JoinColumn(name = "prefer_trip") + private Trip preferTrip; @Column(nullable = false) private LocalDateTime createdAt; @@ -64,4 +69,10 @@ public void delete(LocalDateTime deletedAt, Member deletedBy) { public void updateTeamNotice(String teamNotice) { this.teamNotice = teamNotice; } + + public void updatePreferTrip(Trip preferTrip, Member member) { + this.preferTrip = preferTrip; + this.lastModifiedBy = member; + this.lastModifiedAt=LocalDateTime.now(); + } } diff --git a/src/main/java/com/hanaro/triptogether/team/dto/request/UpdateTeamPreferenceReqDto.java b/src/main/java/com/hanaro/triptogether/team/dto/request/UpdateTeamPreferenceReqDto.java new file mode 100644 index 0000000..2b78fa4 --- /dev/null +++ b/src/main/java/com/hanaro/triptogether/team/dto/request/UpdateTeamPreferenceReqDto.java @@ -0,0 +1,10 @@ +package com.hanaro.triptogether.team.dto.request; + +import lombok.Getter; + +@Getter +public class UpdateTeamPreferenceReqDto { + private Long teamIdx; + private Long tripIdx; + private Long memberIdx; +} diff --git a/src/main/java/com/hanaro/triptogether/team/service/TeamService.java b/src/main/java/com/hanaro/triptogether/team/service/TeamService.java index 1c65777..4fb4a6f 100644 --- a/src/main/java/com/hanaro/triptogether/team/service/TeamService.java +++ b/src/main/java/com/hanaro/triptogether/team/service/TeamService.java @@ -30,4 +30,6 @@ public interface TeamService { //모임 검색 Team findTeamByTeamIdx(Long teamIdx); + + void updateTeamPreference(UpdateTeamPreferenceReqDto dto); } diff --git a/src/main/java/com/hanaro/triptogether/team/service/impl/TeamServiceImpl.java b/src/main/java/com/hanaro/triptogether/team/service/impl/TeamServiceImpl.java index cbcc294..a7f7a89 100644 --- a/src/main/java/com/hanaro/triptogether/team/service/impl/TeamServiceImpl.java +++ b/src/main/java/com/hanaro/triptogether/team/service/impl/TeamServiceImpl.java @@ -16,6 +16,9 @@ import com.hanaro.triptogether.team.service.TeamService; import com.hanaro.triptogether.teamMember.domain.TeamMember; import com.hanaro.triptogether.teamMember.domain.TeamMemberRepository; +import com.hanaro.triptogether.trip.domain.Trip; +import com.hanaro.triptogether.trip.domain.TripRepository; +import com.hanaro.triptogether.trip.service.TripService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,6 +29,7 @@ @Service @RequiredArgsConstructor public class TeamServiceImpl implements TeamService { + private final TripRepository tripRepository; private final TeamRepository teamRepository; private final AccountRepository accountRepository; private final TeamMemberRepository teamMemberRepository; @@ -156,4 +160,19 @@ public InviteTeamResDto inviteTeam(String inviter, Long teamNo) { public Team findTeamByTeamIdx(Long teamIdx) { return teamRepository.findById(teamIdx).orElseThrow(()->new ApiException(ExceptionEnum.TEAM_NOT_FOUND)); } + + @Override + public void updateTeamPreference(UpdateTeamPreferenceReqDto dto) { + Team team = teamRepository.findById(dto.getTeamIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.TEAM_NOT_FOUND)); + Member member = memberRepository.findById(dto.getMemberIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.MEMBER_NOT_FOUND)); + Trip trip =null; + if(dto.getTripIdx() != null) { + trip = tripRepository.findById(dto.getTripIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.TRIP_NOT_FOUND)); + if(!trip.getTeam().equals(team)){ + throw new ApiException(ExceptionEnum.TEAM_AND_TRIP_NOT_MATCH); + } + } + team.updatePreferTrip(trip, member); + teamRepository.save(team); + } }