Skip to content

Commit

Permalink
Merge branch 'develop' into chore-ci-github_actions
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/prography/cakeke/server/store/adapter/in/web/StoreController.java
  • Loading branch information
govl6113 committed Aug 9, 2023
2 parents eb22f60 + 68a4e32 commit f835ff5
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 105 deletions.
14 changes: 0 additions & 14 deletions src/main/java/prography/cakeke/server/TestController.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package prography.cakeke.server.store.adapter.in.web;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -12,9 +13,10 @@

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse;
import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO;
import prography.cakeke.server.store.adapter.in.web.response.FeedImageResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreBlogResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreBookmarkResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreDetailResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreTagResponse;
Expand All @@ -31,7 +33,7 @@ public class StoreController {

@Operation(description = "각 구별 가게 갯수 조회")
@GetMapping("/district/count")
public ResponseEntity<List<DistrictCountResponse>> getCount() {
public ResponseEntity<List<DistrictCountDTO>> getCount() {
return ResponseEntity.ok().body(this.storeUseCase.getCount());
}

Expand All @@ -54,10 +56,10 @@ public ResponseEntity<List<StoreResponse>> getList(
public ResponseEntity<List<StoreResponse>> reload(
@RequestParam(value = "storeTypes", required = false) List<StoreType> storeTypes,
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "southwestLatitude", required = true) Double southwestLatitude,
@RequestParam(value = "southwestLongitude", required = true) Double southwestLongitude,
@RequestParam(value = "northeastLatitude", required = true) Double northeastLatitude,
@RequestParam(value = "northeastLongitude", required = true) Double northeastLongitude
@RequestParam(value = "southwestLatitude") Double southwestLatitude,
@RequestParam(value = "southwestLongitude") Double southwestLongitude,
@RequestParam(value = "northeastLatitude") Double northeastLatitude,
@RequestParam(value = "northeastLongitude") Double northeastLongitude
) {
return ResponseEntity.ok().body(
this.storeUseCase.reload(
Expand All @@ -80,38 +82,31 @@ public ResponseEntity<StoreTagResponse> getStoreType(@PathVariable(value = "id")
@Operation(description = "feed로 케이크 이미지 조회")
@GetMapping("/feed")
public ResponseEntity<List<FeedImageResponse>> getFeedImage(
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "southwestLatitude", required = true) Double southwestLatitude,
@RequestParam(value = "southwestLongitude", required = true) Double southwestLongitude,
@RequestParam(value = "northeastLatitude", required = true) Double northeastLatitude,
@RequestParam(value = "northeastLongitude", required = true) Double northeastLongitude
@RequestParam(value = "page", required = false, defaultValue = "1") int page
) {
List<Store> stores = this.storeUseCase.reload(
null, page,
southwestLatitude, southwestLongitude,
northeastLatitude, northeastLongitude
);
List<Store> stores = this.storeUseCase.getList(null, null, page);

List<FeedImageResponse> response = stores
.stream().flatMap(
store -> store.getImageUrls()
.stream().map(
imageUrl -> new FeedImageResponse(store.getId(), imageUrl)
imageUrl -> new FeedImageResponse(
store.getId(), store.getName(), store.getDistrict(), imageUrl)
)
)
.collect(Collectors.toList());

Collections.shuffle(response);
return ResponseEntity.ok().body(response);
}

@Operation(description = "케이크샵 상세 정보 조회(상세 정보만)")
@GetMapping("/{id}")
public ResponseEntity<StoreDetailResponse> getStoreDetail(@PathVariable("id") Long storeId) {
StoreResponse storeResponse = this.storeUseCase.getStore(storeId);
Store store = this.storeUseCase.getStore(storeId);
return ResponseEntity.ok().body(
new StoreDetailResponse(
storeResponse,
this.storeUseCase.getNaverLocalApiByStore(storeResponse)));
new StoreDetailResponse(store,
this.storeUseCase.getNaverLocalApiByStore(store)));
}

@Operation(description = "케이크샵 블로그 정보 조회")
Expand All @@ -122,4 +117,10 @@ public ResponseEntity<StoreBlogResponse> getStoreBlog(
return ResponseEntity.ok().body(
new StoreBlogResponse(this.storeUseCase.getNaverBlogApiByStore(storeId, blogNum)));
}

@Operation(description = "북마크 가게 조회")
@GetMapping("/{id}/bookmark")
public ResponseEntity<StoreBookmarkResponse> getStoreBookmark(@PathVariable(value = "id") Long storeId) {
return ResponseEntity.ok().body(new StoreBookmarkResponse(this.storeUseCase.getStore(storeId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@Getter
@NoArgsConstructor
public class DistrictCountResponse {
public class DistrictCountDTO {

District district;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

import lombok.Builder;
import lombok.Getter;
import prography.cakeke.server.store.domain.District;

@Getter
public class FeedImageResponse {

Long storeId;

String storeName;

District district;

String imageUrl;

@Builder
public FeedImageResponse(Long storeId, String imageUrl) {
public FeedImageResponse(Long storeId, String storeName, District district, String imageUrl) {
this.storeId = storeId;
this.storeName = storeName;
this.district = district;
this.imageUrl = imageUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package prography.cakeke.server.store.adapter.in.web.response;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;
import prography.cakeke.server.store.domain.District;
import prography.cakeke.server.store.domain.Store;

@Getter
@AllArgsConstructor
public class StoreBookmarkResponse {

Long id;

String name;

District district;

String location;

List<String> imageUrls;

public StoreBookmarkResponse(Store store) {
this.id = store.getId();
this.name = store.getName();
this.district = store.getDistrict();
this.location = store.getLocation();
this.imageUrls = store.getImageUrls() != null ? store.getImageUrls() : List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import prography.cakeke.server.store.domain.City;
import prography.cakeke.server.store.domain.District;
import prography.cakeke.server.store.domain.Store;
import prography.cakeke.server.store.domain.StoreAndTag;
import prography.cakeke.server.store.domain.StoreTag;
import prography.cakeke.server.store.domain.StoreType;

@Getter
Expand Down Expand Up @@ -49,21 +53,24 @@ public class StoreDetailResponse {

@Builder
public StoreDetailResponse(
StoreResponse storeResponse, StoreNaverLocalSearchApiResponse storeNaverLocalSearchApiResponse
Store store, StoreNaverLocalSearchApiResponse storeNaverLocalSearchApiResponse
) {
this.id = storeResponse.getId();
this.createdAt = storeResponse.getCreatedAt();
this.modifiedAt = storeResponse.getModifiedAt();
this.name = storeResponse.getName();
this.shareLink = storeResponse.getShareLink();
this.city = storeResponse.getCity();
this.district = storeResponse.getDistrict();
this.location = storeResponse.getLocation();
this.latitude = storeResponse.getLatitude();
this.longitude = storeResponse.getLongitude();
this.storeTypes = storeResponse.getStoreTypes();
this.thumbnail = storeResponse.getThumbnail();
this.imageUrls = storeResponse.getImageUrls();
List<StoreTag> storeTagList = store.getStoreAndTags().stream().map(StoreAndTag::getStoreTag).toList();
this.storeTypes = storeTagList != null ?
storeTagList.stream().map(StoreTag::getStoreType).collect(Collectors.toList())
: List.of();
this.id = store.getId();
this.createdAt = store.getCreatedAt();
this.modifiedAt = store.getModifiedAt();
this.name = store.getName();
this.shareLink = store.getShareLink();
this.city = store.getCity();
this.district = store.getDistrict();
this.location = store.getLocation();
this.latitude = store.getLatitude();
this.longitude = store.getLongitude();
this.thumbnail = store.getThumbnail();
this.imageUrls = store.getImageUrls();
this.link = storeNaverLocalSearchApiResponse.getLink();
this.description = storeNaverLocalSearchApiResponse.getDescription();
this.phoneNumber = storeNaverLocalSearchApiResponse.getPhoneNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Getter
public class StoreNaverLocalSearchApiResponse {
String link; // 가게 URL

String description; // 가게 설명

String phoneNumber; // 가게 번호
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<StoreNaverBlogSearchApiResponse> getNaverBlogSearchResponse(String s
* sim: 정확도순으로 내림차순 정렬(기본값)
* date: 날짜순으로 내림차순 정렬
* */
final String sortType = "sim";
final String sortType = "date";
JSONArray responseJson = getNaverSearchApiResponse(storeName, blogNum, sortType, blogPath);

List<StoreNaverBlogSearchApiResponse> storeNaverBlogSearchApiResponseList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static com.querydsl.core.group.GroupBy.list;

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

import org.springframework.data.domain.Pageable;
Expand All @@ -16,8 +15,7 @@
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;
import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreResponse;
import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO;
import prography.cakeke.server.store.application.port.out.DeleteStorePort;
import prography.cakeke.server.store.application.port.out.LoadStorePort;
import prography.cakeke.server.store.application.port.out.SaveStorePort;
Expand All @@ -43,9 +41,9 @@ public class StorePersistenceAdapter implements LoadStorePort, SaveStorePort, De
private final QStoreTag storeTag = QStoreTag.storeTag;

@Override
public List<DistrictCountResponse> getDistrictCount() {
public List<DistrictCountDTO> getDistrictCount() {
return queryFactory
.select(Projections.fields(DistrictCountResponse.class,
.select(Projections.fields(DistrictCountDTO.class,
store.district,
store.id.count().as("count")
))
Expand All @@ -71,26 +69,17 @@ public List<Store> getList(
.distinct()
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(store.id.asc())
.fetch();
}

@Override
public Map<Long, StoreResponse> getStore(Long storeId) {
public Store getStore(Long storeId) {
return queryFactory
.select(store)
.from(store)
.leftJoin(store.storeAndTags, storeAndTag)
.leftJoin(storeAndTag.storeTag, storeTag)
.selectFrom(store)
.leftJoin(store.storeAndTags, storeAndTag).fetchJoin()
.leftJoin(storeAndTag.storeTag, storeTag).fetchJoin()
.where(store.id.eq(storeId))
.transform(
groupBy(store.id).as(
Projections.constructor(StoreResponse.class,
store,
list(storeTag)
)
)
);
.fetchOne();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import java.util.List;

import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse;
import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO;
import prography.cakeke.server.store.adapter.in.web.response.StoreNaverBlogSearchApiResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreNaverLocalSearchApiResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreResponse;
import prography.cakeke.server.store.domain.District;
import prography.cakeke.server.store.domain.Store;
import prography.cakeke.server.store.domain.StoreTag;
import prography.cakeke.server.store.domain.StoreType;

public interface StoreUseCase {
List<DistrictCountResponse> getCount();
List<DistrictCountDTO> getCount();

List<Store> getList(List<District> district, List<StoreType> storeTypes, int page);

Expand All @@ -24,9 +23,9 @@ List<Store> reload(

List<StoreTag> getStoreTypeByStoreId(Long storeId);

StoreResponse getStore(Long storeId);
Store getStore(Long storeId);

StoreNaverLocalSearchApiResponse getNaverLocalApiByStore(StoreResponse storeResponse);
StoreNaverLocalSearchApiResponse getNaverLocalApiByStore(Store store);

List<StoreNaverBlogSearchApiResponse> getNaverBlogApiByStore(Long storeId, Integer blogNum);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
package prography.cakeke.server.store.application.port.out;

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

import org.springframework.data.domain.Pageable;

import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse;
import prography.cakeke.server.store.adapter.in.web.response.StoreResponse;
import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO;
import prography.cakeke.server.store.domain.District;
import prography.cakeke.server.store.domain.Store;
import prography.cakeke.server.store.domain.StoreTag;
import prography.cakeke.server.store.domain.StoreType;

public interface LoadStorePort {
List<DistrictCountResponse> getDistrictCount();
List<DistrictCountDTO> getDistrictCount();

List<Store> getList(
List<District> district, List<StoreType> storeTypes, Pageable pageable,
Double southwestLongitude, Double northeastLongitude,
Double southwestLatitude, Double northeastLatitude
);

Map<Long, StoreResponse> getStore(Long storeId);
Store getStore(Long storeId);

Optional<Store> getByName(String name);

Expand Down
Loading

0 comments on commit f835ff5

Please sign in to comment.