Skip to content

Commit

Permalink
Merge pull request #9 from Sopo2023/feat/#2
Browse files Browse the repository at this point in the history
Feat/#2
  • Loading branch information
alexipharmical authored Aug 2, 2024
2 parents e493e57 + 6e44e4c commit 76a6e7c
Show file tree
Hide file tree
Showing 25 changed files with 519 additions and 71 deletions.
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
ENTRYPOINT ["java","-jar","/sopo.jar"]
>>>>>>> 12f73049a4d31fff0df65fbbc7b5fa5b6e7dd993
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,8 +27,8 @@ public class BoardController {
private final BoardService boardService;

@GetMapping("/all")
public ResponseData<List<BoardLoadRes>> getBoards() {
return boardService.getBoards();
public ResponseData<List<BoardLoadRes>> getBoards(@ModelAttribute PageRequest pageRequest) {
return boardService.getBoards(pageRequest);
}

@PostMapping
Expand All @@ -32,18 +37,21 @@ public ResponseData<Long> createBoard() {
}

@GetMapping
public ResponseData<BoardLoadRes> getBoard(Long boardId) {
public ResponseData<BoardLoadRes> 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);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public record BoardUpdateReq(
String boardTitle,
String boardContent
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,7 @@
@Entity
@Table(name = "tbl_board")
@NoArgsConstructor
@Setter
@SuperBuilder
public class BoardEntity extends BaseTimeEntity {

Expand Down Expand Up @@ -62,4 +64,4 @@ public void update(BoardUpdateReq updateReq) {
public void likeUpdate(int boardLikeCount) {
this.boardLikeCount += boardLikeCount;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
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;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
Expand All @@ -27,11 +29,14 @@ public class BoardService {
private final GetCurrentMember getCurrentMember;

// 게시글 전체 조회
public ResponseData<List<BoardLoadRes>> getBoards() {
public ResponseData<List<BoardLoadRes>> getBoards(PageRequest pageRequest) {
List<BoardEntity> boardList = boardRepository.findAll();
List<BoardLoadRes> boardLoadResList = boardList.stream().map(
BoardLoadRes::of
).toList();

List<BoardLoadRes> boardLoadResList = boardList.stream()
.map(BoardLoadRes::of)
.skip((pageRequest.page() -1) * pageRequest.size())
.limit(pageRequest.size())
.collect(Collectors.toList());

return ResponseData.of(HttpStatus.OK, "게시물 전체 조회 완료", boardLoadResList);
}
Expand All @@ -43,15 +48,18 @@ public ResponseData<Long> 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)
Expand All @@ -63,6 +71,7 @@ public Response loadBoard(Long boardId, BoardUpdateReq updateReq) {
}

board.update(updateReq);

return Response.of(HttpStatus.OK, "게시물 업데이트 완료");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
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;
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.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;
Expand All @@ -22,8 +25,8 @@ public class ContestController {
private final ContestService contestService;

@GetMapping("/all")
public ResponseData<List<ContestLoadRes>> getContests() {
return contestService.getContests();
public ResponseData<List<ContestLoadRes>> getContests(PageRequest pageRequest) {
return contestService.getContests(pageRequest);
}

@PostMapping
Expand All @@ -32,22 +35,22 @@ public ResponseData<Long> createContest() {
}

@GetMapping
public ResponseData<ContestLoadRes> getContest(Long contestId) {
public ResponseData<ContestLoadRes> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
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,
String contestTitle,
String contestContent,
Integer contestMax,
Integer contestPerson,
LocalDateTime contestDateTime
// List<String> fileUrls,
// Long memberId
LocalDateTime contestDateTime,
String memberName,
List<String> memberIdList
) {
public static ContestLoadRes of(ContestEntity contest) {
List<String> 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
);
}
}
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

// 대회 제목
Expand Down Expand Up @@ -74,6 +78,12 @@ public class ContestEntity extends BaseTimeEntity {
@OneToMany(mappedBy = "contest", cascade = CascadeType.ALL, orphanRemoval = true) // 읽기만, 게시물 삭제될 때 함께 삭제
private List<FileEntity> file;

// 대회 유저 이름
@ManyToMany
@JoinColumn(name = "member_id_list")
private List<MemberEntity> memberIdList;


public void update(ContestUpdateReq updateReq) {
this.contestTitle = updateReq.contestTitle();
this.contestContent = updateReq.contestContent();
Expand All @@ -86,11 +96,19 @@ 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;
}

public void stateUpdateDisabled() {
this.contestState = ContestState.DISABLED;
}
}
}
Loading

0 comments on commit 76a6e7c

Please sign in to comment.