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

Refactor/#36/create funding #39

Merged
merged 2 commits into from
Jul 15, 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
20 changes: 7 additions & 13 deletions src/main/java/com/habday/server/controller/FundingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

import com.habday.server.classes.Common;
import com.habday.server.classes.implemented.HostedList;
import com.habday.server.classes.implemented.ParticipatedList;
import com.habday.server.config.S3Uploader;
import com.habday.server.domain.fundingItem.FundingItem;
import com.habday.server.domain.member.Member;
import com.habday.server.dto.req.fund.ConfirmationRequest;
import com.habday.server.dto.req.fund.ParticipateFundingRequest;
import com.habday.server.dto.CommonResponse;
import com.habday.server.dto.res.DeleteFundingItemResponse;
import com.habday.server.dto.res.fund.*;
import com.habday.server.exception.CustomException;
import com.habday.server.service.FundingService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Optional;

import static com.habday.server.constants.code.ExceptionCode.FAIL_UPLOADING_IMG;
import static com.habday.server.constants.code.ExceptionCode.NO_MEMBER_ID;
import static com.habday.server.constants.code.ExceptionCode.*;
import static com.habday.server.constants.code.SuccessCode.*;

//펀딩 생성, 참여, 삭제, 조회 등 모든 펀딩 로직이 들어가는 부분(추후에 필요할 시 컨트롤러 나눌 예정
Expand Down Expand Up @@ -100,9 +94,9 @@ public ResponseEntity<CommonResponse> getParticipatedList(@RequestParam @NotNull
// 펀딩 수정

// 펀딩 식제
/*@DeleteMapping("/delete/fundingItem/{fundingItemId}")
public ResponseEntity<CommonResponse> deleteFundingItem(@PathVariable("fundingItemId") Long fundingItemId) {
FundingItem fundingItem = fundingItemRepository.deleteById(fundingItemId);
return CommonResponse.toResponse(DELETE_FUNDING_ITEM_SUCCESS);
}*/
@GetMapping("/delete/{fundingItemId}")
public ResponseEntity<DeleteFundingItemResponse> deleteFundingItem(@PathVariable("fundingItemId") Long fundingItemId) {
fundingService.deleteFundingItem(fundingItemId);
return DeleteFundingItemResponse.newResponse(DELETE_FUNDING_ITEM_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package com.habday.server.dto.res;

public class DeleteFundingItemResponse {
import com.habday.server.constants.code.SuccessCode;
import com.habday.server.dto.BaseResponse;
import org.springframework.http.ResponseEntity;

public class DeleteFundingItemResponse extends BaseResponse {
private DeleteFundingItemResponse(Boolean success, String msg) {
super(success, msg);
}

public static ResponseEntity<DeleteFundingItemResponse> newResponse(SuccessCode code) {
return new ResponseEntity(DeleteFundingItemResponse.of(true, code.getMsg()), code.getStatus());
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/habday/server/service/FundingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,9 @@ public void confirm(MultipartFile img, ConfirmationRequest request, Long memberI
throw new CustomException(FAIL_UPLOADING_IMG);
}
}

public void deleteFundingItem(Long fundingItemId) {
fundingItemRepository.delete(fundingItemRepository.findById(fundingItemId)
.orElseThrow(() -> new CustomException(NO_FUNDING_ITEM_ID)));
}
}