Skip to content

Commit

Permalink
Merge pull request #93 from kko-bugi/feature/8-getProduceEditView
Browse files Browse the repository at this point in the history
[feature/8-getProduceEditView] 판매글 수정 화면 조회 API
  • Loading branch information
JoongHyun-Kim authored Feb 23, 2024
2 parents f52a6cd + cd79784 commit be4e226
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.kkobugi.puremarket.common.BaseException;
import com.kkobugi.puremarket.common.gcs.GCSService;
import com.kkobugi.puremarket.produce.domain.dto.ProduceEditViewResponse;
import com.kkobugi.puremarket.produce.domain.dto.ProduceListResponse;
import com.kkobugi.puremarket.produce.domain.dto.ProducePostRequest;
import com.kkobugi.puremarket.produce.domain.dto.ProduceResponse;
Expand Down Expand Up @@ -125,7 +126,7 @@ public void changeProduceStatus(Long produceIdx) throws BaseException {
}
}

// 판매글 삭제
// [작성자] 판매글 삭제
@Transactional(rollbackFor = Exception.class)
public void deleteProduce(Long produceIdx) throws BaseException {
try {
Expand All @@ -147,6 +148,22 @@ public void deleteProduce(Long produceIdx) throws BaseException {
}
}

// [작성자] 판매글 수정 화면 조회
public ProduceEditViewResponse getProduceEditView(Long produceIdx) throws BaseException {
try {
Long userIdx = getUserIdxWithValidation();
Produce produce = produceRepository.findById(produceIdx).orElseThrow(() -> new BaseException(INVALID_PRODUCE_IDX));
if (produce.getStatus().equals(INACTIVE)) throw new BaseException(ALREADY_DELETED_PRODUCE);

return new ProduceEditViewResponse(produce.getTitle(), produce.getContent(), produce.getPrice(), produce.getProduceImage(),
produce.getUser().getNickname(), produce.getUser().getContact(), produce.getUser().getProfileImage());
} catch (BaseException e) {
throw e;
} catch (Exception e) {
throw new BaseException(DATABASE_ERROR);
}
}

private Long getUserIdxWithValidation() throws BaseException {
Long userIdx = authService.getUserIdx();
if (userIdx == null) throw new BaseException(NULL_ACCESS_TOKEN);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.kkobugi.puremarket.produce.domain.dto;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "판매글 수정 화면 조회 응답")
public record ProduceEditViewResponse(@Schema(description = "글 제목", example = "판매글")
String title,
@Schema(description = "글 내용", example = "판매함니다~")
String content,
@Schema(description = "가격", example = "10000")
Integer price,
@Schema(description = "글 이미지 url", example = "https://dwffwdfdwbwv")
String produceImage,
@Schema(description = "닉네임", example = "꼬부기")
String nickname,
@Schema(description = "연락처", example = "01012345678")
String contact,
@Schema(description = "프로필 이미지 url", example = "https://dwffwdfdwbwv")
String profileImage) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.kkobugi.puremarket.common.BaseException;
import com.kkobugi.puremarket.common.BaseResponse;
import com.kkobugi.puremarket.produce.application.ProduceService;
import com.kkobugi.puremarket.produce.domain.dto.ProduceEditViewResponse;
import com.kkobugi.puremarket.produce.domain.dto.ProduceListResponse;
import com.kkobugi.puremarket.produce.domain.dto.ProducePostRequest;
import com.kkobugi.puremarket.produce.domain.dto.ProduceResponse;
Expand Down Expand Up @@ -109,4 +110,15 @@ public BaseResponse<?> deleteProduce(@Parameter(description = "판매글 Idx", i
return new BaseResponse<>(e.getStatus());
}
}

// [작성자] 판매글 수정화면 조회
@GetMapping("/editView/{produceIdx}")
@Operation(summary = "판매글 수정화면 조회", description = "해당 판매글의 원데이터를 조회한다.")
public BaseResponse<ProduceEditViewResponse> getProduceEditView(@Parameter(description = "판매글 Idx", in = ParameterIn.PATH) @PathVariable Long produceIdx) {
try {
return new BaseResponse<>(produceService.getProduceEditView(produceIdx));
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}
}

0 comments on commit be4e226

Please sign in to comment.