Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

카페 생성 API 리팩토링 #177

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/main/java/shop/cazait/domain/cafe/api/CafeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
Expand All @@ -26,33 +27,33 @@
import javax.validation.Valid;
import java.util.List;

@Api(tags = "카페 정보 API")
@Api(tags = "카페 API")
@RestController
@RequestMapping("/api/cafes")
@RequiredArgsConstructor
public class CafeController {

private final CafeService cafeService;
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());

@PostMapping(value = "/add/master/{masterId}", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
@ApiOperation(value = "카페 등록", notes = "master가 카페를 등록한다.")
@ApiImplicitParam(name = "masterId", value = "마스터 ID")
public SuccessResponse<String> addCafe(@PathVariable Long masterId,
@RequestParam String json,
@RequestPart(value = "cafeImages", required = false) List<MultipartFile> cafeImage) throws JsonProcessingException {

ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
PostCafeReq postCafeReq = objectMapper.readValue(json, new TypeReference<>() {});
cafeService.addCafe(masterId, postCafeReq, cafeImage);
@Parameter(description = "카페 정보 : {\"name\": \"보난자\", \"address\": \"서울 광진구 능동로 239-1 B동 1층\"")
@RequestParam @Valid String cafeInfo,
@Parameter(description = "카페 이미지") @RequestPart(required = false) List<MultipartFile> cafeImages)
throws JsonProcessingException {
PostCafeReq postCafeReq = objectMapper.readValue(cafeInfo, new TypeReference<>() {});
cafeService.addCafe(masterId, postCafeReq, cafeImages);
return new SuccessResponse<>("카페 등록 완료");

}

@GetMapping("/all/user/{userId}")
@ApiOperation(value = "카페 전체 조회", notes = "ACTIVE한 카페를 조회한다.")
@ApiImplicitParam(name = "userId", value = "유저 ID")
public SuccessResponse<List<List<GetCafesRes>>> getCafeByStatus(@PathVariable Long userId,
@RequestBody PostDistanceReq distanceReq) throws CafeException {
@RequestBody PostDistanceReq distanceReq) throws CafeException {
try {
List<List<GetCafesRes>> cafeResList = cafeService.getCafeByStatus(userId, distanceReq);
return new SuccessResponse<>(cafeResList);
Expand Down Expand Up @@ -84,8 +85,8 @@ public SuccessResponse<GetCafeRes> getCafeById(@PathVariable Long userId,
@ApiImplicitParam(name = "userId", value = "유저 ID")
})
public SuccessResponse<List<List<GetCafesRes>>> getCafeByName(@PathVariable String cafeName,
@PathVariable Long userId,
@RequestBody PostDistanceReq distanceReq) throws CafeException {
@PathVariable Long userId,
@RequestBody PostDistanceReq distanceReq) throws CafeException {
try {
List<List<GetCafesRes>> cafeResList = cafeService.getCafeByName(cafeName, userId, distanceReq);
return new SuccessResponse<>(cafeResList);
Expand Down
13 changes: 0 additions & 13 deletions src/test/java/shop/cazait/CazaitApplicationTests.java

This file was deleted.