Skip to content

Commit

Permalink
Merge pull request #13 from 9oormthon-univ/dev
Browse files Browse the repository at this point in the history
token fix
  • Loading branch information
sumin220 authored Nov 21, 2024
2 parents ce2fee3 + 6ae9501 commit b28f62e
Show file tree
Hide file tree
Showing 23 changed files with 660 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package univ.yesummit.domain.board.api.dto.request;

import univ.yesummit.domain.board.domain.Board;
import univ.yesummit.domain.member.entity.Member;

import java.util.List;

public record BoardSaveReqDto(
String title,

String content,
List<String> imageUrl,
String serviceUrl,
String PTUrl
) {
public Board toEntity(Member member) {
return Board.builder()
.title(title)
.content(content)
.writer(member)
.serviceUrl(serviceUrl)
.PTUrl(PTUrl)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package univ.yesummit.domain.board.api.dto.request;

import java.util.List;

public record BoardUpdateReqDto(
String title,
String content,
List<String> newImageUrl,
String serviceUrl,
String PTUrl
) {
}
110 changes: 110 additions & 0 deletions src/main/java/univ/yesummit/domain/board/domain/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package univ.yesummit.domain.board.domain;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import univ.yesummit.domain.board.api.dto.request.BoardUpdateReqDto;
import univ.yesummit.domain.comment.domain.Comment;
import univ.yesummit.domain.member.entity.Member;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Board {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "board_id")
@Schema(description = "피칭 게시글 id", example = "1")
private Long boardId;

// 게시글 써밋 아이디 필드 만들기 (숫자만 저장하는 컬럼)

@Schema(description = "피칭 제목", example = "제목")
@NotNull(message = "필수 입력 항목입니다.")
private String title;

@Schema(description = "피칭 요약", example = "요약")
@Column(columnDefinition = "TEXT")
@NotNull(message = "필수 입력 항목입니다.")
private String content;

@Schema(description = "서비스 웹사이트 혹은 기타 링크(선택)", example = "사이트 링크")
@Column(columnDefinition = "TEXT")
private String serviceUrl;

@Schema(description = "PT 영상 링크", example = "영상 링크")
@Column(columnDefinition = "TEXT")
@NotNull(message = "필수 입력 항목입니다.")
private String PTUrl;

@Schema(description = "게시글 날짜", example = "2024.06.21")
private String boardDate;

@Schema(description = "좋아요 개수", example = "1")
private int likeCount;

@Schema(description = "투자 제안한 횟수", example = "1")
private int investmentCount;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
@Schema(description = "작성자", example = "nickname")
private Member writer;

@OneToMany(mappedBy = "board", orphanRemoval = true, cascade = CascadeType.ALL)
@Schema(description = "이미지")
private List<BoardPicture> pictures = new ArrayList<>();

@OneToMany(mappedBy = "board", orphanRemoval = true, cascade = CascadeType.ALL)
private List<Comment> comments = new ArrayList<>();

@Builder
private Board(String title, String content, String serviceUrl, String PTUrl, Member writer) {
this.title = title;
this.content = content;
this.serviceUrl = serviceUrl;
this.PTUrl = PTUrl;
this.boardDate = String.valueOf(LocalDateTime.now(ZoneId.of("Asia/Seoul")));
this.likeCount = 0;
this.writer = writer;
}


public void boardUpdate(BoardUpdateReqDto boardUpdateReqDto) {
this.title = boardUpdateReqDto.title();
this.content = boardUpdateReqDto.content();
}

public void updateLikeCount() {
this.likeCount++;
}
public void updateInvestmentCount() {
this.investmentCount++;
}

public void cancelLikeCount() {
if (this.likeCount <= 0) {
this.likeCount = 0;
} else {
this.likeCount--;
}
}
public void cancelInvestmentCount() {
if (this.investmentCount <= 0) {
this.investmentCount = 0;
} else {
this.investmentCount--;
}
}

}
34 changes: 34 additions & 0 deletions src/main/java/univ/yesummit/domain/board/domain/BoardLike.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package univ.yesummit.domain.board.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import univ.yesummit.domain.member.entity.Member;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class BoardLike {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "board_like_id")
private Long boardLikeId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "board_id")
private Board board;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@Builder
private BoardLike(Board board, Member member) {
this.board = board;
this.member = member;
}

}
36 changes: 36 additions & 0 deletions src/main/java/univ/yesummit/domain/board/domain/BoardPicture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package univ.yesummit.domain.board.domain;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class BoardPicture {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "board_picture_id")
@Schema(description = "게시글의 사진 id", example = "1")
private Long boardPictureId;

@Schema(description = "게시글 이미지 URL", example = "https://~~")
@NotNull(message = "게시글 이미지 삽입은 필수입니다.")
private String imageUrl;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "board_id")
private Board board;

@Builder
private BoardPicture(String imageUrl, Board board) {
this.imageUrl = imageUrl;
this.board = board;
}

}
34 changes: 34 additions & 0 deletions src/main/java/univ/yesummit/domain/board/domain/Investment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package univ.yesummit.domain.board.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import univ.yesummit.domain.member.entity.Member;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Investment {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "investment_id")
private Long investmentId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "board_id")
private Board board;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@Builder
private Investment(Board board, Member member) {
this.board = board;
this.member = member;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package univ.yesummit.domain.board.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import univ.yesummit.domain.board.domain.Board;
import univ.yesummit.domain.board.domain.BoardLike;
import univ.yesummit.domain.member.entity.Member;

import java.util.List;
import java.util.Optional;

public interface BoardLikeRepository extends JpaRepository<BoardLike, Long> {

boolean existsByBoardAndMember(Board board, Member member);

Optional<BoardLike> findByBoardAndMember(Board board, Member member);

List<BoardLike> findByMember(Member member);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package univ.yesummit.domain.board.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import univ.yesummit.domain.board.domain.Board;
import univ.yesummit.domain.board.domain.BoardPicture;

import java.util.List;

public interface BoardPictureRepository extends JpaRepository<BoardPicture, String> {

void deleteByBoardBoardId(Long boardId);

void deleteByBoardAndImageUrlIn(Board board, List<String> urlsToDelete);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package univ.yesummit.domain.board.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import univ.yesummit.domain.board.domain.Board;


public interface BoardRepository extends JpaRepository<Board, Long> {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package univ.yesummit.domain.board.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import univ.yesummit.domain.board.domain.Board;
import univ.yesummit.domain.board.domain.Investment;
import univ.yesummit.domain.member.entity.Member;

import java.util.Optional;


public interface InvestmentRepository extends JpaRepository<Investment, Long> {

boolean existsByBoardAndMember(Board board, Member member);

Optional<Investment> findByBoardAndMember(Board board, Member member);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package univ.yesummit.domain.comment.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 lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import univ.yesummit.domain.comment.api.dto.request.CommentSaveReqDto;
import univ.yesummit.domain.comment.api.dto.request.CommentUpdateReqDto;
import univ.yesummit.domain.comment.application.CommentService;

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/api/comment")
public class CommentController {

private final CommentService commentService;

@Operation(summary = "댓글 등록", description = "댓글을 등록합니다.")
@ApiResponse(responseCode = "200", description = "댓글 등록 성공")
@ApiResponse(responseCode = "401", description = "인증 실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN")))
@PostMapping("/")
public ResponseEntity<String> commentSave(@AuthenticationPrincipal String email,
@RequestBody CommentSaveReqDto commentSaveReqDto) {

commentService.commentSave(email, commentSaveReqDto);

String responseMessage = String.format("%d 게시글에 댓글이 등록되었습니다.", commentSaveReqDto.boardId());
return ResponseEntity.status(HttpStatus.CREATED).body(responseMessage);
}

@Operation(summary = "댓글 수정", description = "댓글을 수정합니다.")
@ApiResponse(responseCode = "200", description = "댓글 수정 성공")
@ApiResponse(responseCode = "401", description = "인증 실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN")))
@PutMapping("/{commentId}")
public ResponseEntity<String> commentUpdate(@AuthenticationPrincipal String email,
@PathVariable("commentId") Long commentId,
@RequestBody CommentUpdateReqDto commentUpdateReqDto) {

commentService.commentUpdate(email, commentId, commentUpdateReqDto);

String responseMessage = String.format("%d 게시글의 댓글이 수정돠었습니다.", commentId);
return ResponseEntity.status(HttpStatus.OK).body(responseMessage);
}

@Operation(summary = "댓글 삭제", description = "댓글을 삭제합니다.")
@ApiResponse(responseCode = "200", description = "댓글 삭제 성공")
@ApiResponse(responseCode = "401", description = "인증 실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN")))
@DeleteMapping("/{commentId}")
public ResponseEntity<String> commentDelete(@AuthenticationPrincipal String email,
@PathVariable("commentId") Long commentId) {
commentService.commentDelete(email, commentId);

String responseMessage = String.format("%d 게시글의 댓글이 삭제되었습니다.", commentId);
return ResponseEntity.status(HttpStatus.OK).body(responseMessage);
}
}
Loading

0 comments on commit b28f62e

Please sign in to comment.