Skip to content

Commit

Permalink
feat: content detail api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JONG-KYEONG committed Aug 13, 2024
1 parent 18d3163 commit 93a23fc
Show file tree
Hide file tree
Showing 38 changed files with 99 additions and 0 deletions.
Binary file modified server/.gradle/8.8/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified server/.gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified server/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified server/build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,39 @@ public RecentKeywordResponse getRecentKeyword(Long userId){
}
return new RecentKeywordResponse(recentKeywords);
}

public ContentDetailResponse getContentDetailResponse(Long userId, Long contentId){
User user = userRepository.findById(userId)
.orElseThrow(() -> new BadRequestException("유저 토큰 값을 다시 확인해주세요"));
DataField dataField = dataFieldRepository.findById(contentId)
.orElseThrow(() -> new BadRequestException("contentId 값을 다시 확인해주세요"));
List<Data> datas = dataRepository.findAllByTitle(dataField.getTitleName());
List<String> addressTags = new ArrayList<>();
List<PlaceDto> placeDtos = new ArrayList<>();
for(Data data : datas){
PlaceDto placeDto = PlaceDto.builder()
.placeId(data.getId())
.placeAddress(data.getAddress())
.placeImage(data.getImage())
.placeOverview(data.getPlaceOverview())
.placeName(data.getPlaceName())
.openTime(data.getOpenTime())
.build();
placeDtos.add(placeDto);

String[] parts = data.getAddress().split(" ");
if(!addressTags.contains(parts[0]))
addressTags.add(parts[0]);
}
ContentDetailResponse contentDetailResponse = ContentDetailResponse.builder()
.contentId(contentId)
.contentImage(dataField.getImage())
.contentType(dataField.getMediaType())
.addressTag(addressTags)
.contentTitle(dataField.getTitleName())
.isScraped(isScraped(user,dataField))
.placeDtos(placeDtos)
.build();
return contentDetailResponse;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.hackathon.content.controller;

import com.example.hackathon.content.application.ContentService;
import com.example.hackathon.content.dto.ContentDetailResponse;
import com.example.hackathon.content.dto.InterestContentResponse;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@RequestMapping("/api/detail")
public class ContentDetailController {
private final ContentService contentService;
@GetMapping("/content")
@Operation(summary = "내가 관심 있어 하는 장르의 작품 리스트 + 간편 주소를 가져옵니다. " ,description = "userId와 가져올 컨텐츠 갯수를 파라미터로 넣어주세요")
public ResponseEntity<ContentDetailResponse> getInterestContentResponse(@RequestParam Long userId, @RequestParam Long contentId) {
ContentDetailResponse contentDetailResponse = contentService.getContentDetailResponse(userId, contentId);
return new ResponseEntity<>(contentDetailResponse, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.hackathon.content.dto;

import lombok.Builder;

import java.util.List;

@Builder
public record ContentDetailResponse(
Long contentId,
String contentTitle,
String contentImage,
String contentType,
Boolean isScraped,
List<String> addressTag,
List<PlaceDto> placeDtos
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.hackathon.content.dto;

import lombok.Builder;

@Builder
public record PlaceDto(
Long placeId,
String placeName,
String placeOverview,
String placeImage,
String placeAddress,
String openTime
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ public class Data {
private String mapX;
@Column(name = "tel")
private String tel;
@Column(name = "image")
private String image;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface DataRepository extends JpaRepository<Data, Long> {
@Query("SELECT d FROM Data d WHERE d.titleName=:title ORDER BY RAND() limit 1")
Optional<Data> findByTitle(@Param("title")String title);

@Query("SELECT d FROM Data d WHERE d.titleName=:title")
List<Data> findAllByTitle(@Param("title")String title);
}

0 comments on commit 93a23fc

Please sign in to comment.