diff --git a/Dockerfile b/Dockerfile index 9e2b5dd..51e51db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,11 @@ +<<<<<<< HEAD +ARG JAR_FILE=build/libs/*.jar +COPY ${JAR_FILE} sopo-2.0.0.jar +ENV TZ=Asia/Seoul +ENTRYPOINT ["java","-jar","/sopo-2.0.0.jar","-Duser.timezone=Asia/Seoul"] +======= FROM openjdk:17 ARG JAR_FILE=build/libs/SOPO_server_v2-0.0.2-SNAPSHOT.jar COPY ${JAR_FILE} sopo.jar -ENTRYPOINT ["java","-jar","/sopo.jar"] \ No newline at end of file +ENTRYPOINT ["java","-jar","/sopo.jar"] +>>>>>>> 12f73049a4d31fff0df65fbbc7b5fa5b6e7dd993 diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/SopoServerV2Application.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/SopoServerV2Application.java index 50bc048..494099a 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/SopoServerV2Application.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/SopoServerV2Application.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication +@EnableJpaAuditing public class SopoServerV2Application { public static void main(String[] args) { diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/controller/BoardController.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/controller/BoardController.java index 373cc77..01c05fa 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/controller/BoardController.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/controller/BoardController.java @@ -3,14 +3,19 @@ import kr.hs.dgsw.SOPO_server_v2.domain.board.dto.BoardLoadRes; import kr.hs.dgsw.SOPO_server_v2.domain.board.dto.BoardUpdateReq; import kr.hs.dgsw.SOPO_server_v2.domain.board.service.BoardService; +import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; import kr.hs.dgsw.SOPO_server_v2.global.response.Response; import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; + import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -22,8 +27,8 @@ public class BoardController { private final BoardService boardService; @GetMapping("/all") - public ResponseData> getBoards() { - return boardService.getBoards(); + public ResponseData> getBoards(@ModelAttribute PageRequest pageRequest) { + return boardService.getBoards(pageRequest); } @PostMapping @@ -32,18 +37,21 @@ public ResponseData createBoard() { } @GetMapping - public ResponseData getBoard(Long boardId) { + public ResponseData getBoard(@RequestParam Long boardId) { return boardService.findOneBoard(boardId); } @PatchMapping - public Response loadBoard(Long boardId, BoardUpdateReq updateReq) { - return boardService.loadBoard(boardId, updateReq); + public Response updateBoard( + @RequestParam Long boardId, + @RequestBody BoardUpdateReq updateReq + ) { + return boardService.updateBoard(boardId, updateReq); } @DeleteMapping - public Response deleteBoard(Long boardId) { + public Response deleteBoard(@RequestParam Long boardId) { return boardService.deleteBoard(boardId); } -} +} \ No newline at end of file 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 index aa34495..2e7dc03 100644 --- 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 @@ -2,21 +2,21 @@ 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 + Integer boardLikeCount, + String memberName ){ public static BoardLoadRes of(BoardEntity board) { return new BoardLoadRes( board.getBoardId(), board.getBoardTitle(), board.getBoardTitle(), - board.getBoardLikeCount() - //board.getFile() Url을 String 으로 묶어서 받아야 함. + board.getBoardLikeCount(), + board.getMember().getMemberName() ); } -} +} \ No newline at end of file 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 index 4af3686..53c42e0 100644 --- 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 @@ -4,4 +4,4 @@ public record BoardUpdateReq( String boardTitle, String boardContent ) { -} +} \ No newline at end of file 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 index b413047..89847c8 100644 --- 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 @@ -16,6 +16,7 @@ import kr.hs.dgsw.SOPO_server_v2.global.common.entity.BaseTimeEntity; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.experimental.SuperBuilder; import java.util.List; @@ -24,6 +25,7 @@ @Entity @Table(name = "tbl_board") @NoArgsConstructor +@Setter @SuperBuilder public class BoardEntity extends BaseTimeEntity { @@ -62,4 +64,4 @@ public void update(BoardUpdateReq updateReq) { public void likeUpdate(int boardLikeCount) { this.boardLikeCount += boardLikeCount; } -} +} \ No newline at end of file diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/service/BoardService.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/service/BoardService.java index af45ad0..00da9bf 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/service/BoardService.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/board/service/BoardService.java @@ -10,6 +10,7 @@ import kr.hs.dgsw.SOPO_server_v2.global.error.custom.board.BoardNotFound; import kr.hs.dgsw.SOPO_server_v2.global.error.custom.member.MemberNotCoincideException; import kr.hs.dgsw.SOPO_server_v2.global.infra.security.GetCurrentMember; +import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; import kr.hs.dgsw.SOPO_server_v2.global.response.Response; import lombok.RequiredArgsConstructor; @@ -17,6 +18,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.stream.Collectors; @Service @Transactional @@ -27,11 +29,14 @@ public class BoardService { private final GetCurrentMember getCurrentMember; // 게시글 전체 조회 - public ResponseData> getBoards() { + public ResponseData> getBoards(PageRequest pageRequest) { List boardList = boardRepository.findAll(); - List boardLoadResList = boardList.stream().map( - BoardLoadRes::of - ).toList(); + + List boardLoadResList = boardList.stream() + .map(BoardLoadRes::of) + .skip((pageRequest.page() -1) * pageRequest.size()) + .limit(pageRequest.size()) + .collect(Collectors.toList()); return ResponseData.of(HttpStatus.OK, "게시물 전체 조회 완료", boardLoadResList); } @@ -43,15 +48,18 @@ public ResponseData createBoard() { BoardEntity board = BoardEntity.builder() .boardTitle(null) .boardContent(null) + .boardLikeCount(0) .file(null) .member(curMember) .build(); + boardRepository.save(board); + return ResponseData.of(HttpStatus.OK, "빈 게시물 생성 완료", board.getBoardId()); } // 게시글 업데이트 - public Response loadBoard(Long boardId, BoardUpdateReq updateReq) { + public Response updateBoard(Long boardId, BoardUpdateReq updateReq) { MemberEntity curMember = getCurrentMember.current(); BoardEntity board = boardRepository.findById(boardId) @@ -63,6 +71,7 @@ public Response loadBoard(Long boardId, BoardUpdateReq updateReq) { } board.update(updateReq); + return Response.of(HttpStatus.OK, "게시물 업데이트 완료"); } diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/controller/ContestController.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/controller/ContestController.java index d44b80c..eb4109f 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/controller/ContestController.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/controller/ContestController.java @@ -3,6 +3,7 @@ import kr.hs.dgsw.SOPO_server_v2.domain.contest.dto.ContestLoadRes; import kr.hs.dgsw.SOPO_server_v2.domain.contest.dto.ContestUpdateReq; import kr.hs.dgsw.SOPO_server_v2.domain.contest.service.ContestService; +import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; import kr.hs.dgsw.SOPO_server_v2.global.response.Response; import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; import lombok.RequiredArgsConstructor; @@ -10,7 +11,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -22,8 +25,8 @@ public class ContestController { private final ContestService contestService; @GetMapping("/all") - public ResponseData> getContests() { - return contestService.getContests(); + public ResponseData> getContests(PageRequest pageRequest) { + return contestService.getContests(pageRequest); } @PostMapping @@ -32,22 +35,22 @@ public ResponseData createContest() { } @GetMapping - public ResponseData getContest(Long contestId) { + public ResponseData getContest(@RequestParam Long contestId) { return contestService.findOneContest(contestId); } @PatchMapping - public Response loadContest(Long contestId, ContestUpdateReq updateReq) { - return contestService.loadContest(contestId, updateReq); + public Response updateContest(@RequestParam Long contestId, @RequestBody ContestUpdateReq updateReq) { + return contestService.updateContest(contestId, updateReq); } @DeleteMapping - public Response deleteContest(Long contestId) { + public Response deleteContest(@RequestParam Long contestId) { return contestService.deleteContest(contestId); } @PatchMapping("/state") - public Response changeContestState(Long contestId) { + public Response changeContestState(@RequestParam Long contestId) { return contestService.changeContestState(contestId); } -} +} \ No newline at end of file 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 index d02e589..88050b4 100644 --- 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 @@ -1,8 +1,11 @@ package kr.hs.dgsw.SOPO_server_v2.domain.contest.dto; import kr.hs.dgsw.SOPO_server_v2.domain.contest.entity.ContestEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity; import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; public record ContestLoadRes ( Long contestId, @@ -10,19 +13,27 @@ public record ContestLoadRes ( String contestContent, Integer contestMax, Integer contestPerson, - LocalDateTime contestDateTime - // List fileUrls, - // Long memberId + LocalDateTime contestDateTime, + String memberName, + List memberIdList ) { public static ContestLoadRes of(ContestEntity contest) { + List memberIdList = contest.getMemberIdList().stream() + .map(MemberEntity::getMemberId) + .collect(Collectors.toList()); + + // 대회 생성자의 이름 가져오기 + String memberName = contest.getMember().getMemberName(); + return new ContestLoadRes ( contest.getContestId(), contest.getContestTitle(), contest.getContestContent(), contest.getContestMax(), contest.getContestPerson(), - contest.getContestDateTime() - //contest.getFile() Url을 String 으로 묶어서 받아야 함. + contest.getContestDateTime(), + memberName, + memberIdList ); } } 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 index d4dc108..0361784 100644 --- 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 @@ -1,7 +1,5 @@ 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 ( 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 index 6aee5b3..c340200 100644 --- 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 @@ -5,8 +5,11 @@ import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; @@ -17,23 +20,24 @@ import kr.hs.dgsw.SOPO_server_v2.global.common.entity.BaseTimeEntity; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.experimental.SuperBuilder; -import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.Date; import java.util.List; @Getter +@Setter @Entity @Table(name = "tbl_contest") @NoArgsConstructor @SuperBuilder -public class ContestEntity extends BaseTimeEntity { +public class ContestEntity extends BaseTimeEntity { // board, contest 에 유저 이름이랑 아이디 같이 보내주기 // 대회 아이디 @Id @Column(name = "contest_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long contestId; // 대회 제목 @@ -74,6 +78,12 @@ public class ContestEntity extends BaseTimeEntity { @OneToMany(mappedBy = "contest", cascade = CascadeType.ALL, orphanRemoval = true) // 읽기만, 게시물 삭제될 때 함께 삭제 private List file; + // 대회 유저 이름 + @ManyToMany + @JoinColumn(name = "member_id_list") + private List memberIdList; + + public void update(ContestUpdateReq updateReq) { this.contestTitle = updateReq.contestTitle(); this.contestContent = updateReq.contestContent(); @@ -86,6 +96,14 @@ public void likeUpdate(int contestLikeCount) { this.contestLikeCount += contestLikeCount; } + public void addContestPerson(int contestPerson) { + this.contestPerson += contestPerson; + } + + public void addAllowMember(MemberEntity member) { + this.memberIdList.add(member); + } + public void stateUpdateActive() { this.contestState = ContestState.ACTIVE; } @@ -93,4 +111,4 @@ public void stateUpdateActive() { public void stateUpdateDisabled() { this.contestState = ContestState.DISABLED; } -} +} \ No newline at end of file diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/service/ContestService.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/service/ContestService.java index 152d46f..5036c72 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/service/ContestService.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/contest/service/ContestService.java @@ -11,6 +11,7 @@ import kr.hs.dgsw.SOPO_server_v2.global.error.custom.contest.ContestNotFound; import kr.hs.dgsw.SOPO_server_v2.global.error.custom.member.MemberNotCoincideException; import kr.hs.dgsw.SOPO_server_v2.global.infra.security.GetCurrentMember; +import kr.hs.dgsw.SOPO_server_v2.global.page.PageRequest; import kr.hs.dgsw.SOPO_server_v2.global.response.Response; import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; import lombok.RequiredArgsConstructor; @@ -18,35 +19,52 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.stream.Collectors; @Service @Transactional @RequiredArgsConstructor -public class ContestService { // 대회 전환 필요 -> ACTIVE +public class ContestService { + private final ContestRepository contestRepository; private final GetCurrentMember getCurrentMember; + // 대회 전체 조회 - public ResponseData> getContests() { + public ResponseData> getContests(PageRequest pageRequest) { List contestList = contestRepository.findAll(); - List contestLoadRes = contestList.stream().map( - ContestLoadRes :: of - ).toList(); + + List contestLoadRes = contestList.stream() + .map(ContestLoadRes::of) + .skip((pageRequest.page() -1) * pageRequest.size()) + .limit(pageRequest.size()) + .collect(Collectors.toList()); return ResponseData.of(HttpStatus.OK, "대회 전체 조회 완료", contestLoadRes); } // 빈 대회 생성 public ResponseData createContest() { - MemberEntity curMember = getCurrentMember.current(); + ContestEntity contest = ContestEntity.builder() + .contestMax(0) + .contestContent(null) + .contestPerson(0) + .contestState(ContestState.ACTIVE) + .contestLikeCount(0) + .contestDateTime(null) + .memberIdList(null) + .file(null) .member(curMember) .build(); + + contestRepository.save(contest); + return ResponseData.of(HttpStatus.OK, "대회 생성 완료", contest.getContestId()); } // 대회 업데이트 - public Response loadContest(Long contestId, ContestUpdateReq updateReq) { + public Response updateContest(Long contestId, ContestUpdateReq updateReq) { MemberEntity curMember = getCurrentMember.current(); @@ -111,4 +129,4 @@ public Response changeContestState(Long contestId) { return Response.of(HttpStatus.OK, "대회 상태 변경 성공!"); } -} +} \ No newline at end of file diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/controller/EnrollController.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/controller/EnrollController.java new file mode 100644 index 0000000..a7d6800 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/controller/EnrollController.java @@ -0,0 +1,41 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.enroll.controller; + +import kr.hs.dgsw.SOPO_server_v2.domain.enroll.service.EnrollService; +import kr.hs.dgsw.SOPO_server_v2.global.response.Response; +import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/enroll") +@RequiredArgsConstructor +public class EnrollController { + private final EnrollService enrollService; + + @PatchMapping + public Response patch(@RequestParam Long contestId){ + return enrollService.toggle(contestId); + } + + @GetMapping + public ResponseData> showEnrollPeople(@RequestParam Long contestId) { + return enrollService.showEnrollPeople(contestId); + } + + @DeleteMapping("/allow") + public Response allowContest(@RequestParam Long contestId, @RequestParam String memberId) { + return enrollService.allowContest(contestId, memberId); + } + + @DeleteMapping("/refuse") + public Response refuseContest(@RequestParam Long contestId, @RequestParam String memberId) { + return enrollService.refuseContest(contestId, memberId); + } +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/entity/EnrollEntity.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/entity/EnrollEntity.java new file mode 100644 index 0000000..4630259 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/entity/EnrollEntity.java @@ -0,0 +1,37 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.enroll.entity; + +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.Table; +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; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +@Entity +@SuperBuilder +@Getter +@Setter +@NoArgsConstructor +@Table(name = "tbl_enroll") +public class EnrollEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long EnrollIdx; + + @ManyToOne() + @JoinColumn(name = "fk_member_id") + private MemberEntity member; + + @ManyToOne() + @JoinColumn(name = "fk_contest_id") + private ContestEntity contest; + +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/repository/EnrollRepository.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/repository/EnrollRepository.java new file mode 100644 index 0000000..7ffc4ca --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/repository/EnrollRepository.java @@ -0,0 +1,14 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.enroll.repository; + +import kr.hs.dgsw.SOPO_server_v2.domain.contest.entity.ContestEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.enroll.entity.EnrollEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + +public interface EnrollRepository extends JpaRepository { + Optional findByMemberAndContest(MemberEntity member, ContestEntity contest); + List findByContest(ContestEntity contest); +} \ No newline at end of file diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/service/EnrollService.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/service/EnrollService.java new file mode 100644 index 0000000..fe14dd2 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/enroll/service/EnrollService.java @@ -0,0 +1,167 @@ +package kr.hs.dgsw.SOPO_server_v2.domain.enroll.service; + +import jakarta.transaction.Transactional; +import kr.hs.dgsw.SOPO_server_v2.domain.contest.entity.ContestEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.contest.enums.ContestState; +import kr.hs.dgsw.SOPO_server_v2.domain.contest.repository.ContestRepository; +import kr.hs.dgsw.SOPO_server_v2.domain.enroll.entity.EnrollEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.enroll.repository.EnrollRepository; +import kr.hs.dgsw.SOPO_server_v2.domain.member.entity.MemberEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.member.enums.MemberCategory; +import kr.hs.dgsw.SOPO_server_v2.domain.member.repository.MemberRepository; +import kr.hs.dgsw.SOPO_server_v2.global.error.custom.contest.ContestNotFound; +import kr.hs.dgsw.SOPO_server_v2.global.error.custom.enroll.ENROLL_NOT_FOUND; +import kr.hs.dgsw.SOPO_server_v2.global.error.custom.member.MemberNotCoincideException; +import kr.hs.dgsw.SOPO_server_v2.global.infra.security.GetCurrentMember; +import kr.hs.dgsw.SOPO_server_v2.global.response.Response; +import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@Service +@Transactional +@RequiredArgsConstructor +public class EnrollService { + + private final ContestRepository contestRepository; + private final GetCurrentMember getCurrentMember; + private final EnrollRepository enrollRepository; + private final MemberRepository memberRepository; + + // 신청 기능 + public Response toggle(Long contestId) { + + MemberEntity curMember = getCurrentMember.current(); + + ContestEntity contest = contestRepository.findById(contestId) + .orElseThrow(() -> ContestNotFound.EXCEPTION); + + Optional enroll = enrollRepository.findByMemberAndContest(curMember, contest); + + if (enroll.isEmpty()) { + enrollContest(curMember, contest); + + if (contest.getContestState() == ContestState.DISABLED) { + return Response.of(HttpStatus.OK, "신청이 마감되었습니다."); + } + else { + // enroll 찾기 + return Response.of(HttpStatus.OK, "신청 성공"); + } + } + else { + enrollRepository.delete(enroll.get()); + + return Response.of(HttpStatus.OK, "신청 취소 성공"); + } + + } + + public void enrollContest(MemberEntity member, ContestEntity contest) { + enrollRepository.save( + EnrollEntity.builder() + .contest(contest) + .member(member) + .build() + ); + } + + // 허락 기능 + public Response allowContest(Long contestId, String memberId) { // 대회, 허락받은 사람 + + MemberEntity curMember = getCurrentMember.current(); + + + ContestEntity contest = contestRepository.findById(contestId) + .orElseThrow(() -> ContestNotFound.EXCEPTION); + + MemberEntity member = memberRepository.findByMemberId(memberId); + + // 대회가 이미 닫혀있다면? + if (contest.getContestState() == ContestState.DISABLED) { + return Response.of(HttpStatus.OK, "허락할 수 없습니다."); + } + + if (!contest.getMember().getMemberId().equals(curMember.getMemberId()) && curMember.getMemberCategory() == MemberCategory.USER) { + throw MemberNotCoincideException.EXCEPTION; + } + + + // enroll 찾기 + Optional enroll = enrollRepository.findByMemberAndContest(member, contest); + + System.out.println(enroll); + + // enroll 삭제 + enroll.ifPresent(enrollRepository::delete); + + if (enroll.isEmpty()) { + throw ENROLL_NOT_FOUND.EXCEPTION; + } + + contest.addContestPerson(1); + + if (contest.getContestMax().equals(contest.getContestPerson())) { + contest.stateUpdateDisabled(); + } + + // member 정보 넣기 + contest.addAllowMember(member); + + return Response.of(HttpStatus.OK, "대회 신청 허락 완료"); + } + + // 거절 기능 + public Response refuseContest(Long contestId, String memberId) { + + MemberEntity curMember = getCurrentMember.current(); + + ContestEntity contest = contestRepository.findById(contestId) + .orElseThrow(() -> ContestNotFound.EXCEPTION); + + MemberEntity member = memberRepository.findByMemberId(memberId); + + if (!contest.getMember().getMemberId().equals(curMember.getMemberId()) && curMember.getMemberCategory() == MemberCategory.USER) { + throw MemberNotCoincideException.EXCEPTION; + } + + // enroll 찾기 + Optional enroll = enrollRepository.findByMemberAndContest(member, contest); + + if (contest.getContestMax().equals(contest.getContestPerson())) { + contest.stateUpdateDisabled(); + } + + // enroll 삭제 + enroll.ifPresent(enrollRepository::delete); + + return Response.of(HttpStatus.OK, "대회 신청 거절 완료"); + } + + // 신청한 사람 보여주는 기능 + public ResponseData> showEnrollPeople(Long contestId) { + MemberEntity curMember = getCurrentMember.current(); + + ContestEntity contest = contestRepository.findById(contestId) + .orElseThrow(() -> ContestNotFound.EXCEPTION); + + List enrollList = enrollRepository.findByContest(contest); + + List memberNameList = new ArrayList<>(); + for (EnrollEntity enroll : enrollList) { + memberNameList.add(enroll.getMember().getMemberName()); + } + + if (!contest.getMember().getMemberId().equals(curMember.getMemberId()) && curMember.getMemberCategory() == MemberCategory.USER) { + throw MemberNotCoincideException.EXCEPTION; + } + + return ResponseData.of(HttpStatus.OK, "신청한 사람 조회 성공", memberNameList); + } + +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/controller/FileController.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/controller/FileController.java index 68a07ea..70b7e8d 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/controller/FileController.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/controller/FileController.java @@ -5,6 +5,7 @@ import kr.hs.dgsw.SOPO_server_v2.domain.file.service.FileService; import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -21,7 +22,12 @@ public class FileController { private final FileService fileService; @PostMapping - public ResponseData> fileUpload(@RequestParam FileCategory fileCategory, @RequestPart List fileList) { - return fileService.fileUpload(fileCategory, fileList); + public ResponseData> fileUpload(@RequestParam Long id, @RequestParam FileCategory fileCategory, @RequestPart List fileList) { + return fileService.fileUpload(id, fileCategory, fileList); + } + + @GetMapping + public ResponseData> getFiles(@RequestParam Long id, @RequestParam FileCategory fileCategory) { + return fileService.getFiles(id, fileCategory); } } 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 index eea3614..8e4f7b2 100644 --- 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 @@ -4,6 +4,8 @@ import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; @@ -26,6 +28,7 @@ public class FileEntity extends BaseTimeEntity { // 파일 아이디 @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "file_id") private Long fileId; @@ -56,4 +59,4 @@ public class FileEntity extends BaseTimeEntity { @JoinColumn(name = "member_id") private MemberEntity member; -} +} \ No newline at end of file diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/enums/FileCategory.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/enums/FileCategory.java index 674f253..95db14b 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/enums/FileCategory.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/enums/FileCategory.java @@ -3,5 +3,6 @@ public enum FileCategory { BOARD, CONTEST, - PROFILE + PROFILE, + PORTFOLIO } diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/repository/FileRepository.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/repository/FileRepository.java index 60fd7fd..12e6ba9 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/repository/FileRepository.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/repository/FileRepository.java @@ -3,5 +3,9 @@ import kr.hs.dgsw.SOPO_server_v2.domain.file.entity.FileEntity; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface FileRepository extends JpaRepository { + List findByBoard_BoardId(Long boardId); + List findByContest_ContestId(Long contestId); } diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/service/FileService.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/service/FileService.java index 4a45c8f..f2dca8a 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/service/FileService.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/file/service/FileService.java @@ -3,10 +3,16 @@ import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; +import kr.hs.dgsw.SOPO_server_v2.domain.board.entity.BoardEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.board.repository.BoardRepository; +import kr.hs.dgsw.SOPO_server_v2.domain.contest.entity.ContestEntity; +import kr.hs.dgsw.SOPO_server_v2.domain.contest.repository.ContestRepository; import kr.hs.dgsw.SOPO_server_v2.domain.file.dto.FileRes; import kr.hs.dgsw.SOPO_server_v2.domain.file.entity.FileEntity; import kr.hs.dgsw.SOPO_server_v2.domain.file.enums.FileCategory; import kr.hs.dgsw.SOPO_server_v2.domain.file.repository.FileRepository; +import kr.hs.dgsw.SOPO_server_v2.global.error.custom.board.BoardNotFound; +import kr.hs.dgsw.SOPO_server_v2.global.error.custom.contest.ContestNotFound; import kr.hs.dgsw.SOPO_server_v2.global.response.ResponseData; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; @@ -18,6 +24,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -30,10 +37,17 @@ public class FileService { private final FileRepository fileRepository; + private final BoardRepository boardRepository; + + private final ContestRepository contestRepository; + @Transactional - public ResponseData> fileUpload(FileCategory fileCategory, List fileList) { + public ResponseData> fileUpload(Long id, FileCategory fileCategory, List fileList) { + List fileLists = new ArrayList<>(); + try { + for (MultipartFile file : fileList) { String fileName = file.getOriginalFilename(); @@ -52,20 +66,90 @@ public ResponseData> fileUpload(FileCategory fileCategory, List BoardNotFound.EXCEPTION); + + // DB에 저장하는 코드 + FileEntity fileEntity = FileEntity.builder() + .fileName(fileName) + .fileCategory(fileCategory) + .fileUrl(amazonS3.getUrl(bucket, fileName).toString()) + .board(board) + .build(); + fileRepository.save(fileEntity); + + // 현재 게시물의 파일 목록에 새로 업로드된 파일 추가 + List files = board.getFile(); + if (files == null) { + files = new ArrayList<>(); + } + files.add(fileEntity); + board.setFile(files); // BoardEntity의 파일 목록 직접 수정 + + // 게시물 엔티티를 DB에 저장하여 파일 목록 반영 + boardRepository.save(board); + + } else if (fileCategory == FileCategory.CONTEST) { + ContestEntity contest = contestRepository.findById(id) + .orElseThrow(() -> ContestNotFound.EXCEPTION); + + // DB에 저장하는 코드 + FileEntity fileEntity = FileEntity.builder() + .fileName(fileName) + .fileCategory(fileCategory) + .fileUrl(amazonS3.getUrl(bucket, fileName).toString()) + .contest(contest) + .build(); + + fileRepository.save(fileEntity); + + // 현재 게시물의 파일 목록에 새로 업로드된 파일 추가 + List files = contest.getFile(); + if (files == null) { + files = new ArrayList<>(); + } + files.add(fileEntity); + contest.setFile(files); // BoardEntity의 파일 목록 직접 수정 + + // 게시물 엔티티를 DB에 저장하여 파일 목록 반영 + contestRepository.save(contest); + } } } catch (IOException e) { throw new RuntimeException("Error uploading file to S3", e); } return ResponseData.of(HttpStatus.OK, "파일 업로드 완료", fileLists); } + + public ResponseData> getFiles(Long id, FileCategory fileCategory) { + + List fileList = new ArrayList<>(); + + if (fileCategory == FileCategory.BOARD) { + + fileList = fileRepository.findByBoard_BoardId(id).stream() + .map(file -> FileRes.builder() + .fileName(file.getFileName()) + .fileUrl(file.getFileUrl()) + .build()) + .collect(Collectors.toList()); + + } else if (fileCategory == FileCategory.CONTEST) { + fileList = fileRepository.findByContest_ContestId(id).stream() + .map(file -> FileRes.builder() + .fileName(file.getFileName()) + .fileUrl(file.getFileUrl()) + .build()) + .collect(Collectors.toList()); + } + + return ResponseData.of(HttpStatus.OK, "파일 조회 완료", fileList); + } + + } diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/like/service/LikeService.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/like/service/LikeService.java index 236d0bb..f9dbdb8 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/like/service/LikeService.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/domain/like/service/LikeService.java @@ -31,8 +31,7 @@ public class LikeService { public Response toggle(Long id, LikeCategory category) { MemberEntity curMember = getCurrentMember.current(); - // 토큰 가져오기 - // 게시물 좋아요일 때 + if (category == LikeCategory.BOARD) { BoardEntity board = boardRepository.findById(id) .orElseThrow(() -> BoardNotFound.EXCEPTION); @@ -42,9 +41,11 @@ public Response toggle(Long id, LikeCategory category) { if (like.isEmpty()) { addBoardLike(curMember, board); board.likeUpdate(1); + return Response.of(HttpStatus.OK, "좋아요 생성 완료"); } else { boardRepository.delete(like.get().getBoard()); board.likeUpdate(-1); + return Response.of(HttpStatus.OK, "좋아요 취소 완료"); } } @@ -59,17 +60,17 @@ else if (category == LikeCategory.CONTEST) { if (like.isEmpty()) { addContestLike(curMember, contest); contest.likeUpdate(1); + return Response.of(HttpStatus.OK, "좋아요 생성 완료"); } else { contestRepository.delete(like.get().getContest()); contest.likeUpdate(1); + return Response.of(HttpStatus.OK, "좋아요 취소 완료"); } } - // else if (프로필) {} - - return Response.of(HttpStatus.OK, "좋아요 생성/취소 완료"); - - + else { // 여기다가 프로필 만드셈 + return Response.of(HttpStatus.OK, "???"); + } } @@ -94,4 +95,4 @@ public void addContestLike(MemberEntity member, ContestEntity contest) { } // 프로필 -} +} \ No newline at end of file diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/config/S3Config.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/config/S3Config.java index 93ab5ea..dd45fde 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/config/S3Config.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/config/S3Config.java @@ -25,7 +25,6 @@ public AmazonS3 amazonS3Client() { BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); return AmazonS3ClientBuilder.standard() .withRegion(region) - .enablePathStyleAccess() .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) .build(); } diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/custom/enroll/ENROLL_NOT_FOUND.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/custom/enroll/ENROLL_NOT_FOUND.java new file mode 100644 index 0000000..93afc89 --- /dev/null +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/custom/enroll/ENROLL_NOT_FOUND.java @@ -0,0 +1,12 @@ +package kr.hs.dgsw.SOPO_server_v2.global.error.custom.enroll; + +import kr.hs.dgsw.SOPO_server_v2.global.error.exception.BusinessException; +import kr.hs.dgsw.SOPO_server_v2.global.error.exception.StatusEnum; + +public class ENROLL_NOT_FOUND extends BusinessException { + public static final BusinessException EXCEPTION = new ENROLL_NOT_FOUND(); + + public ENROLL_NOT_FOUND() { + super(StatusEnum.ENROLL_NOT_FOUND);} + +} diff --git a/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/exception/StatusEnum.java b/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/exception/StatusEnum.java index f6c5246..74f1d2e 100644 --- a/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/exception/StatusEnum.java +++ b/src/main/java/kr/hs/dgsw/SOPO_server_v2/global/error/exception/StatusEnum.java @@ -57,7 +57,10 @@ public enum StatusEnum { BOARD_NOT_FOUND(404, "게시물을 찾을 수 없습니다."), // contest - CONTEST_NOT_FOUND(404, "대회를 찾을 수 없습니다"); + CONTEST_NOT_FOUND(404, "대회를 찾을 수 없습니다"), + + // enroll + ENROLL_NOT_FOUND(404, "신청을 찾을 수 없습니다"); private final int statusCode; private final String message;