Skip to content

Commit

Permalink
[Chore] #268 - Congestion DTO 네이밍 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
parkrootseok committed May 10, 2023
1 parent 254148b commit 71d7fac
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shop.cazait.domain.congestion.dto.PostCongestionReq;
import shop.cazait.domain.congestion.dto.PostCongestionRes;
import shop.cazait.domain.congestion.dto.request.CongestionUpdateInDTO;
import shop.cazait.domain.congestion.dto.response.CongestionUpdateOutDTO;
import shop.cazait.domain.congestion.exception.CongestionException;
import shop.cazait.domain.congestion.service.CongestionService;
import shop.cazait.domain.user.exception.UserException;
import shop.cazait.global.common.dto.response.SuccessResponse;
import shop.cazait.global.config.encrypt.JwtService;
import shop.cazait.global.error.status.SuccessStatus;

@Tag(name = "혼잡도 API")
Expand All @@ -25,20 +27,21 @@
public class CongestionApiController {

private final CongestionService congestionService;
private final JwtService jwtService;

@Operation(summary = "혼잡도 등록 및 수정", description = "마스터 ID, 카페 ID, 혼잡도 상태를 받아 혼잡도를 수정 또는 등록한다.")
@Parameters({
@Parameter(name = "masterId", description = "카페에 대한 권한이 있는 마스터 ID"),
@Parameter(name = "cafeId", description = "혼잡도를 등록 또는 수정할 카페 ID")
})
@PostMapping("/master/{masterId}/cafe/{cafeId}")
public SuccessResponse<PostCongestionRes> addCongestion(@PathVariable Long masterId,
@PathVariable Long cafeId,
@RequestBody @Valid PostCongestionReq postCongestionReq)
public SuccessResponse<CongestionUpdateOutDTO> addCongestion(@PathVariable Long masterId,
@PathVariable Long cafeId,
@RequestBody @Valid CongestionUpdateInDTO congestionUpdateInDTO)
throws CongestionException {

return new SuccessResponse<>(
SuccessStatus.CREATE_CONGESTION, congestionService.addAndUpdateCongestion(cafeId, postCongestionReq));
SuccessStatus.CREATE_CONGESTION, congestionService.addAndUpdateCongestion(cafeId, congestionUpdateInDTO));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package shop.cazait.domain.congestion.dto;
package shop.cazait.domain.congestion.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotBlank;
Expand All @@ -9,10 +9,10 @@
import shop.cazait.domain.congestion.entity.Congestion;
import shop.cazait.domain.congestion.entity.CongestionStatus;

@Schema(description = "혼잡도 등록(수정) Request : 등록 및 수정할 혼잡도 정보")
@Schema(name = "혼잡도 등록(수정) Request", description = "등록 및 수정할 혼잡도 정보")
@Data
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PostCongestionReq {
public class CongestionUpdateInDTO {

@Schema(description = "혼잡도 상태", required = true, example = "FREE")
@NotBlank(message = "혼잡도를 입력해주세요.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package shop.cazait.domain.congestion.dto;
package shop.cazait.domain.congestion.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
Expand All @@ -9,7 +9,7 @@
@Schema(description = "혼잡도 등록(수정) Response : 등록 또는 수정 완료한 혼잡도 정보")
@Getter
@Builder(access = AccessLevel.PRIVATE)
public class PostCongestionRes {
public class CongestionUpdateOutDTO {

@Schema(description = "혼잡도 ID", example = "1")
private Long congestionId;
Expand All @@ -20,9 +20,9 @@ public class PostCongestionRes {
@Schema(description = "혼잡도 상태", example = "FREE")
private String congestionStatus;

public static PostCongestionRes of(Congestion newCongestion) {
public static CongestionUpdateOutDTO of(Congestion newCongestion) {

return PostCongestionRes.builder()
return CongestionUpdateOutDTO.builder()
.congestionId(newCongestion.getId())
.cafeId(newCongestion.getCafe().getId())
.congestionStatus(newCongestion.getCongestionStatus().getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import shop.cazait.domain.cafe.entity.Cafe;
import shop.cazait.domain.cafe.exception.CafeException;
import shop.cazait.domain.cafe.repository.CafeRepository;
import shop.cazait.domain.congestion.dto.PostCongestionReq;
import shop.cazait.domain.congestion.dto.PostCongestionRes;
import shop.cazait.domain.congestion.dto.request.CongestionUpdateInDTO;
import shop.cazait.domain.congestion.dto.response.CongestionUpdateOutDTO;
import shop.cazait.domain.congestion.entity.Congestion;
import shop.cazait.domain.congestion.entity.CongestionStatus;
import shop.cazait.domain.congestion.exception.CongestionException;
Expand All @@ -29,13 +29,13 @@ public class CongestionService {
/**
* 혼잡도 등록 및 수정
*/
public PostCongestionRes addAndUpdateCongestion(Long cafeId, PostCongestionReq postCongestionReq) {
public CongestionUpdateOutDTO addAndUpdateCongestion(Long cafeId, CongestionUpdateInDTO congestionUpdateInDTO) {

Cafe findCafe = getCafe(cafeId);
Congestion findCongestion = findCafe.getCongestion();
Congestion newCongestion = null;

CongestionStatus congestionStatus = getCongestionStatus(postCongestionReq.getCongestionStatus());
CongestionStatus congestionStatus = getCongestionStatus(congestionUpdateInDTO.getCongestionStatus());

if (findCongestion == NOT_EXIST_CONGESTION) {
newCongestion = addCongestion(findCafe, congestionStatus);
Expand All @@ -46,7 +46,7 @@ public PostCongestionRes addAndUpdateCongestion(Long cafeId, PostCongestionReq p

}

return PostCongestionRes.of(newCongestion);
return CongestionUpdateOutDTO.of(newCongestion);

}

Expand All @@ -72,7 +72,7 @@ private CongestionStatus getCongestionStatus(String congestionStatus) {

private Congestion addCongestion(Cafe cafe, CongestionStatus congestionStatus) {

Congestion addCongestion = PostCongestionReq.toEntity(cafe, congestionStatus);
Congestion addCongestion = CongestionUpdateInDTO.toEntity(cafe, congestionStatus);
congestionRepository.save(addCongestion);
cafe.changeCongestion(addCongestion);
cafeRepository.save(cafe);
Expand Down

0 comments on commit 71d7fac

Please sign in to comment.