Skip to content

Commit

Permalink
Merge pull request #39 from 9oormthonUniv-seoultech/feat/#37
Browse files Browse the repository at this point in the history
Feat/#37 포토부스 검색 API
  • Loading branch information
Jeongh00 authored Oct 20, 2024
2 parents fe550a8 + 09ea99c commit 11ddf81
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.dto.photobooth;

public record PhotoBoothSearchDto(
Long id,
String name
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pocket.domain.port.photobooth;

import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;

import java.util.List;

public interface PhotoBoothSearchPort {

List<PhotoBoothSearchDto> searchPhotoBooth(String keyword);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo;
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import com.pocket.domain.port.photobooth.PhotoBoothFindPort;
import com.pocket.domain.port.photobooth.PhotoBoothGetNamePort;
import com.pocket.domain.port.photobooth.PhotoBoothGetRatingPort;
import com.pocket.domain.port.photobooth.PhotoBoothSearchPort;
import com.pocket.domain.usecase.photobooth.PhotoBoothFindUseCase;
import com.pocket.domain.usecase.photobooth.PhotoBoothGetNameUseCase;
import com.pocket.domain.usecase.photobooth.PhotoBoothGetRatingUseCase;
import com.pocket.domain.usecase.photobooth.PhotoBoothSearchUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -18,11 +21,12 @@

@Service
@RequiredArgsConstructor
public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase {
public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase {

private final PhotoBoothFindPort photoBoothFindPort;
private final PhotoBoothGetRatingPort photoBoothGetRatingPort;
private final PhotoBoothGetNamePort photoBoothGetNamePort;
private final PhotoBoothSearchPort photoBoothSearchPort;

public PhotoBoothFindResponseDto findPhotoBoothResponse(Long id) {
return photoBoothFindPort.findById(id);
Expand All @@ -38,4 +42,8 @@ public List<NearPhotoBoothInfo> findNearPhotoBooth(double lat, double lon, List<
public BigDecimal getPhotoBoothRating(Long photoboothId) {
return photoBoothGetRatingPort.getRating(photoboothId);
}

public List<PhotoBoothSearchDto> searchPhotoBooth(String keyword) {
return photoBoothSearchPort.searchPhotoBooth(keyword);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pocket.domain.usecase.photobooth;

import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;

import java.util.List;

public interface PhotoBoothSearchUseCase {

List<PhotoBoothSearchDto> searchPhotoBooth(String keyword);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.pocket.core.exception.common.ApplicationResponse;
import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo;
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import com.pocket.domain.port.photobooth.PhotoBoothGetNamePort;
import com.pocket.domain.usecase.photobooth.PhotoBoothFindUseCase;
import com.pocket.domain.usecase.photobooth.PhotoBoothGetNameUseCase;
import com.pocket.domain.usecase.photobooth.PhotoBoothGetRatingUseCase;
import com.pocket.domain.usecase.photobooth.PhotoBoothSearchUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

Expand All @@ -22,6 +24,7 @@ public class PhotoBoothController implements PhotoBoothControllerDocs {
private final PhotoBoothFindUseCase photoBoothFindUseCase;
private final PhotoBoothGetRatingUseCase photoBoothGetRatingUseCase;
private final PhotoBoothGetNameUseCase photoBoothGetNameUseCase;
private final PhotoBoothSearchUseCase photoBoothSearchUseCase;

@GetMapping("{id}")
public ApplicationResponse<PhotoBoothFindResponseDto> getPhotoBoothById(@PathVariable("id") Long id) {
Expand Down Expand Up @@ -53,4 +56,9 @@ public ApplicationResponse<BigDecimal> getPhotoBoothRating(@PathVariable("id") L
return ApplicationResponse.ok(response);
}

@GetMapping("/search")
public ApplicationResponse<List<PhotoBoothSearchDto>> searchPhotoBooth(@RequestParam("keyword") String keyword) {
List<PhotoBoothSearchDto> response = photoBoothSearchUseCase.searchPhotoBooth(keyword);
return ApplicationResponse.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.pocket.core.exception.common.ApplicationResponse;
import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo;
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -66,4 +67,16 @@ ApplicationResponse<List<NearPhotoBoothInfo>> getAllPhotoBooth(
@Operation(summary = "포토부스 평점 조회", description = "해당 id의 포토부스에 대한 평점을 제공하는 API")
ApplicationResponse<BigDecimal> getPhotoBoothRating(
@PathVariable("id") Long id);

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "BAD REQUEST",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}),
@ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))})
})
@Operation(summary = "포토부스 검색", description = "keyword를 주면 해당 keyword가 포함된 이름의 포토부스 id와 이름을 제공하는 API")
ApplicationResponse<List<PhotoBoothSearchDto>> searchPhotoBooth(
@RequestParam("keyword") String keyword
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class ReviewController implements ReviewControllerDocs {
private final ReviewGetBoothFeatureUseCase reviewGetBoothFeatureUseCase;
private final ReviewGetPhotoFeatureUseCase reviewGetPhotoFeatureUseCase;



@PostMapping
public ApplicationResponse<ReviewRegisterResponseDto> postReview(
@RequestBody ReviewRegisterRequestDto requestDto,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.pocket.outbound.adapter.photobooth.adapter;


import com.pocket.core.aop.annotation.AdapterService;
import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;
import com.pocket.domain.port.photobooth.PhotoBoothSearchPort;
import com.pocket.outbound.entity.photobooth.JpaPhotoBooth;
import com.pocket.outbound.repository.photobooth.PhotoBoothRepository;
import lombok.RequiredArgsConstructor;

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

@AdapterService
@RequiredArgsConstructor
public class PhotoBoothSerachAdapter implements PhotoBoothSearchPort {

private final PhotoBoothRepository photoBoothRepository;

public List<PhotoBoothSearchDto> searchPhotoBooth(String keyword) {
List<JpaPhotoBooth> photoBoothList = photoBoothRepository.findByPhotoBoothNameContaining(keyword);

return photoBoothList.stream()
.map(jpaPhotoBooth -> new PhotoBoothSearchDto(
jpaPhotoBooth.getId(),
jpaPhotoBooth.getPhotoBooth().getName()))
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ public interface PhotoBoothRepository extends JpaRepository<JpaPhotoBooth, Long>
Optional<JpaPhotoBooth> findByPhotoBoothNameAndPhotoBoothXAndPhotoBoothY(String name, double x, double y);

List<JpaPhotoBooth> findByPhotoBoothPhotoBoothBrandIn(List<PhotoBoothBrand> brands);

List<JpaPhotoBooth> findByPhotoBoothNameContaining(String keyword);

}

0 comments on commit 11ddf81

Please sign in to comment.