Skip to content

Commit

Permalink
Merge pull request #78 from AR-TTUBEOG/feat/77
Browse files Browse the repository at this point in the history
[Feat] 방명록, 스팟 프론트요구사항 반영
  • Loading branch information
choeun7 authored Feb 18, 2024
2 parents 1d8394a + 6940213 commit 84de22f
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ public List<Comment> getAllComments() {
// AR뷰를 위한 댓글 조회
public ResponseEntity<?> getCommentForAR(GetCommentReq getCommentReq) {

Float userLatitude = getCommentReq.getLatitude();
Float userLongitude = getCommentReq.getLongitude();
Double userLatitude = getCommentReq.getLatitude();
Double userLongitude = getCommentReq.getLongitude();

List<Comment> allComments = getAllComments();
Double radius = 20.0; // 반경값 확인 필요
List<GetCommentRes> showComments = new ArrayList<>();

for (Comment comment : allComments) {

Float commentLatitude = comment.getLatitude();
Float commentLongitude = comment.getLongitude();
Double commentLatitude = comment.getLatitude();
Double commentLongitude = comment.getLongitude();

double distance = calculateDistance(userLatitude, userLongitude, commentLatitude, commentLongitude);

Expand All @@ -153,7 +153,7 @@ public ResponseEntity<?> getCommentForAR(GetCommentReq getCommentReq) {
}

// 거리 계산
private double calculateDistance(Float lat1, Float lon1, Float lat2, Float lon2) {
private double calculateDistance(Double lat1, Double lon1, Double lat2, Double lon2) {
double R = 6371; // 지구 반지름

double dLat = Math.toRadians(lat2 - lat1);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ttubeog/domain/comment/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class Comment extends BaseEntity {
private String content;

@Column(name = "latitude")
private Float latitude;
private Double latitude;

@Column(name = "longitude")
private Float longitude;
private Double longitude;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
public class GetCommentReq {

@Schema(description = "사용자 위치 위도값")
private Float latitude;
private Double latitude;

@Schema(description = "사용자 위치 경도값")
private Float longitude;
private Double longitude;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class WriteCommentReq {
@Schema(description = "댓글 내용")
private String content;
@Schema(description = "위도")
private Float latitude;
private Double latitude;
@Schema(description = "경도")
private Float longitude;
private Double longitude;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class WriteCommentRes {
private String content;

@Schema(description = "위도")
private Float latitude;
private Double latitude;

@Schema(description = "경도")
private Float longitude;
private Double longitude;

@Builder
public WriteCommentRes(Long commentId, Long memberId, String content, Float latitude, Float longitude) {
public WriteCommentRes(Long commentId, Long memberId, String content, Double latitude, Double longitude) {
this.commentId = commentId;
this.memberId = memberId;
this.content = content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
Expand Down Expand Up @@ -66,6 +67,7 @@ private ResponseEntity<?> getResponseEntity(GuestBook guestBook) {
.guestBookType(guestBook.getGuestBookType())
.spotId(guestBook.getSpot().getId())
.memberId(guestBook.getMember().getId())
.memberName(guestBook.getMember().getNickname())
.star(guestBook.getStar())
.build();
} else if (guestBook.getGuestBookType().equals(GuestBookType.STORE)) {
Expand All @@ -75,6 +77,7 @@ private ResponseEntity<?> getResponseEntity(GuestBook guestBook) {
.guestBookType(guestBook.getGuestBookType())
.storeId(guestBook.getStore().getId())
.memberId(guestBook.getMember().getId())
.memberName(guestBook.getMember().getNickname())
.star(guestBook.getStar())
.build();
} else {
Expand Down Expand Up @@ -195,19 +198,17 @@ public ResponseEntity<?> findGuestBookBySpotId(HttpServletRequest request, Long

Page<GuestBook> guestBookPage = guestBookRepository.findAllBySpot(spot, PageRequest.of(pageNum, 10));

List<GuestBookResponseDto> guestBookResponseDtoList = null;

for (GuestBook guestBook : guestBookPage) {
GuestBookResponseDto guestBookResponseDto = GuestBookResponseDto.builder()
.id(guestBook.getId())
.content(guestBook.getContent())
.guestBookType(guestBook.getGuestBookType())
.spotId(guestBook.getSpot().getId())
.memberId(guestBook.getMember().getId())
.star(guestBook.getStar())
.build();
guestBookResponseDtoList.add(guestBookResponseDto);
}
List<GuestBookResponseDto> guestBookResponseDtoList = guestBookPage.stream().map(
guestBook -> GuestBookResponseDto.builder()
.id(guestBook.getId())
.content(guestBook.getContent())
.guestBookType(guestBook.getGuestBookType())
.spotId(guestBook.getSpot().getId())
.memberId(guestBook.getMember().getId())
.memberName(guestBook.getMember().getNickname())
.star(guestBook.getStar())
.build()
).toList();

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
Expand All @@ -227,19 +228,17 @@ public ResponseEntity<?> findGuestBookByStoreId(HttpServletRequest request, Long

Page<GuestBook> guestBookPage = guestBookRepository.findAllByStore(store, PageRequest.of(pageNum, 10));

List<GuestBookResponseDto> guestBookResponseDtoList = null;

for (GuestBook guestBook : guestBookPage) {
GuestBookResponseDto guestBookResponseDto = GuestBookResponseDto.builder()
.id(guestBook.getId())
.content(guestBook.getContent())
.guestBookType(guestBook.getGuestBookType())
.spotId(guestBook.getSpot().getId())
.memberId(guestBook.getMember().getId())
.star(guestBook.getStar())
.build();
guestBookResponseDtoList.add(guestBookResponseDto);
}
List<GuestBookResponseDto> guestBookResponseDtoList = guestBookPage.stream().map(
guestBook -> GuestBookResponseDto.builder()
.id(guestBook.getId())
.content(guestBook.getContent())
.guestBookType(guestBook.getGuestBookType())
.storeId(guestBook.getStore().getId())
.memberId(guestBook.getMember().getId())
.memberName(guestBook.getMember().getNickname())
.star(guestBook.getStar())
.build()
).toList();

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class GuestBookResponseDto {

private Long memberId;

private String memberName;

private GuestBookType guestBookType;

private Long spotId;
Expand All @@ -24,9 +26,10 @@ public class GuestBookResponseDto {

private Float star;

public GuestBookResponseDto(Long id, Long memberId, GuestBookType guestBookType, Long spotId, Long storeId, String content, Float star) {
public GuestBookResponseDto(Long id, Long memberId, String memberName, GuestBookType guestBookType, Long spotId, Long storeId, String content, Float star) {
this.id = id;
this.memberId = memberId;
this.memberName = memberName;
this.guestBookType = guestBookType;
this.spotId = spotId;
this.storeId = storeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ private GetAllPlaceRes mapSpotToDto(HttpServletRequest request, Spot spot) {
.memberId(spot.getMember().getId())
.name(spot.getName())
.info(spot.getInfo())
// 위도, 경도 double로 변경 필요
//.latitude(spot.getLatitude())
//.longitude(spot.getLongitude())
.latitude(spot.getLatitude())
.longitude(spot.getLongitude())
.image(representativeImageUrl)
.stars(spot.getStars())
.guestbookCount(intValue(guestBookRepository.countAllBySpot(spot)))
Expand Down
44 changes: 35 additions & 9 deletions src/main/java/com/ttubeog/domain/spot/application/SpotService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.ttubeog.domain.spot.application;

import com.ttubeog.domain.auth.security.JwtTokenProvider;
import com.ttubeog.domain.benefit.domain.repository.BenefitRepository;
import com.ttubeog.domain.guestbook.domain.GuestBook;
import com.ttubeog.domain.guestbook.domain.repository.GuestBookRepository;
import com.ttubeog.domain.image.application.ImageService;
import com.ttubeog.domain.image.domain.Image;
import com.ttubeog.domain.image.domain.ImageType;
import com.ttubeog.domain.image.domain.repository.ImageRepository;
import com.ttubeog.domain.image.dto.request.CreateImageRequestDto;
import com.ttubeog.domain.likes.domain.repository.LikesRepository;
import com.ttubeog.domain.member.domain.Member;
import com.ttubeog.domain.member.domain.repository.MemberRepository;
import com.ttubeog.domain.member.exception.InvalidMemberException;
Expand All @@ -16,10 +18,12 @@
import com.ttubeog.domain.spot.domain.repository.SpotRepository;
import com.ttubeog.domain.spot.dto.request.CreateSpotRequestDto;
import com.ttubeog.domain.spot.dto.request.UpdateSpotRequestDto;
import com.ttubeog.domain.spot.dto.response.GetSpotDetailRes;
import com.ttubeog.domain.spot.dto.response.SpotResponseDto;
import com.ttubeog.domain.spot.exception.AlreadyExistsSpotException;
import com.ttubeog.domain.spot.exception.InvalidImageListSizeException;
import com.ttubeog.domain.spot.exception.InvalidSpotIdException;
import com.ttubeog.domain.store.exception.NonExistentStoreException;
import com.ttubeog.global.payload.ApiResponse;
import com.ttubeog.global.payload.Message;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -42,6 +46,8 @@ public class SpotService {
private final MemberRepository memberRepository;
private final ImageRepository imageRepository;
private final GuestBookRepository guestBookRepository;
private final LikesRepository likesRepository;
private final BenefitRepository benefitRepository;

private final ImageService imageService;

Expand Down Expand Up @@ -71,6 +77,7 @@ private ResponseEntity<?> getResponseEntity(Spot spot) {
return ResponseEntity.ok(apiResponse);
}

//Spot 생성 Method
@Transactional
public ResponseEntity<?> createSpot(HttpServletRequest request, CreateSpotRequestDto createSpotRequestDto) {

Expand Down Expand Up @@ -117,16 +124,39 @@ public ResponseEntity<?> createSpot(HttpServletRequest request, CreateSpotReques
return getResponseEntity(spot);
}

//ID로 스팟 조회 Method
public ResponseEntity<?> findBySpotId(HttpServletRequest request, Long spotId) {

Long memberId = jwtTokenProvider.getMemberId(request);
Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new);
Spot spot = spotRepository.findById(spotId).orElseThrow(NonExistentStoreException::new);

// 유효한 사용자 로그인 상태인지 체크
memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new);
Integer guestbookCount = guestBookRepository.countAllBySpot(spot).intValue();
Integer likesCount = likesRepository.countBySpot(spot);
Boolean isFavorited = likesRepository.existsByMemberAndSpot(member, spot);

Spot spot = spotRepository.findById(spotId).orElseThrow(InvalidSpotIdException::new);
GetSpotDetailRes getSpotDetailRes = GetSpotDetailRes.builder()
.spotId(spotId)
.memberId(spot.getMember().getId())
.name(spot.getName())
.info(spot.getInfo())
.dongAreaId(spot.getDongArea())
.detailAddress(spot.getDetailAddress())
.latitude(spot.getLatitude())
.longitude(spot.getLongitude())
.image(getImageString(imageRepository.findBySpotId(spot.getId())))
.stars(spot.getStars())
.guestbookCount(guestbookCount)
.likesCount(likesCount)
.isFavorited(isFavorited)
.build();

return getResponseEntity(spot);
ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(getSpotDetailRes)
.build();

return ResponseEntity.ok(apiResponse);
}

@Transactional
Expand Down Expand Up @@ -181,6 +211,7 @@ public ResponseEntity<?> updateSpot(HttpServletRequest request, Long spotId, Upd
return getResponseEntity(spot);
}

//Spot 삭제 Method
@Transactional
public ResponseEntity<?> deleteSpot(HttpServletRequest request, Long spotId) {

Expand Down Expand Up @@ -210,9 +241,4 @@ public ResponseEntity<?> deleteSpot(HttpServletRequest request, Long spotId) {

return ResponseEntity.ok(apiResponse);
}

@Transactional
public ResponseEntity<?> likeSpot(HttpServletRequest request, Integer spotId) {
return null;
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/ttubeog/domain/spot/domain/Spot.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public class Spot extends BaseEntity {

@Schema(description = "위도", example = "36.5642886")
@Column(name = "latitude", nullable = false)
private Float latitude;
private Double latitude;

@Schema(description = "경도", example = "126.9275718")
@Column(name = "longitude", nullable = false)
private Float longitude;
private Double longitude;

@Schema(description = "별점 평균", example = "3.4")
@Column(name = "stars")
Expand All @@ -60,7 +60,7 @@ public class Spot extends BaseEntity {
@Column(name = "detail_address", nullable = false)
private String detailAddress;

public Spot(Long id, String name, String info, Float latitude, Float longitude, Float stars, Member member, String dongArea, String detailAddress) {
public Spot(Long id, String name, String info, Double latitude, Double longitude, Float stars, Member member, String dongArea, String detailAddress) {
this.id = id;
this.name = name;
this.info = info;
Expand All @@ -72,7 +72,7 @@ public Spot(Long id, String name, String info, Float latitude, Float longitude,
this.detailAddress = detailAddress;
}

public void updateSpot(String name, String info, Float latitude, Float longitude, String dongArea, String detailAddress) {
public void updateSpot(String name, String info, Double latitude, Double longitude, String dongArea, String detailAddress) {
this.name = name;
this.info = info;
this.latitude = latitude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class CreateSpotRequestDto {
private String info;

@Schema(description = "위도", defaultValue = "36.5642886")
private Float latitude;
private Double latitude;

@Schema(description = "경도", defaultValue = "126.9275718")
private Float longitude;
private Double longitude;

@Schema(description = "이미지 리스트")
private List<String> image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class UpdateSpotRequestDto {
private String info;

@Schema(description = "위도", defaultValue = "36.5642886")
private Float latitude;
private Double latitude;

@Schema(description = "경도", defaultValue = "126.9275718")
private Float longitude;
private Double longitude;

@Schema(description = "이미지 리스트")
private List<String> image;
Expand Down
Loading

0 comments on commit 84de22f

Please sign in to comment.