Skip to content

Commit

Permalink
feat: 중간 커밋
Browse files Browse the repository at this point in the history
  • Loading branch information
alexipharmical committed Jul 31, 2024
1 parent 26a775b commit 861ade3
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 36 deletions.
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 @@ -5,12 +5,15 @@
import kr.hs.dgsw.SOPO_server_v2.domain.board.service.BoardService;
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 @@ -37,13 +40,16 @@ public ResponseData<BoardLoadRes> getBoard(Long 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) {
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 memberId
){
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().getMemberId()
);
}
}
}
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 @@ -43,15 +43,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 +66,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 @@ -10,7 +10,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;
Expand All @@ -32,22 +34,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
Expand Up @@ -5,6 +5,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;
Expand All @@ -17,14 +19,14 @@
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
Expand All @@ -34,6 +36,7 @@ public class ContestEntity extends BaseTimeEntity {
// 대회 아이디
@Id
@Column(name = "contest_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long contestId;

// 대회 제목
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
@Transactional
@RequiredArgsConstructor
public class ContestService { // 대회 전환 필요 -> ACTIVE

private final ContestRepository contestRepository;
private final GetCurrentMember getCurrentMember;

// 대회 전체 조회
public ResponseData<List<ContestLoadRes>> getContests() {
List<ContestEntity> contestList = contestRepository.findAll();
Expand All @@ -37,16 +39,26 @@ public ResponseData<List<ContestLoadRes>> getContests() {

// 빈 대회 생성
public ResponseData<Long> createContest() {

MemberEntity curMember = getCurrentMember.current();

ContestEntity contest = ContestEntity.builder()
.contestMax(null)
.contestContent(null)
.contestPerson(null)
.contestState(ContestState.ACTIVE)
.contestLikeCount(0)
.contestDateTime(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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,12 @@ public class FileController {
private final FileService fileService;

@PostMapping
public ResponseData<List<FileRes>> fileUpload(@RequestParam FileCategory fileCategory, @RequestPart List<MultipartFile> fileList) {
return fileService.fileUpload(fileCategory, fileList);
public ResponseData<List<FileRes>> fileUpload(@RequestParam Long id, @RequestParam FileCategory fileCategory, @RequestPart List<MultipartFile> fileList) {
return fileService.fileUpload(id, fileCategory, fileList);
}

@GetMapping
public ResponseData<List<FileRes>> getFiles(@RequestParam Long id, @RequestParam FileCategory fileCategory) {
return fileService.getFiles(id, fileCategory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +28,7 @@ public class FileEntity extends BaseTimeEntity {

// 파일 아이디
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "file_id")
private Long fileId;

Expand Down Expand Up @@ -56,4 +59,4 @@ public class FileEntity extends BaseTimeEntity {
@JoinColumn(name = "member_id")
private MemberEntity member;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileEntity, Long> {
List<FileEntity> findByBoard_BoardId(Long boardId);
List<FileEntity> findByContest_ContestId(Long contestId);
}
Loading

0 comments on commit 861ade3

Please sign in to comment.