Skip to content

Commit

Permalink
feat: 선호 여행 등록
Browse files Browse the repository at this point in the history
  • Loading branch information
mummhy0811 committed Jun 4, 2024
1 parent 510b057 commit 03ebb6c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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가 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
13 changes: 12 additions & 1 deletion src/main/java/com/hanaro/triptogether/team/domain/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface TeamService {

//모임 검색
Team findTeamByTeamIdx(Long teamIdx);

void updateTeamPreference(UpdateTeamPreferenceReqDto dto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 03ebb6c

Please sign in to comment.