7 Commits

Author SHA1 Message Date
kimyonghwa
6329c24584 bugfix
- update ftl path
- delete duplicate security settings
2019-11-14 11:30:35 +09:00
codej99
37b4b9cd73 Merge branch 'master' into feature/board 2019-09-17 17:35:37 +09:00
kimyonghwa
4173fc1225 add api
- create board
2019-09-17 17:34:13 +09:00
kimyonghwa
200168c601 Merge branch 'feature/board' 2019-09-05 23:14:52 +09:00
kimyonghwa
a51dce74ad post 정렬 추가 2019-09-05 23:13:20 +09:00
kimyonghwa
d4e74d92c1 Serializable 추가 2019-09-04 00:55:07 +09:00
codej99
8cecd7edcf Merge pull request #20 from codej99/cache-data-redis
Cache data redis
2019-08-08 02:09:31 +09:00
5 changed files with 22 additions and 4 deletions

View File

@@ -28,6 +28,15 @@ public class BoardController {
private final BoardService boardService;
private final ResponseService responseService;
@ApiImplicitParams({
@ApiImplicitParam(name = "X-AUTH-TOKEN", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header")
})
@ApiOperation(value = "게시판 생성", notes = "신규 게시판을 생성한다.")
@PostMapping(value = "/{boardName}")
public SingleResult<Board> createBoard(@PathVariable String boardName) {
return responseService.getSingleResult(boardService.insertBoard(boardName));
}
@ApiOperation(value = "게시판 정보 조회", notes = "게시판 정보를 조회한다.")
@GetMapping(value = "/{boardName}")
public SingleResult<Board> boardInfo(@PathVariable String boardName) {
@@ -44,7 +53,7 @@ public class BoardController {
@ApiImplicitParam(name = "X-AUTH-TOKEN", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header")
})
@ApiOperation(value = "게시글 작성", notes = "게시글을 작성한다.")
@PostMapping(value = "/{boardName}")
@PostMapping(value = "/{boardName}/post")
public SingleResult<Post> post(@PathVariable String boardName, @Valid @ModelAttribute ParamsPost post) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String uid = authentication.getName();

View File

@@ -1,15 +1,19 @@
package com.rest.api.entity.board;
import com.rest.api.entity.common.CommonDateEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
@Builder
@Entity
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Board extends CommonDateEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

View File

@@ -7,12 +7,13 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.time.LocalDateTime;
@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class CommonDateEntity {
public abstract class CommonDateEntity implements Serializable {
@CreatedDate
private LocalDateTime createdAt;
@LastModifiedDate

View File

@@ -7,5 +7,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface PostJpaRepo extends JpaRepository<Post, Long> {
List<Post> findByBoard(Board board);
List<Post> findByBoardOrderByPostIdDesc(Board board);
}

View File

@@ -34,6 +34,10 @@ public class BoardService {
private final UserJpaRepo userJpaRepo;
private final CacheSevice cacheSevice;
public Board insertBoard(String boardName) {
return boardJpaRepo.save(Board.builder().name(boardName).build());
}
// 게시판 이름으로 게시판을 조회. 없을경우 CResourceNotExistException 처리
@Cacheable(value = CacheKey.BOARD, key = "#boardName", unless = "#result == null")
public Board findBoard(String boardName) {
@@ -43,7 +47,7 @@ public class BoardService {
// 게시판 이름으로 게시글 리스트 조회.
@Cacheable(value = CacheKey.POSTS, key = "#boardName", unless = "#result == null")
public List<Post> findPosts(String boardName) {
return postJpaRepo.findByBoard(findBoard(boardName));
return postJpaRepo.findByBoardOrderByPostIdDesc(findBoard(boardName));
}
// 게시글ID로 게시글 단건 조회. 없을경우 CResourceNotExistException 처리