Skip to content

Commit

Permalink
[#40]✨Feat: 투자자 구분 엔드포인트 지정
Browse files Browse the repository at this point in the history
  • Loading branch information
sumin220 committed Nov 23, 2024
1 parent 00162d3 commit 4f73abe
Showing 1 changed file with 70 additions and 46 deletions.
116 changes: 70 additions & 46 deletions src/main/java/univ/yesummit/domain/board/api/InvestmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -21,62 +22,85 @@

@RestController
@RequestMapping("/v1/api/board/investment")
@RequiredArgsConstructor
public class InvestmentController {
private final BoardRepository boardRepository;
private final MemberRepository memberRepository;

private final InvestmentService investmentService;

public InvestmentController(BoardRepository boardRepository, MemberRepository memberRepository, InvestmentService investmentService) {
this.boardRepository = boardRepository;
this.memberRepository = memberRepository;
this.investmentService = investmentService;
}
@Operation(summary = "투자 제안하기", description = "투자 제안을 등록합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "투자 제안하기 성공"),
@ApiResponse(responseCode = "401", description = "인증실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))),
@ApiResponse(responseCode = "404", description = "게시글 또는 회원을 찾을 수 없음", content = @Content(schema = @Schema(example = "BOARD_NOT_FOUND or MEMBER_NOT_FOUND"))),
})
@PostMapping(value = "/invest", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<String> addBoardLike(@User LoginUser loginUser, @RequestParam Long boardId) {
Member member = memberRepository.findById(loginUser.getMemberId())
.orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다."));
Board board = boardRepository.findById(boardId)
.orElseThrow(() -> new IllegalArgumentException("게시글을 찾을 수 없습니다."));
@Operation(summary = "투자 제안하기", description = "특정 게시글에 투자 제안을 등록합니다.")
@PostMapping("/{boardId}")
public ResponseEntity<String> addInvestment(
@User LoginUser loginUser,
@PathVariable Long boardId) {

investmentService.addInvestment(loginUser.getMemberId(), board);
return ResponseEntity.ok("투자 제안하기");
investmentService.addInvestment(loginUser.getMemberId(), boardId);
return ResponseEntity.ok("investment ok");
}

@Operation(summary = "투자 제안하기 취소", description = "투자 제안을 취소합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "투자 제안하기 취소 성공"),
@ApiResponse(responseCode = "401", description = "인증실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))),
@ApiResponse(responseCode = "404", description = "게시글 또는 회원을 찾을 수 없음", content = @Content(schema = @Schema(example = "BOARD_NOT_FOUND or MEMBER_NOT_FOUND"))),
})
@PostMapping(value = "/cancel", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<String> cancelBoardLike(@User LoginUser loginUser, @RequestParam Long boardId) {
Member member = memberRepository.findById(loginUser.getMemberId())
.orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다."));
Board board = boardRepository.findById(boardId)
.orElseThrow(() -> new IllegalArgumentException("게시글을 찾을 수 없습니다."));
@Operation(summary = "투자 제안 취소", description = "특정 게시글의 투자 제안을 취소합니다.")
@DeleteMapping("/{boardId}")
public ResponseEntity<String> cancelInvestment(
@User LoginUser loginUser,
@PathVariable Long boardId) {

investmentService.cancelInvestment(loginUser.getMemberId(), board);
return ResponseEntity.ok("투자 제안하기 취소");
investmentService.cancelInvestment(loginUser.getMemberId(), boardId);
return ResponseEntity.ok("cancel investment ok");
}

@Operation(summary = "내가 받은 투자 제안 조회", description = "내가 받은 투자 제안을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "내가 받은 투자 제안 조회 성공"),
@ApiResponse(responseCode = "401", description = "인증실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))),
@ApiResponse(responseCode = "404", description = "게시글 또는 회원을 찾을 수 없음", content = @Content(schema = @Schema(example = "BOARD_NOT_FOUND or MEMBER_NOT_FOUND"))),
})
@GetMapping("/get-investment")
public ResponseEntity<List<InvestmentResDto>> getAllInvestment(@User LoginUser loginUser, @RequestParam Long boardId) {
List<InvestmentResDto> investments = investmentService.getAllInvestment(loginUser.getMemberId(), boardId);
@Operation(summary = "내가 투자한 게시글 조회", description = "특정 사용자가 투자한 게시글 리스트를 조회합니다.")
@GetMapping("/my-investments")
public ResponseEntity<List<InvestmentResDto>> getMyInvestments(@User LoginUser loginUser) {
List<InvestmentResDto> investments = investmentService.getInvestedBoardsWithDetailsByMember(loginUser.getMemberId());
return ResponseEntity.ok(investments);
}


}

//
// @Operation(summary = "투자 제안하기", description = "투자 제안을 등록합니다.")
// @ApiResponses(value = {
// @ApiResponse(responseCode = "200", description = "투자 제안하기 성공"),
// @ApiResponse(responseCode = "401", description = "인증실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))),
// @ApiResponse(responseCode = "404", description = "게시글 또는 회원을 찾을 수 없음", content = @Content(schema = @Schema(example = "BOARD_NOT_FOUND or MEMBER_NOT_FOUND"))),
// })
// @PostMapping(value = "/invest", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
// public ResponseEntity<String> addBoardLike(@User LoginUser loginUser, @RequestParam Long boardId) {
// Member member = memberRepository.findById(loginUser.getMemberId())
// .orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다."));
// Board board = boardRepository.findById(boardId)
// .orElseThrow(() -> new IllegalArgumentException("게시글을 찾을 수 없습니다."));
//
// investmentService.addInvestment(loginUser.getMemberId(), board);
// return ResponseEntity.ok("투자 제안하기");
// }
//
// @Operation(summary = "투자 제안하기 취소", description = "투자 제안을 취소합니다.")
// @ApiResponses(value = {
// @ApiResponse(responseCode = "200", description = "투자 제안하기 취소 성공"),
// @ApiResponse(responseCode = "401", description = "인증실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))),
// @ApiResponse(responseCode = "404", description = "게시글 또는 회원을 찾을 수 없음", content = @Content(schema = @Schema(example = "BOARD_NOT_FOUND or MEMBER_NOT_FOUND"))),
// })
// @PostMapping(value = "/cancel", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
// public ResponseEntity<String> cancelBoardLike(@User LoginUser loginUser, @RequestParam Long boardId) {
// Member member = memberRepository.findById(loginUser.getMemberId())
// .orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다."));
// Board board = boardRepository.findById(boardId)
// .orElseThrow(() -> new IllegalArgumentException("게시글을 찾을 수 없습니다."));
//
// investmentService.cancelInvestment(loginUser.getMemberId(), board);
// return ResponseEntity.ok("투자 제안하기 취소");
// }
//
// @Operation(summary = "내가 받은 투자 제안 조회", description = "내가 받은 투자 제안을 조회합니다.")
// @ApiResponses(value = {
// @ApiResponse(responseCode = "200", description = "내가 받은 투자 제안 조회 성공"),
// @ApiResponse(responseCode = "401", description = "인증실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))),
// @ApiResponse(responseCode = "404", description = "게시글 또는 회원을 찾을 수 없음", content = @Content(schema = @Schema(example = "BOARD_NOT_FOUND or MEMBER_NOT_FOUND"))),
// })
// @GetMapping("/get-investment")
// public ResponseEntity<List<InvestmentResDto>> getAllInvestment(@User LoginUser loginUser, @RequestParam Long boardId) {
// List<InvestmentResDto> investments = investmentService.getAllInvestment(loginUser.getMemberId(), boardId);
// return ResponseEntity.ok(investments);
// }
//
//}

0 comments on commit 4f73abe

Please sign in to comment.