Skip to content

Commit

Permalink
Merge pull request #47 from 9oormthon-univ/dev
Browse files Browse the repository at this point in the history
내가 받은 투자 보기 API 구현
  • Loading branch information
sumin220 authored Nov 23, 2024
2 parents 5dbc3fc + e32a76b commit dee4e4f
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 144 deletions.
24 changes: 18 additions & 6 deletions src/main/java/univ/yesummit/domain/board/api/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
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.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import univ.yesummit.domain.board.api.dto.request.BoardSaveReqDto;
import univ.yesummit.domain.board.api.dto.request.BoardUpdateReqDto;
import univ.yesummit.domain.board.api.dto.response.BoardInfoResDto;
Expand All @@ -21,12 +21,13 @@
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/api/board")
public class BoardController {
private final BoardService boardService;
public BoardController(BoardService boardService) {
this.boardService = boardService;
}
private Logger log;



@Operation(summary = "PT 영상 및 정보 등록", description = "PT 영상 및 정보를 등록합니다.")
@ApiResponses(value = {
Expand All @@ -35,12 +36,23 @@ public BoardController(BoardService boardService) {
})
@PostMapping("/summit/{summitId}")
public ResponseEntity<String> boardSave(@User LoginUser loginUser,
@PathVariable Long summitId,
@RequestBody BoardSaveReqDto boardSaveReqDto) {
Long boardId = boardService.boardSave(loginUser.getMemberId(), boardSaveReqDto);
BoardSaveReqDto updatedBoardSaveReqDto = new BoardSaveReqDto(
boardSaveReqDto.title(),
boardSaveReqDto.content(),
boardSaveReqDto.imageUrl(),
boardSaveReqDto.serviceUrl(),
boardSaveReqDto.PTUrl(),
summitId
);

Long boardId = boardService.boardSave(loginUser.getMemberId(), updatedBoardSaveReqDto);
String message = String.format("%d번 게시글 등록!", boardId);
return new ResponseEntity<>(message, HttpStatus.CREATED);
}


@Operation(summary = "주제별 PT 영상 게시글 조회", description = "주제별 PT 영상 게시글을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회 성공"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package univ.yesummit.domain.board.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
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.*;
import univ.yesummit.domain.board.api.dto.response.InvestmentReceivedResDto;
import univ.yesummit.domain.board.api.dto.response.InvestmentResDto;
import univ.yesummit.domain.board.application.InvestmentService;
import univ.yesummit.domain.board.domain.Board;
import univ.yesummit.domain.board.domain.repository.BoardRepository;
import univ.yesummit.domain.member.entity.Member;
import univ.yesummit.domain.member.repository.MemberRepository;
import univ.yesummit.global.resolver.LoginUser;
import univ.yesummit.global.resolver.User;

Expand Down Expand Up @@ -53,54 +45,11 @@ public ResponseEntity<List<InvestmentResDto>> getMyInvestments(@User LoginUser l
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);
// }
//
//}

@Operation(summary = "내가 받은 투자 보기", description = "")
@GetMapping("/received-list")
public ResponseEntity<List<InvestmentReceivedResDto>> getReceivedInvestments(@User LoginUser loginUser) {
List<InvestmentReceivedResDto> investments = investmentService.getReceivedInvestments(loginUser.getMemberId());
return ResponseEntity.ok(investments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public record BoardSaveReqDto(
String content,
List<String> imageUrl,
String serviceUrl,
String PTUrl
String PTUrl,
Long summitId

) {
public Board toEntity(Member member) {
List<String> images = (imageUrl == null) ? new ArrayList<>() : imageUrl;
Expand All @@ -30,6 +32,7 @@ public Board toEntity(Member member) {
.pictures(boardPictures)
.serviceUrl(serviceUrl)
.PTUrl(PTUrl)
.summitId(summitId)
.writer(member)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package univ.yesummit.domain.board.api.dto.response;

import lombok.Builder;

@Builder
public record InvestmentReceivedResDto(
Long boardId, // 게시글 ID
String boardTitle, // 게시글 제목
Long investorId, // 투자자 ID
String investorName, // 투자자 이름
String investorEmail, // 투자자 이메일
String investorPhoneNumber, //투자자 휴대폰번호
String investorPosition
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public class BoardService {
// 게시글 저장
@Transactional
public Long boardSave(Long memberId, BoardSaveReqDto boardSaveReqDto) {
log.info("Received BoardSaveReqDto: {}", boardSaveReqDto);
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다. " + memberId));

Board board = boardSaveReqDto.toEntity(member);
log.info("Board object created: {}", board);

List<Feed> feeds = getFeedsByMember(member);
boardImageSave(board, boardSaveReqDto.imageUrl(), feeds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import univ.yesummit.domain.board.api.dto.response.InvestmentReceivedResDto;
import univ.yesummit.domain.board.api.dto.response.InvestmentResDto;
import univ.yesummit.domain.board.domain.Board;
import univ.yesummit.domain.board.domain.Investment;
Expand Down Expand Up @@ -78,81 +79,28 @@ public List<InvestmentResDto> getInvestedBoardsWithDetailsByMember(Long memberId
})
.collect(Collectors.toList());
}
}
//@Service
//@RequiredArgsConstructor
//@Transactional(readOnly = true)
//public class InvestmentService {
//
// private final MemberRepository memberRepository;
// private final BoardRepository boardRepository;
// private final InvestmentRepository investmentRepository;
//
//
// // 투자하기 버튼 클릭
// @Transactional
// public void addInvestment(Long memberId, Board boardId) {
// Member member = memberRepository.findById(memberId)
// .orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다."));
//
// Board board = boardRepository.findById(boardId.getBoardId())
// .orElseThrow(() -> new IllegalArgumentException("게시글이 존재하지 않습니다."));
//
// if (!investmentRepository.existsByBoardAndMember(board, member)) {
// throw new IllegalStateException("이미 투자 제안 중입니다.");
// }
//
// board.updateInvestmentCount();
// investmentRepository.save(Investment.builder()
// .board(board)
// .member(member)
// .build());
// }
//
// // 투자하기 취소
// @Transactional
// public void cancelInvestment(Long memberId, Board boardId) {
//
// Member member = memberRepository.findById(memberId)
// .orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다."));
//
// Board board = boardRepository.findById(boardId.getBoardId())
// .orElseThrow(() -> new IllegalArgumentException("게시글이 존재하지 않습니다."));
//
// if (!investmentRepository.existsByBoardAndMember(board, member)) {
// throw new IllegalStateException("투자 제안 중이 아닙니다.");
// }
//
// Investment investment = investmentRepository.findByBoardAndMember(board, member)
// .orElseThrow(() -> new IllegalArgumentException("좋아요 정보가 없습니다."));
//
// board.cancelInvestmentCount();
// investmentRepository.delete(investment);
// }
//
// @Transactional
// public List<InvestmentResDto> getAllInvestment(Long memberId, Long boardId) {
// Member member = memberRepository.findById(memberId)
// .orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다."));
//
// Board board = boardRepository.findById(boardId)
// .orElseThrow(() -> new IllegalArgumentException("게시글이 존재하지 않습니다."));
//
// // 해당 게시글에 대한 모든 투자 제안 조회
// List<Investment> investments = investmentRepository.findByBoard(board);
// return investments.stream()
// .map(investment -> {
// Member investor = investment.getMember(); // 투자자 정보 가져오기
// return new InvestmentResDto(
// investor.getId(),
// investor.getUsername(),
// investor.getPosition(),
// investor.getPhoneNumber(),
// investor.getEmail(),
// boardId
// );
// })
// .collect(Collectors.toList());
// }
//
//}

// 내가 투자받은 투자자 목록 조회
public List<InvestmentReceivedResDto> getReceivedInvestments(Long memberId) {
// 작성한 게시글에 대한 투자 기록 조회
List<Investment> investments = investmentRepository.findAllByBoardWriterId(memberId);

// 투자 정보를 DTO로 변환
return investments.stream()
.map(investment -> {
Member investor = investment.getMember(); // 투자자 정보
Board board = investment.getBoard(); // 게시글 정보

return InvestmentReceivedResDto.builder()
.boardId(board.getBoardId())
.boardTitle(board.getTitle())
.investorId(investor.getId())
.investorName(investor.getUsername())
.investorEmail(investor.getEmail())
.investorPhoneNumber(investor.getPhoneNumber())
.investorPosition(investor.getPosition())
.build();
})
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@

public interface BoardRepository extends JpaRepository<Board, Long> {
Optional<Board> findFirstByWriter(Member member);
List<Board> findByWriter(Member member);

List<Board> findBySummitId(Long summitId);

List<Board> findAllByBoardIdIn(List<Long> boardIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public interface InvestmentRepository extends JpaRepository<Investment, Long> {
Optional<Investment> findByBoardAndMember(Board board, Member member);

List<Investment> findByMember(Member member);

List<Investment> findByBoard(Board board);

// 게시글 작성자 ID로 투자 조회
List<Investment> findAllByBoardWriterId(Long writerId);
}

0 comments on commit dee4e4f

Please sign in to comment.