Skip to content

Commit

Permalink
Merge pull request #224 from swm-nodriversomabus/BUS-229-place-latitu…
Browse files Browse the repository at this point in the history
…de-longitude

Bus 229 place latitude longitude
  • Loading branch information
Lemonade255 authored Nov 21, 2023
2 parents c0be306 + e13cee1 commit 7623fe7
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import com.example.api.common.exception.CustomException;
import com.example.api.common.type.ApplicationStateEnum;
import com.example.api.common.type.ErrorCodeEnum;
import com.example.api.common.type.Pair;
import com.example.api.common.utils.AuthenticationUtils;
import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface;
import com.example.api.matching.application.port.in.*;
import com.example.api.matching.domain.MatchingApplication;
import com.example.api.matching.dto.*;
import com.example.api.matching.type.MatchingTypeEnum;
import com.example.api.member.application.port.in.AddMemberChatRoomUsecase;
Expand Down Expand Up @@ -117,9 +117,7 @@ public void createMatchingApplication(@Valid @RequestBody SaveMatchingApplicatio
throw new CustomException(ErrorCodeEnum.MATCHING_NOT_FOUND);
}

MatchingApplication matchingApplication = matchingApplicationUsecase.createMatchingApplicationData(securityUser.getUserId(), matchingApplicationDto);
//ChatRoom chatRoom = createChatRoomUsecase.createMatchingChatRoom(matchingApplication);
//return addMemberChatRoomUsecase.setupMatchingChatRoom(matchingApplication, chatRoom);
matchingApplicationUsecase.createMatchingApplicationData(securityUser.getUserId(), matchingApplicationDto);
}

/**
Expand All @@ -136,7 +134,11 @@ public List<FindMatchingDto> getAll() {
}
return findMatchingUsecase.getAll();
}


/**
* 식사 매칭 목록 조회
* @return dining matching list
*/
@Operation(summary = "Get all dining matching", description = "모든 식사 매칭 목록을 조회한다.")
@GetMapping("/diningmatching")
public List<FindMatchingDto> getDiningMatchingList() {
Expand Down Expand Up @@ -186,16 +188,39 @@ public AccommodationMatchingDto getMatchingById(@PathVariable Long matchingId) {
return matchingDto;
}

@Operation(summary = "Get matching", description = "자기 자신의 매칭을 조회한다.")
/**
* 로그인한 사용자가 작성한 매칭 조회
* @return own matching
*/
@Operation(summary = "Get own matching", description = "자기 자신의 매칭을 조회한다.")
@GetMapping("/matching/my-matching")
public List<FindMatchingDto> getMyMatching() {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::getMatchingById: Login is needed");
log.error("MatchingController::getMyMatching: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
return findMatchingUsecase.getMatchingByWriterId(securityUser.getUserId());
// return findMatchingUsecase.getMatchingById(matchingId);
}

/**
* 선택한 위치와 가까운 매칭 조회
* @param coordination (위치)
* @return near matching list
*/
@Operation(summary = "Get matching by place coordinate", description = "선택한 위치와 가까운 여행지의 매칭 목록을 조회한다.")
@GetMapping("/matching/nearfrom")
public List<FindMatchingDto> getNearMatching(@RequestBody(required = false) Pair<Double, Double> coordination) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("MatchingController::getNearMatching: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
Pair<Double, Double> coordinationData = coordination;
if (coordinationData == null) {
coordinationData = new Pair<>(37.5544, 126.9707); // 서울역
}
return findMatchingUsecase.getNearMatching(coordinationData.getFirst(), coordinationData.getSecond());
}

/**
Expand Down Expand Up @@ -262,7 +287,11 @@ public int getLikeCount(@PathVariable Long matchingId) {
}
return likeUsecase.getLikeCount(matchingId);
}


/**
* 추천 숙소 리스트 조회
* @return recommended accommodation list
*/
@Operation(summary = "Get recommended accommodation list", description = "추천 숙소 리스트를 반환한다.")
@GetMapping("/accommodation/recommended")
public List<AccommodationDto> getRecommendedAccommodationList() {
Expand Down Expand Up @@ -290,7 +319,12 @@ public FindMatchingDto updateMatching(@PathVariable Long matchingId, @RequestBod
}
return saveMatchingUsecase.updateMatching(matchingId, matchingDto);
}


/**
* 숙소 정보 수정
* @param matchingId (ID)
* @param accommodationDto (데이터)
*/
@Operation(summary = "Update accommodation", description = "숙소 정보를 수정한다.")
@PutMapping("/matching/{matchingId}/accommodation")
public void updateAccommodation(@PathVariable Long matchingId, @RequestBody AccommodationDto accommodationDto) {
Expand Down Expand Up @@ -374,7 +408,11 @@ public void deleteMatching(@PathVariable Long matchingId) {
}
deleteMatchingUsecase.deleteMatching(matchingId);
}


/**
* 숙소 정보 초기화
* @param matchingId (ID)
*/
@Operation(summary = "Reset accommodation", description = "숙소 정보를 초기화한다.")
@DeleteMapping("/matching/{matchingId}/accommodation")
public void deleteAccommodation(@PathVariable Long matchingId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public class MatchingEntity extends BaseEntity {
@Column(nullable = false, length = 3000)
private String place;

@Column
private Double latitude;

@Column
private Double longitude;

@Column(nullable = false, length = 6000)
private String content;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public List<MatchingEntity> getByWriterId(UUID userId) {
return matchingRepository.getByWriterId(userId);
}

@Override
public List<MatchingEntity> getByPlaceCoordinate(Double latitude, Double longitude) {
return matchingRepository.getByLatitudeGreaterThanEqualAndLatitudeLessThanEqualAndLongitudeGreaterThanEqualAndLongitudeLessThanEqual(latitude - 0.02, latitude + 0.02, longitude - 0.025, longitude + 0.025);
}

@Override
public List<MatchingEntity> getByIsActive(Boolean isActive) {
return matchingRepository.getByIsActive(isActive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface FindMatchingUsecase {
List<FindMatchingDto> getDiningMatchingList();
FindMatchingDto getMatchingById(Long matchingId);
List<FindMatchingDto> getMatchingByWriterId(UUID userId);
List<FindMatchingDto> getNearMatching(Double latitude, Double longitude);
List<FindMatchingDto> getMatchingByIsActive(Boolean isActive);
List<FindMatchingDto> getRecommendedMatchingList(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public interface FindMatchingPort {
List<MatchingEntity> getDiningMatchingList();
Optional<MatchingEntity> getByMatchingId(Long matchingId);
List<MatchingEntity> getByWriterId(UUID userId);
List<MatchingEntity> getByPlaceCoordinate(Double latitude, Double longitude);
List<MatchingEntity> getByIsActive(Boolean isActive);
}
2 changes: 2 additions & 0 deletions src/main/java/com/example/api/matching/domain/Matching.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Matching {
private MatchingTypeEnum type;
private String title;
private String place;
private Double latitude;
private Double longitude;
private String content;
private LocalDateTime startDate;
private LocalDateTime endDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -33,6 +34,12 @@ public class FindMatchingDto {

@NotBlank
private String place;

@Size(min = -90, max = 90)
private Double latitude;

@Size(min = -180, max = 180)
private Double longitude;

@NotBlank
private String content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;

import java.time.LocalDateTime;
Expand All @@ -27,6 +28,12 @@ public class SaveMatchingDto {
@NotBlank(message = "Place is empty")
private String place;

@Size(min = -90, max = 90)
private Double latitude;

@Size(min = -180, max = 180)
private Double longitude;

@NotNull
private String content;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface MatchingRepository extends JpaRepository<MatchingEntity, Long>
List<MatchingEntity> getAllBy();
Optional<MatchingEntity> getByMatchingId(Long matchingId);
List<MatchingEntity> getByWriterId(UUID userId);
List<MatchingEntity> getByLatitudeGreaterThanEqualAndLatitudeLessThanEqualAndLongitudeGreaterThanEqualAndLongitudeLessThanEqual(Double minLatitude, Double maxLatitude, Double minLongitude, Double maxLongitude);
List<MatchingEntity> getByType(MatchingTypeEnum type);
List<MatchingEntity> getByIsActive(Boolean isActive);
void deleteAllBy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public FindMatchingDto getMatchingById(Long matchingId) {
public List<FindMatchingDto> getMatchingByWriterId(UUID userId) {
return this.setCurrentMember(findMatchingPort.getByWriterId(userId));
}

@Override
public List<FindMatchingDto> getNearMatching(Double latitude, Double longitude) {
return this.setCurrentMember(findMatchingPort.getByPlaceCoordinate(latitude, longitude));
}

@Override
public List<FindMatchingDto> getMatchingByIsActive(Boolean isActive) {
Expand Down

0 comments on commit 7623fe7

Please sign in to comment.