Skip to content

Commit

Permalink
Chore : 큐시트 히스토리 수정 (#47)
Browse files Browse the repository at this point in the history
* Chore: user, org 수정

* Chore: bookmark, board user,org 수정

* Chore: boardController 업데이트

---------

Co-authored-by: yby654 <yby654321@gmail.com>
  • Loading branch information
yby654 and yby654321 authored Oct 28, 2023
1 parent 9b47bc1 commit 959ff58
Show file tree
Hide file tree
Showing 18 changed files with 422 additions and 88 deletions.
172 changes: 172 additions & 0 deletions nw/src/main/java/lab/cherry/nw/controller/BoardController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package lab.cherry.nw.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lab.cherry.nw.error.ErrorResponse;
import lab.cherry.nw.error.ResultResponse;
import lab.cherry.nw.error.enums.SuccessCode;
import lab.cherry.nw.model.BoardEntity;
import lab.cherry.nw.service.BoardService;
import lab.cherry.nw.util.Common;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
* <pre>
* ClassName : BoardController
* Type : class
* Description : 게시물 목록 조회, 게시물 상세 조회, 게시물 업데이트, 게시물 삭제, 게시물 찾기 등 게시물과 관련된 함수를 포함하고 있는 클래스입니다.
* Related : BoardRepository, BoardService, BoardServiceImpl
* </pre>
*/

// MEMO : 재사용성을 위해 ServiceImpl에서만 비즈니스 로직을 사용하기로 함
// Dto를 통해 알맞는 파라미터로 데이터 가공 후 사용하기로 함
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/board")
@Tag(name = "Board", description = "Board API Document")
public class BoardController {
private final BoardService boardService;

/**
* [BoardController] 전체 게시물 목록 함수
*
* @return 전체 게시물 목록을 반환합니다.
*
* Author : yby654(yby654@github.com)
*/
@GetMapping("/post")
@Operation(summary = "게시물 목록", description = "게시물 목록을 조회합니다.")
public ResponseEntity<?> findAllBoards(
@RequestParam(required = false) String userid,
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "5") Integer size,
@RequestParam(defaultValue = "created_at,desc") String[] sort) {

log.info("retrieve all boards controller...!");

Pageable pageable = PageRequest.of(page, size, Sort.by(Common.getOrder(sort)));

Page<BoardEntity> boardEntity;
if(userid == null ) {
boardEntity = boardService.getBoards(pageable);
} else {
boardEntity = boardService.findPageByUserId(userid, pageable);
}
// for (BoardEntity board : boardEntity) {
// board.sortDataByOrderIndex();
// }
return new ResponseEntity<>(boardEntity, new HttpHeaders(), HttpStatus.OK);
}

/**
* [BoardController] 게시물 생성 함수
* <pre>
* @param boardCreateDto 게시물 생성에 필요한 게시물 정보를 담고 있는 객체입니다.
* @return
* true : 업데이트된 게시물 정보를 반환합니다.
* false : 에러(400, 404)를 반환합니다.
* </pre>
*
* Author : yby654(yby654@github.com)
*/
@PostMapping("/post")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "게시물 생성이 완료되었습니다.", content = @Content(schema = @Schema(implementation = ResponseEntity.class))),
@ApiResponse(responseCode = "400", description = "입력 값이 잘못 되었습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@Operation(summary = "Board 생성", description = "Board를 추가합니다.")
public ResponseEntity<?> createBoard(@Valid @RequestBody BoardEntity.BoardCreateDto boardCreateDto) {
log.info("[BoardController] createBoard...!");
boardService.createBoard(boardCreateDto);

final ResultResponse response = ResultResponse.of(SuccessCode.OK);
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
}
/**
* [BoardController] 게시물 수정 함수
* <pre>
* @param id 게시물 고유번호를 입력합니다.
* @param boardUpdateDto 게시물 업데이트에 필요한 게시물 정보를 담고 있는 객체입니다.
* @return
* true : 업데이트된 게시물 정보를 반환합니다.
* false : 에러(400, 404)를 반환합니다.
* </pre>
*
* Author : yby654(yby654@github.com)
*/
@PatchMapping("/post/{id}")
@Operation(summary = "게시물 업데이트", description = "특정 게시물를 업데이트합니다.")
public ResponseEntity<?> updateById(
@PathVariable("id") String id,
@RequestBody BoardEntity.BoardUpdateDto boardUpdateDto) {

log.info("[BoardController] updateBoard...!");

boardService.updateById(id, boardUpdateDto);

// final ResultResponse response = ResultResponse.of(SuccessCode.OK);
return new ResponseEntity<>(boardService.findById(id), new HttpHeaders(), HttpStatus.OK);
}
/**
* [BoardController] 특정 게시물 삭제 함수
*
* @param id 게시물 고유번호를 입력합니다.
* @return
* <pre>
* true : 특정 게시물를 삭제처리합니다.
* false : 에러(400, 404)를 반환합니다.
* </pre>
*
* Author : yby654(yby654@github.com)
*/
@DeleteMapping("{id}")
@Operation(summary = "게시글 삭제", description = "게시글을 삭제합니다.")
public ResponseEntity<?> deleteById(@PathVariable("id") String id) {

log.info("[BoardController] deleteBoardPost...!");

boardService.deleteById(id);

final ResultResponse response = ResultResponse.of(SuccessCode.OK);
return new ResponseEntity<>(response, new HttpHeaders(), HttpStatus.OK);
}

/**
* [BoardController] 특정 게시물 조회 함수
*
* @param id 게시물 고유번호를 입력합니다.
* @return
* <pre>
* true : 특정 게시물 정보를 반환합니다.
* false : 에러(400, 404)를 반환합니다.
* </pre>
*
* Author : yby654(yby654@github.com)
*/
@GetMapping("{id}")
@Operation(summary = "ID로 게시물 찾기", description = "게시물를 조회합니다.")
public ResponseEntity<?> findByBoardId(@PathVariable("id") String id) {

log.info("[BoardController] findByBoardId...!");

// final ResultResponse response = ResultResponse.of(SuccessCode.OK, userService.findById(id));
return new ResponseEntity<>(boardService.findById(id), new HttpHeaders(), HttpStatus.OK);
}

}
12 changes: 6 additions & 6 deletions nw/src/main/java/lab/cherry/nw/controller/QsheetController.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public class QsheetController {
@GetMapping("")
@Operation(summary = "큐시트 목록", description = "큐시트 목록을 조회합니다.")
public ResponseEntity<?> findAllQsheets(
@RequestParam(required = false) String userid,
@RequestParam(required = false) String orgid,
@RequestParam(required = false) String userSeq,
@RequestParam(required = false) String orgSeq,
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "5") Integer size,
@RequestParam(defaultValue = "id,desc") String[] sort) {
Expand All @@ -76,12 +76,12 @@ public ResponseEntity<?> findAllQsheets(
Pageable pageable = PageRequest.of(page, size, Sort.by(Common.getOrder(sort)));

Page<QsheetEntity> qsheetEntity;
if(userid == null && orgid==null) {
if(userSeq == null && orgSeq==null) {
qsheetEntity = qsheetService.getQsheets(pageable);
} else if(userid != null && orgid==null) {
qsheetEntity = qsheetService.findPageByUserId(userid, pageable);
} else if(userSeq != null && orgSeq==null) {
qsheetEntity = qsheetService.findPageByUserId(userSeq, pageable);
} else{
qsheetEntity = qsheetService.findPageByOrgId(orgid, pageable);
qsheetEntity = qsheetService.findPageByOrgId(orgSeq, pageable);
}
for (QsheetEntity qsheet : qsheetEntity) {
qsheet.sortDataByOrderIndex();
Expand Down
2 changes: 1 addition & 1 deletion nw/src/main/java/lab/cherry/nw/model/BoardEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BoardEntity implements Serializable {
@DBRef
@JsonProperty("userSeq")
@Schema(title = "유저 고유번호", example = "38352658567418867") // (Long) Tsid
private UserEntity userid;
private UserEntity user;

@JsonProperty("content")
@Schema(title = "내용", example = "드디어 결혼합니다!")
Expand Down
2 changes: 1 addition & 1 deletion nw/src/main/java/lab/cherry/nw/model/BookmarkEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BookmarkEntity implements Serializable {
@DBRef
@JsonProperty("user")
@Schema(title = "유저 고유번호", example = "38352658567418867") // (Long) Tsid
private UserEntity userid;
private UserEntity user;

@JsonProperty("data")
private Map<String, String> data;
Expand Down
15 changes: 7 additions & 8 deletions nw/src/main/java/lab/cherry/nw/model/QsheetEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.time.Instant;
import java.util.Comparator;
import java.util.List;

import java.util.Objects;

/**
* <pre>
Expand All @@ -40,14 +40,14 @@ public class QsheetEntity implements Serializable {
private String id;

@DBRef
@JsonProperty("userSeq")
@Schema(title = "유저 고유번호", type="String",example = "38352658567418867") // (Long) Tsid
private UserEntity userid;
@JsonProperty("user")
@Schema(title = "유저 정보") // (Long) Tsid
private UserEntity user;

@DBRef
@JsonProperty("orgSeq")
@Schema(title = "조직 정보", type="String",example = "38352658567418867") // (Long) Tsid
private OrgEntity orgid;
@JsonProperty("org")
@Schema(title = "조직 정보") // (Long) Tsid
private OrgEntity org;


@JsonProperty("name")
Expand Down Expand Up @@ -105,7 +105,6 @@ public static class ItemData {
@Schema(title = "파일위치", example = "./")
private String filePath;
}

@Getter
@Builder
@NoArgsConstructor @AllArgsConstructor
Expand Down
50 changes: 50 additions & 0 deletions nw/src/main/java/lab/cherry/nw/model/QsheetLogEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package lab.cherry.nw.model;

import java.io.Serializable;
import java.time.Instant;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;
import lab.cherry.nw.model.QsheetEntity.ItemData;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* <pre>
* ClassName : QsheetLogEntity
* Type : class
* Description : 큐시트 로그와 관련된 Entity를 구성하고 있는 클래스입니다.
* Related : QsheetLogRepository, QsheetLogServiceImpl
* </pre>
*/
@Getter
@Builder
@NoArgsConstructor @AllArgsConstructor
@Document(collection = "qsheet_log")
@JsonPropertyOrder({ "id", "method"})
public class QsheetLogEntity implements Serializable {

@Id
@JsonProperty("qsheetLogSeq")
@Schema(title = "큐시트 고유번호",type="String", example = "38352658567418867") // (Long) Tsid
private String id;

@JsonProperty("method")
@Schema(title = "method", example = "create")
private String method;

@JsonProperty("qsheet")
@Schema(title = "큐시트") // (Long) Tsid
private QsheetEntity qsheet;

//////////////////////////////////////////////////////////////////////////

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package lab.cherry.nw.repository;

import lab.cherry.nw.model.BoardEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;

import org.springframework.data.mongodb.repository.Query;
import java.util.Optional;
import java.util.UUID;

Expand All @@ -19,10 +18,11 @@
public interface BoardRepository extends MongoRepository<BoardEntity, String> {

Page<BoardEntity> findAll(Pageable pageable);
@Query("{'user.$_id' : ?0}")
Page<BoardEntity> findPageByUserid(String userid, Pageable pageable);

Optional<BoardEntity> findById(String id);

@Query("{'user.$_id' : ?0}")
Optional<BoardEntity> findByuserid(String userid);
void deleteById(UUID id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
public interface BookmarkRepository extends MongoRepository<BookmarkEntity, String> {

Page<BookmarkEntity> findAll(Pageable pageable);


@Query("{'user.$_id' : ?0}")
Page<BookmarkEntity> findPageByUserid(String userid, Pageable pageable);

Optional<BookmarkEntity> findById(String id);

@Query("{'userid.$id' : ?0}")
Optional<BookmarkEntity> findByUserid(ObjectId userId);
@Query("{'user.$_id' : ?0}")
Optional<BookmarkEntity> findByUserid(ObjectId userSeq);


void deleteById(UUID id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package lab.cherry.nw.repository;

import java.util.Optional;
import org.bson.types.ObjectId;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import lab.cherry.nw.model.BookmarkEntity;

import lab.cherry.nw.model.EventEntity;

/**
Expand Down
13 changes: 13 additions & 0 deletions nw/src/main/java/lab/cherry/nw/repository/QsheetLogRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package lab.cherry.nw.repository;

import java.util.List;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import lab.cherry.nw.model.QsheetLogEntity;


public interface QsheetLogRepository extends MongoRepository<QsheetLogEntity, String> {
@Query("{'qsheet.$_id' : ?0}")
List<QsheetLogEntity> findByQsheetId(ObjectId qsheetId);
}
Loading

0 comments on commit 959ff58

Please sign in to comment.