-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add Board findAll,findByID #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jiwon-cho
wants to merge
51
commits into
fire-crew:main
Choose a base branch
from
Jiwon-cho:feature/Board_CRUD
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
ef7d876
updateREAEME
Jiwon-cho e561bf3
swagger,h2
b53e4ed
Merge branch 'feature/README' into main
587503f
swagger,h2
677ab6d
swagger 수정
Jiwon-cho 9eb7cf8
board CRUD,SEARCH
Jiwon-cho 0539af5
board CRUD,find
Jiwon-cho 0185d14
swagger,CRD
1affd5c
Merge branch 'main' of https://github.com/Jiwon-cho/Anonymous_Server …
0888eea
swagger,CRD
dd17471
Merge branch 'main' into feature/README
choipureum 39e816b
swagger,respons 적용중
fe343ce
Merge remote-tracking branch 'origin/feature/README' into feature/README
e45ad7b
Common class 생성
Jiwon-cho b3498c9
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
2b5bfdf
BoardResponse,SaveRequestDTO 생성,Controller 수정
ed6b474
BoardResponse,SaveRequestDTO 생성,Controller 수정
664fe20
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
d24d6f0
BoardResponse,SaveRequestDTO 생성,Controller 수정
7259335
Merge remote-tracking branch 'origin/main' into main
e6c216c
swagger,h2
49674f0
swagger 수정
Jiwon-cho 275975a
board CRUD,SEARCH
Jiwon-cho 4adc451
board CRUD,find
Jiwon-cho 80c4238
swagger,CRD
aba21fc
swagger,CRD
9fc60c6
swagger,respons 적용중
a8841c6
Common class 생성
Jiwon-cho d0fe5a6
BoardResponse,SaveRequestDTO 생성,Controller 수정
999f72b
BoardResponse,SaveRequestDTO 생성,Controller 수정
e202620
BoardResponse,SaveRequestDTO 생성,Controller 수정
6c3d5b4
Board CRUD 브랜치 REBASE
56048f6
Merge remote-tracking branch 'origin/feature/Board_CRUD' into feature…
bcefa98
Board CRUD delte
fc65c58
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
9da8222
Board CRUD,update,selectAll
e5c64f9
User,UserController 삭제,Transactional 변경
1199562
BoardResponse,SaveRequestDTO 삭제
343630c
controllerTest test
Jiwon-cho 9f09d9f
controllerTest createTest
Jiwon-cho cf4c836
BoardControllerTest,deleteBoardTest 작성
5097be2
controllerTest,selectBoardTest,serviceTest
Jiwon-cho 128f516
BoardControllerTest,When 추가
70df3ab
BoardControllerTest,When 추가
37bb9f6
BoardControllerTest,select,create test 로직 변경
5541e51
BoardRepositoryTest 작성,BoardFixture 내 메소드 추가
Jiwon-cho 8725965
BoardServiceTest 추가
Jiwon-cho c5c1225
Post로 이름 수정,ServiceTest 코드 추가작성, 향후 메소드명 변경 계획
Jiwon-cho f8dce5a
method명 변경,Controller-updateTest 추가
e226d67
build Fail 확인용 커밋
6029a85
build Fail 확인용 커밋
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
43 changes: 43 additions & 0 deletions
43
src/main/java/com/makefire/anonymous/domain/board/entity/Board.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package com.makefire.anonymous.domain.board.entity; | ||
|
|
||
|
|
||
| import com.makefire.anonymous.domain.common.BasicEntity; | ||
| import lombok.*; | ||
|
|
||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.Lob; | ||
| import javax.persistence.Table; | ||
|
|
||
|
|
||
| @Entity | ||
| @Table(name="BOARD") | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class Board extends BasicEntity { | ||
|
|
||
|
|
||
|
|
||
|
||
| @Column(nullable = false) | ||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private String title; | ||
|
|
||
| @Lob | ||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Column(nullable = false) | ||
| private String content; | ||
|
|
||
|
|
||
| private String author; | ||
|
|
||
| private Long authorId; | ||
|
|
||
|
|
||
| @Builder | ||
| public Board(String title, String content, String author, Long authorId) { | ||
| this.title = title; | ||
| this.content = content; | ||
| this.author = author; | ||
| this.authorId = authorId; | ||
| } | ||
|
|
||
| } | ||
15 changes: 15 additions & 0 deletions
15
src/main/java/com/makefire/anonymous/domain/board/repository/BoardRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.makefire.anonymous.domain.board.repository; | ||
|
|
||
| import com.makefire.anonymous.domain.board.entity.Board; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| @Repository | ||
| public interface BoardRepository extends JpaRepository<Board, Long> { | ||
|
|
||
|
|
||
|
|
||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/makefire/anonymous/domain/common/BasicEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.makefire.anonymous.domain.common; | ||
|
|
||
| import lombok.Getter; | ||
| import org.springframework.data.annotation.CreatedDate; | ||
| import org.springframework.data.annotation.LastModifiedDate; | ||
| import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
|
||
|
|
||
| import javax.persistence.*; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @MappedSuperclass | ||
| @EntityListeners(AuditingEntityListener.class) | ||
| public abstract class BasicEntity { | ||
| @Id | ||
| @GeneratedValue | ||
| private Long id; | ||
|
|
||
|
|
||
| @CreatedDate | ||
| @Column(name = "created_date") | ||
| private LocalDateTime createdDate; | ||
|
|
||
| @LastModifiedDate | ||
| @Column(name = "modifiedDate") | ||
| private LocalDateTime modifiedDate; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/makefire/anonymous/rest/controller/api/BoardController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.makefire.anonymous.rest.controller.api; | ||
|
|
||
|
|
||
| import com.makefire.anonymous.rest.dto.request.board.BoardSaveRequestDTO; | ||
| import com.makefire.anonymous.rest.dto.response.board.BoardResponseDTO; | ||
| import com.makefire.anonymous.service.board.BoardService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/board") | ||
| public class BoardController { | ||
|
|
||
| private final BoardService boardService; | ||
|
|
||
|
|
||
|
|
||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @GetMapping("/findAll") | ||
| public ResponseEntity<List<BoardResponseDTO>> boardList() { | ||
|
|
||
| return ResponseEntity.ok().body( boardService.findAll()); | ||
| } | ||
|
|
||
| @PostMapping("/create") | ||
| public ResponseEntity<Long> save(@RequestBody BoardSaveRequestDTO requestDTO) { | ||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ResponseEntity.ok().body(boardService.save(requestDTO)); | ||
| } | ||
|
|
||
|
|
||
| @GetMapping("/findById/{id}") | ||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public ResponseEntity<BoardResponseDTO> findById(@PathVariable("id") Long id) { | ||
|
|
||
| return ResponseEntity.ok().body(boardService.findById(id)); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/makefire/anonymous/rest/dto/request/board/BoardSaveRequestDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.makefire.anonymous.rest.dto.request.board; | ||
|
|
||
| import com.makefire.anonymous.domain.board.entity.Board; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class BoardSaveRequestDTO { | ||
| private String title; | ||
| private String content; | ||
| private String author; | ||
| private Long authorId; | ||
|
|
||
| @Builder | ||
| public BoardSaveRequestDTO(String title, String content, String author, Long authorId) { | ||
| this.title = title; | ||
| this.content = content; | ||
| this.author = author; | ||
| this.authorId = authorId; | ||
| } | ||
|
|
||
| public Board toEntity() { | ||
| return Board.builder() | ||
| .title(title) | ||
| .content(content) | ||
| .author(author) | ||
| .authorId(authorId) | ||
| .build(); | ||
|
|
||
| } | ||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/main/java/com/makefire/anonymous/rest/dto/response/Message.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.makefire.anonymous.rest.dto.response; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public class Message { | ||
|
|
||
| private StatusEnum status; | ||
| private String message; | ||
| private Object data; | ||
|
|
||
| public Message() { | ||
| this.status = StatusEnum.BAD_REQUEST; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| this.data = null; | ||
| this.message = null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/makefire/anonymous/rest/dto/response/StatusEnum.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.makefire.anonymous.rest.dto.response; | ||
|
|
||
| public enum StatusEnum { | ||
|
|
||
| OK(200, "OK"), | ||
| BAD_REQUEST(400, "BAD_REQUEST"), | ||
| NOT_FOUND(404, "NOT_FOUND"), | ||
| INTERNAL_SERER_ERROR(500, "INTERNAL_SERVER_ERROR"); | ||
|
|
||
| int statusCode; | ||
| String code; | ||
|
|
||
| StatusEnum(int statusCode, String code) { | ||
| this.statusCode = statusCode; | ||
| this.code = code; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/makefire/anonymous/rest/dto/response/board/BoardResponseDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.makefire.anonymous.rest.dto.response.board; | ||
|
|
||
| import com.makefire.anonymous.domain.board.entity.Board; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| public class BoardResponseDTO { | ||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private Long id, authorId; | ||
| private String title, content, author; | ||
|
|
||
| @Setter | ||
| private Long viewCount; | ||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public BoardResponseDTO(Board entity) { | ||
| this.id = entity.getId(); | ||
| this.title = entity.getTitle(); | ||
| this.content = entity.getContent(); | ||
| this.author = entity.getAuthor(); | ||
| this.authorId = entity.getAuthorId(); | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
src/main/java/com/makefire/anonymous/service/board/BoardService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.makefire.anonymous.service.board; | ||
|
|
||
| import com.makefire.anonymous.domain.board.entity.Board; | ||
| import com.makefire.anonymous.domain.board.repository.BoardRepository; | ||
| import com.makefire.anonymous.rest.dto.request.board.BoardSaveRequestDTO; | ||
| import com.makefire.anonymous.rest.dto.response.board.BoardResponseDTO; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class BoardService { | ||
| private final BoardRepository boardRepository; | ||
|
|
||
|
|
||
|
|
||
|
|
||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| public List<BoardResponseDTO> findAll() { | ||
| return boardRepository.findAll().stream().map(BoardResponseDTO::new).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public BoardResponseDTO findById(Long id) { | ||
| Board entity = boardRepository.findById(id) | ||
| .orElseThrow(() -> new IllegalArgumentException("해당 게시물이 없습니다. id=" + id)); | ||
|
|
||
| return new BoardResponseDTO(entity); | ||
| } | ||
|
|
||
| public Long save(BoardSaveRequestDTO requestDTO) { | ||
choipureum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return boardRepository.save(requestDTO.toEntity()) | ||
| .getId(); | ||
| } | ||
|
|
||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.