Skip to content

Commit

Permalink
[Feat] 정체모를 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonInbae committed Oct 1, 2024
1 parent 69b30ac commit 5d0ae16
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.alongtheblue.alongtheblue_server.global.data.cafe.dto.PartCafeResponseDto;
import org.alongtheblue.alongtheblue_server.global.data.restaurant.RestaurantService;
import org.alongtheblue.alongtheblue_server.global.data.restaurant.dto.response.PartRestaurantResponseDto;
import org.alongtheblue.alongtheblue_server.global.data.tourData.TourDataDto;
import org.alongtheblue.alongtheblue_server.global.data.tourData.TourDataService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -24,6 +26,7 @@ public class SearchController {
private final RestaurantService restaurantService;
private final SearchService searchService;
private final CafeService cafeService;
private final TourDataService tourDataService;

@GetMapping("/blue/list")
public ApiResponse<List<BlueResponseDto>> searchBlues() {
Expand Down Expand Up @@ -51,7 +54,7 @@ public ApiResponse<List<AllCategoryResponseDto>> searchAllCategoryByKeyword(@Req
}

@GetMapping("/all/list")
public ApiResponse<List<AllCategoryResponseDto>> getAllCategory(){
public ApiResponse<List<AllCategoryResponseDto>> getAllCategory() {
return searchService.searchAllCategory();
}

Expand All @@ -64,4 +67,14 @@ public ApiResponse<List<PartCafeResponseDto>> getCafesHome() {
public ApiResponse<List<PartCafeResponseDto>> searchCafesByKeyword(@RequestParam String keyword) {
return cafeService.getCafesByKeyword(keyword);
}

@GetMapping("/tourData/list")
public ApiResponse<List<TourDataDto>> getTourData() {
return tourDataService.getHomeTourData();
}

// @GetMapping("/tourData")
// public ApiResponse<List<TourDataDto>> searchTourDataByKeyword(@RequestParam String keyword) {
// return tourDataService.getTourDataByKeyword(keyword);
// }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.alongtheblue.alongtheblue_server.global.data.tourData;

import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void getTourDataImages(){
tourDataService.updateAllTourDataImageUrls();
}
@GetMapping("/home")
public List<TourDataDto> getHomeTourData() {
public ApiResponse<List<TourDataDto>> getHomeTourData() {
return tourDataService.getHomeTourData();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface TourDataRepository extends JpaRepository<TourData, String> {
"LIMIT 6",
nativeQuery = true)
List<TourData> findRandomTourDatasWithImages();

List<TourData> findByTitleContaining(String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse;
import org.alongtheblue.alongtheblue_server.global.data.accommodation.Accommodation;
import org.alongtheblue.alongtheblue_server.global.data.accommodation.AccommodationDTO;
import org.alongtheblue.alongtheblue_server.global.data.accommodation.AccommodationImage;
import org.alongtheblue.alongtheblue_server.global.data.cafe.Cafe;
import org.alongtheblue.alongtheblue_server.global.data.cafe.dto.PartCafeResponseDto;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -353,7 +356,7 @@ public List<TourData> updateInfo() {
return tourDataRepository.findAll();
}

public List<TourDataDto> getHomeTourData() {
public ApiResponse<List<TourDataDto>> getHomeTourData() {
List<TourData> tourDataList = tourDataRepository.findRandomTourDatasWithImages();

// AccommodationDTO 리스트에 데이터를 매핑
Expand All @@ -375,7 +378,7 @@ public List<TourDataDto> getHomeTourData() {
return tourDataDto;
}).collect(Collectors.toList());

return tourDataDtoList;
return ApiResponse.ok("관광지를 성공적으로 조회했습니다.", tourDataDtoList);
}

public TourDataDto getTourDataDetails(String contentsid) {
Expand Down Expand Up @@ -498,5 +501,22 @@ public void updateTourDataImageUrls(TourData tourData) {
}
}

// public ApiResponse<List> getTourDataByKeyword(String keyword) {
// List<TourData> tourDataList = tourDataRepository.findByTitleContaining(keyword);
// List<PartCafeResponseDto> partCafeResponseDtoList = new ArrayList<>();
// for(TourData tourData: tourDataList) {
// String[] arr = cafe.getAddr().substring(8).split(" ");
// PartCafeResponseDto partCafeResponseDto = new PartCafeResponseDto(
// arr[0] + " " + arr[1],
// cafe.getTitle(),
// cafe.getContentId(),
// cafe.getCafeImages().isEmpty() ? null : cafe.getCafeImages().get(0).getOriginimgurl(),
// cafe.getXMap(),
// cafe.getYMap()
// );
// partCafeResponseDtoList.add(partCafeResponseDto);
// }
// return ApiResponse.ok("음식점 정보를 성공적으로 조회했습니다.", partCafeResponseDtoList);
// }
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ public class TourCommunityService {
private final UserTourCourseRepository userTourCourseRepository;
private final TourPostItemRepository tourPostItemRepository;
private final TourImageRepository tourImageRepository;
private final TourPostHashTagRepository tourPostHashTagRepository;
// private final TourPostHashTagRepository tourPostHashTagRepository;

public UserTourCourse createPost(TourCourseRequestDto dto, List<MultipartFile> images) {
// 먼저 userTourCourse 저장

UserTourCourse userTourCourse = new UserTourCourse();
userTourCourse.setTitle(dto.title());
userTourCourse.setTourPostItems(dto.tourItems());
userTourCourse.setTourPostHashTags(dto.hashTags());
// userTourCourse.setTourPostHashTags(dto.hashTags());

TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
userTourCourse.setCreatedate(new Date());
userTourCourse.setWriting(dto.writing());
userTourCourse = userTourCourseRepository.save(userTourCourse);

// tags와 items가 null인 경우 빈 리스트로 초기화
List<TourPostHashTag> tags = userTourCourse.getTourPostHashTags() != null ? userTourCourse.getTourPostHashTags() : new ArrayList<>();
// List<TourPostHashTag> tags = userTourCourse.getTourPostHashTags() != null ? userTourCourse.getTourPostHashTags() : new ArrayList<>();
List<TourPostItem> items = userTourCourse.getTourPostItems() != null ? userTourCourse.getTourPostItems() : new ArrayList<>();

if (dto.index() != null) {
Expand All @@ -58,13 +58,13 @@ public UserTourCourse createPost(TourCourseRequestDto dto, List<MultipartFile> i
}

// tags 리스트가 비어있지 않은 경우 처리
if (!tags.isEmpty()) {
for (TourPostHashTag hashtag : tags) {
// TourPostItem에 UserTourCourse 설정
hashtag.setTourCourseForHashTag(userTourCourse);
}
tourPostHashTagRepository.saveAll(tags);
}
// if (!tags.isEmpty()) {
// for (TourPostHashTag hashtag : tags) {
// // TourPostItem에 UserTourCourse 설정
// hashtag.setTourCourseForHashTag(userTourCourse);
// }
// tourPostHashTagRepository.saveAll(tags);
// }

// userTourCourse 반환 (이미 저장되었으므로)
return userTourCourse;
Expand All @@ -86,7 +86,7 @@ public List<TourDTO> allPost() {
dto.setTitle(tour.getTitle());
dto.setContentid(tour.getContentId());
dto.setWriting(tour.getWriting());
dto.setTags(tourPostHashTagRepository.findBytourCourseForHashTag(tour));
// dto.setTags(tourPostHashTagRepository.findBytourCourseForHashTag(tour));
List<TourPostItem> items= tourPostItemRepository.findByuserTourCourse(tour);
dto.setImg(tourImageRepository.findBytourPostItem(items.get(0)).get(0).getUrl());
dtos.add(dto);
Expand All @@ -105,7 +105,7 @@ public TourDTO onepost(Long postid) {
course= temp.get();
tourDTO.setTitle(course.getTitle());
tourDTO.setWriting(course.getWriting());
tourDTO.setTags(tourPostHashTagRepository.findBytourCourseForHashTag(course));
// tourDTO.setTags(tourPostHashTagRepository.findBytourCourseForHashTag(course));
tourDTO.setContentid(course.getContentId());
for(TourPostItem item: tourPostItemRepository.findByuserTourCourse(course)){
itemDTO.setTitle(item.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class TourDTO {
private String title;
private String writing;
private List<TourPostHashTag> tags;
// private List<TourPostHashTag> tags;
private String contentid;
private String img;
private List<ItemDTO> items;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.alongtheblue.alongtheblue_server.global.data.tourcommunity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;
import lombok.Data;

@Entity
@Data
public class TourPostHashTag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "userTourCourse")
@JsonBackReference
private UserTourCourse tourCourseForHashTag;

private String content;

}
//package org.alongtheblue.alongtheblue_server.global.data.tourcommunity;
//
//import com.fasterxml.jackson.annotation.JsonBackReference;
//import jakarta.persistence.*;
//import lombok.Data;
//
//@Entity
//@Data
//public class TourPostHashTag {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @ManyToOne
// @JoinColumn(name = "userTourCourse")
// @JsonBackReference
// private UserTourCourse tourCourseForHashTag;
//
// private String content;
//
//}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.alongtheblue.alongtheblue_server.global.data.tourcommunity;

import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;

public interface TourPostHashTagRepository extends JpaRepository<TourPostHashTag, Long> {
List<TourPostHashTag> findBytourCourseForHashTag(UserTourCourse userTourCourse);
}
//package org.alongtheblue.alongtheblue_server.global.data.tourcommunity;
//
//import org.springframework.data.jpa.repository.JpaRepository;
//import java.util.List;
//
//public interface TourPostHashTagRepository extends JpaRepository<TourPostHashTag, Long> {
// List<TourPostHashTag> findBytourCourseForHashTag(UserTourCourse userTourCourse);
//}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class UserTourCourse {
@JsonManagedReference
private List<TourPostItem> tourPostItems;

@OneToMany(mappedBy = "tourCourseForHashTag", cascade = CascadeType.ALL)
@JsonManagedReference
private List<TourPostHashTag> tourPostHashTags;
// @OneToMany(mappedBy = "tourCourseForHashTag", cascade = CascadeType.ALL)
// @JsonManagedReference
// private List<TourPostHashTag> tourPostHashTags;

private String contentId;
}

0 comments on commit 5d0ae16

Please sign in to comment.