Skip to content
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ef7d876
updateREAEME
Jiwon-cho Jan 27, 2022
e561bf3
swagger,h2
Feb 3, 2022
b53e4ed
Merge branch 'feature/README' into main
Feb 3, 2022
587503f
swagger,h2
Feb 3, 2022
677ab6d
swagger 수정
Jiwon-cho Feb 3, 2022
9eb7cf8
board CRUD,SEARCH
Jiwon-cho Feb 7, 2022
0539af5
board CRUD,find
Jiwon-cho Feb 8, 2022
0185d14
swagger,CRD
Feb 10, 2022
1affd5c
Merge branch 'main' of https://github.com/Jiwon-cho/Anonymous_Server …
Feb 14, 2022
0888eea
swagger,CRD
Feb 15, 2022
dd17471
Merge branch 'main' into feature/README
choipureum Feb 16, 2022
39e816b
swagger,respons 적용중
Feb 16, 2022
fe343ce
Merge remote-tracking branch 'origin/feature/README' into feature/README
Feb 16, 2022
e45ad7b
Common class 생성
Jiwon-cho Feb 16, 2022
b3498c9
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
Feb 25, 2022
2b5bfdf
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
ed6b474
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
664fe20
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
Feb 25, 2022
d24d6f0
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
7259335
Merge remote-tracking branch 'origin/main' into main
Mar 2, 2022
e6c216c
swagger,h2
Feb 3, 2022
49674f0
swagger 수정
Jiwon-cho Feb 3, 2022
275975a
board CRUD,SEARCH
Jiwon-cho Feb 7, 2022
4adc451
board CRUD,find
Jiwon-cho Feb 8, 2022
80c4238
swagger,CRD
Feb 10, 2022
aba21fc
swagger,CRD
Feb 15, 2022
9fc60c6
swagger,respons 적용중
Feb 16, 2022
a8841c6
Common class 생성
Jiwon-cho Feb 16, 2022
d0fe5a6
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
999f72b
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
e202620
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
6c3d5b4
Board CRUD 브랜치 REBASE
Mar 3, 2022
56048f6
Merge remote-tracking branch 'origin/feature/Board_CRUD' into feature…
Mar 3, 2022
bcefa98
Board CRUD delte
Mar 4, 2022
fc65c58
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
Mar 7, 2022
9da8222
Board CRUD,update,selectAll
Mar 7, 2022
e5c64f9
User,UserController 삭제,Transactional 변경
Mar 8, 2022
1199562
BoardResponse,SaveRequestDTO 삭제
Mar 11, 2022
343630c
controllerTest test
Jiwon-cho Mar 14, 2022
9f09d9f
controllerTest createTest
Jiwon-cho Mar 16, 2022
cf4c836
BoardControllerTest,deleteBoardTest 작성
Mar 17, 2022
5097be2
controllerTest,selectBoardTest,serviceTest
Jiwon-cho Mar 17, 2022
128f516
BoardControllerTest,When 추가
Mar 23, 2022
70df3ab
BoardControllerTest,When 추가
Mar 23, 2022
37bb9f6
BoardControllerTest,select,create test 로직 변경
Mar 24, 2022
5541e51
BoardRepositoryTest 작성,BoardFixture 내 메소드 추가
Jiwon-cho Mar 30, 2022
8725965
BoardServiceTest 추가
Jiwon-cho Mar 31, 2022
c5c1225
Post로 이름 수정,ServiceTest 코드 추가작성, 향후 메소드명 변경 계획
Jiwon-cho Apr 1, 2022
f8dce5a
method명 변경,Controller-updateTest 추가
Apr 4, 2022
e226d67
build Fail 확인용 커밋
Apr 5, 2022
6029a85
build Fail 확인용 커밋
Apr 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.makefire.anonymous.domain.board.entity;


import com.makefire.anonymous.domain.common.BasicEntity;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;


@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Board extends BasicEntity {


@NotNull(message = "Title must not be null")
private String title;


private String content;

@NotNull(message = "Author must not be null")
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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;

@Repository
public interface BoardRepository extends JpaRepository<Board, Long> {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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",updatable = false)
private LocalDateTime createdDate;

@LastModifiedDate
@Column(name = "modifiedDate",insertable = false)
private LocalDateTime modifiedDate;


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.makefire.anonymous.domain.user.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
*packageName : com.makefire.anonymous
Expand All @@ -11,5 +14,14 @@
* 22-01-15 최푸름
* ---------------------------------
*/




public class User {
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.makefire.anonymous.rest.controller.api;


import com.makefire.anonymous.rest.RestSupport;
import com.makefire.anonymous.rest.dto.request.board.BoardRequest;
import com.makefire.anonymous.rest.dto.response.Response;
import com.makefire.anonymous.service.board.BoardService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@RequestMapping("/board")
@Slf4j
public class BoardController extends RestSupport {

private final BoardService boardService;


@PostMapping
public ResponseEntity<Response> createBoard(
@Valid @RequestBody BoardRequest boardRequest) {
log.info("createBoard", boardRequest.toString());
return response(boardService.createBoard(boardRequest));
}

@GetMapping("{id}")
public ResponseEntity<Response> selectBoard(@PathVariable("id") Long id) {

return response(boardService.selectBoard(id));

}

@DeleteMapping("{id}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ 추가

public ResponseEntity<Response> deleteBoard(@PathVariable("id") Long id) {
return response(boardService.deleteBoard(id));
}

}

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.makefire.anonymous.rest.controller.api;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
*packageName : com.makefire.anonymous
* fileName : UserController
Expand All @@ -14,5 +15,13 @@
* ---------------------------------
*/
@Controller
public class UserController {
}
public class UserController{


@RequestMapping(method=RequestMethod.GET,path="/getMethod")
//localhost:8080/api/getMethod
public String getRequest(){
return "skxokj.rolls";

}
}
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 BoardRequest {
private String title;
private String content;
private String author;
private Long authorId;

@Builder
public BoardRequest(String title, String content, String author, Long authorId) {
this.title = title;
this.content = content;
this.author = author;
this.authorId = authorId;
}

public static Board toEntity(BoardRequest boardRequest) {
return Board.builder()
.title(boardRequest.title)
.content(boardRequest.content)
.author(boardRequest.author)
.authorId(boardRequest.authorId)
.build();

}

}
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();

}

}
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BAD_REQUEST로 고정될 경우 다른 경우는 현재 반환이 어려워보입니다. 좀 더 확장성있는 구조 설계를 해야할 것 같습니다

this.data = null;
this.message = null;
}
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.makefire.anonymous.rest.dto.response.board;

import com.makefire.anonymous.domain.board.entity.Board;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class BoardResponse {

private Long id, authorId;
private String title, content, author;
private LocalDateTime createdDate, modifiedDate;


@Builder
public BoardResponse(Long id, Long authorId, String title, String content, String author, LocalDateTime createdDate, LocalDateTime modifiedDate) {
this.id = id;
this.authorId = authorId;
this.title = title;
this.content = content;
this.author = author;
this.createdDate = createdDate;
this.modifiedDate = modifiedDate;

}

public static BoardResponse from(Board board) {
return BoardResponse.builder()
.id(board.getId())
.authorId(board.getAuthorId())
.title(board.getTitle())
.content(board.getContent())
.author(board.getAuthor())
.createdDate(board.getCreatedDate())
.modifiedDate(board.getModifiedDate())
.build();
}

}
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 {

private Long id, authorId;
private String title, content, author;

@Setter
private Long viewCount;

public BoardResponseDTO(Board entity) {
this.id = entity.getId();
this.title = entity.getTitle();
this.content = entity.getContent();
this.author = entity.getAuthor();
this.authorId = entity.getAuthorId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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.BoardRequest;
import com.makefire.anonymous.rest.dto.response.board.BoardResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
@AllArgsConstructor
@Transactional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Transactional을 클래스 레벨에서 다루기보다 메소드 단위로 다루는게 좋아보입니다.

public class BoardService {
private final BoardRepository boardRepository;


public BoardResponse selectBoard(Long id) {
Board board = boardRepository.findById(id).orElseThrow(() -> new IllegalArgumentException());

return BoardResponse.from(board);

}


public BoardResponse createBoard(BoardRequest boardRequest) {

Board board = BoardRequest.toEntity(boardRequest);
return BoardResponse.from(boardRepository.save(board));
}

public Boolean deleteBoard(Long id) {
Board board = boardRepository.findById(id).orElseThrow(() -> new IllegalArgumentException());
boardRepository.delete(board);
return true;

}
}
Loading