diff --git a/build.gradle b/build.gradle index 931edeb..858b8b5 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' + // S3 + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardCommandRes.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardCommandRes.java new file mode 100644 index 0000000..509fe1c --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardCommandRes.java @@ -0,0 +1,13 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.board.dto; + +import kr.hs.dgsw.SOPO_server_v2.domain.board.entity.BoardEntity; + +public record BoardCommandRes ( + Long boardId +) { + public static BoardCommandRes of (BoardEntity board) { + return new BoardCommandRes( + board.getBoardId() + ); + } +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardLoadRes.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardLoadRes.java new file mode 100644 index 0000000..aa34495 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardLoadRes.java @@ -0,0 +1,22 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.board.dto; + +import kr.hs.dgsw.SOPO_server_v2.domain.board.entity.BoardEntity; + +public record BoardLoadRes ( + Long boardId, + String boardTitle, + String boardContent, + Integer boardLikeCount + // List fileUrls, + // Long memberId +){ + public static BoardLoadRes of(BoardEntity board) { + return new BoardLoadRes( + board.getBoardId(), + board.getBoardTitle(), + board.getBoardTitle(), + board.getBoardLikeCount() + //board.getFile() Url을 String 으로 묶어서 받아야 함. + ); + } +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardUpdateReq.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardUpdateReq.java new file mode 100644 index 0000000..4af3686 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/dto/BoardUpdateReq.java @@ -0,0 +1,7 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.board.dto; + +public record BoardUpdateReq( + String boardTitle, + String boardContent +) { +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/entity/BoardEntity.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/entity/BoardEntity.java new file mode 100644 index 0000000..b9bf40c --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/entity/BoardEntity.java @@ -0,0 +1,61 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.board.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import kr.hs.dgsw.SOPO_server_v2.domain.board.dto.BoardUpdateReq; +import kr.hs.dgsw.SOPO_server_v2.domain.file.entity.FileEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +@Getter +@Entity +@Table(name = "tbl_board") +@NoArgsConstructor +@SuperBuilder +public class BoardEntity { + + // 게시물 아이디 + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "board_id") + private Long boardId; + + // 게시물 제목 + @Column(name = "board_title") + private String boardTitle; + + // 게시물 내용 + @Column(name = "board_content") + private String boardContent; + + // 게시물 좋아요 + @Column(name = "board_like_count") + private Integer boardLikeCount = 0; + + // 유저 아이디 + @ManyToOne + @JoinColumn(name = "member_id") // member_id로 참조한다. + private MemberEntity member; + + // 게시물 파일 + @OneToMany(mappedBy = "board", cascade = CascadeType.ALL, orphanRemoval = true) // 읽기만, 게시물 삭제될 때 함께 삭제 + private List file; + + public void update(BoardUpdateReq updateReq) { + this.boardTitle = updateReq.boardTitle(); + this.boardContent = updateReq.boardContent(); + } + +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestCommandRes.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestCommandRes.java new file mode 100644 index 0000000..1b535f2 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestCommandRes.java @@ -0,0 +1,14 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.contest.dto; + +import kr.hs.dgsw.SOPO_server_v2.domain.contest.entity.ContestEntity; + + +public record ContestCommandRes( + Long contestId +) { + public static ContestCommandRes of (ContestEntity contest) { + return new ContestCommandRes( + contest.getContestId() + ); + } +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestLoadRes.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestLoadRes.java new file mode 100644 index 0000000..d02e589 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestLoadRes.java @@ -0,0 +1,28 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.contest.dto; + +import kr.hs.dgsw.SOPO_server_v2.domain.contest.entity.ContestEntity; + +import java.time.LocalDateTime; + +public record ContestLoadRes ( + Long contestId, + String contestTitle, + String contestContent, + Integer contestMax, + Integer contestPerson, + LocalDateTime contestDateTime + // List fileUrls, + // Long memberId +) { + public static ContestLoadRes of(ContestEntity contest) { + return new ContestLoadRes ( + contest.getContestId(), + contest.getContestTitle(), + contest.getContestContent(), + contest.getContestMax(), + contest.getContestPerson(), + contest.getContestDateTime() + //contest.getFile() Url을 String 으로 묶어서 받아야 함. + ); + } +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestUpdateReq.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestUpdateReq.java new file mode 100644 index 0000000..d4dc108 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/dto/ContestUpdateReq.java @@ -0,0 +1,14 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.contest.dto; + +import kr.hs.dgsw.SOPO_server_v2.domain.contest.enums.ContestState; + +import java.time.LocalDateTime; + +public record ContestUpdateReq ( + String contestTitle, + String contestContent, + Integer contestMax, + Integer contestPerson, + LocalDateTime contestDateTime +) { +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/entity/ContestEntity.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/entity/ContestEntity.java new file mode 100644 index 0000000..5dff9c1 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/entity/ContestEntity.java @@ -0,0 +1,83 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.contest.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import kr.hs.dgsw.SOPO_server_v2.domain.contest.dto.ContestUpdateReq; +import kr.hs.dgsw.SOPO_server_v2.domain.contest.enums.ContestState; +import kr.hs.dgsw.SOPO_server_v2.domain.file.entity.FileEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.List; + +@Getter +@Entity +@Table(name = "tbl_contest") +@NoArgsConstructor +@SuperBuilder +public class ContestEntity { + + // 대회 아이디 + @Id + @Column(name = "contest_id") + private Long contestId; + + // 대회 제목 + @Column(name = "contest_title") + private String contestTitle; + + // 대회 내용 + @Column(name = "contest_content") + private String contestContent; + + // 대회 상태 + @Column(name = "contest_state") + @Enumerated(EnumType.STRING) + private ContestState contestState = ContestState.ACTIVE; + + // 대회 정원 + @Column(name = "contest_max") + private Integer contestMax; + + // 대회 인원 + @Column(name = "contest_person") + private Integer contestPerson; + + // 대회 마감일 + @Column(name = "contest_date_time") + private LocalDateTime contestDateTime; + + // 대회 좋아요 + @Column(name = "contest_like_count") + private Integer contestLikeCount = 0; + + // 유저 아이디 + @ManyToOne + @JoinColumn(name = "member_id") + private MemberEntity member; + + // 대회 파일 + @OneToMany(mappedBy = "contest", cascade = CascadeType.ALL, orphanRemoval = true) // 읽기만, 게시물 삭제될 때 함께 삭제 + private List file; + + public void update(ContestUpdateReq updateReq) { + this.contestTitle = updateReq.contestTitle(); + this.contestContent = updateReq.contestContent(); + this.contestMax = updateReq.contestMax(); + this.contestPerson = updateReq.contestPerson(); + this.contestDateTime = updateReq.contestDateTime(); + } +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/enums/ContestState.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/enums/ContestState.java new file mode 100644 index 0000000..cee28d5 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/enums/ContestState.java @@ -0,0 +1,5 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.contest.enums; + +public enum ContestState { + ACTIVE, DISABLED +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/entity/FileEntity.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/entity/FileEntity.java new file mode 100644 index 0000000..65597fd --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/entity/FileEntity.java @@ -0,0 +1,49 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.file.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import kr.hs.dgsw.SOPO_server_v2.domain.board.entity.BoardEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.contest.entity.ContestEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "tbl_file") +@NoArgsConstructor +public class FileEntity { + + // 파일 아이디 + @Id + @Column(name = "file_id") + private Long fileId; + + // 파일 이름 + @Column(name = "file_name") + private String fileName; + + // 파일 url + @Column(name = "file_url") + private String fileUrl; + + // 게시물 아이디 + @ManyToOne + @JoinColumn(name = "board_id") + private BoardEntity board; + + // 대회 아이디 + @ManyToOne + @JoinColumn(name = "contest_id") + private ContestEntity contest; + + // 유저 아이디 + @ManyToOne + @JoinColumn(name = "member_id") + private MemberEntity member; + +}