-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
31 changed files
with
1,526 additions
and
9 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
src/main/java/com/nooblol/board/controller/ArticleController.java
This file contains 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,114 @@ | ||
package com.nooblol.board.controller; | ||
|
||
import com.nooblol.board.dto.ArticleDto; | ||
import com.nooblol.board.dto.ArticleInsertRequestDto; | ||
import com.nooblol.board.dto.ArticleUpdateRequestDto; | ||
import com.nooblol.board.service.ArticleService; | ||
import com.nooblol.global.annotation.UserLoginCheck; | ||
import com.nooblol.global.dto.ResponseDto; | ||
import com.nooblol.global.utils.ResponseUtils; | ||
import com.nooblol.global.utils.SessionUtils; | ||
import javax.servlet.http.HttpSession; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/article") | ||
@RequiredArgsConstructor | ||
public class ArticleController { | ||
|
||
private final ArticleService articleService; | ||
|
||
/** | ||
* articleId의 게시물 정보와 현재 요청한 사용자의 권한을 같이 Return한다 Session에 로그인정보가 없는 경우에는 게시물에 대한 정보 수정을 주는 권한을 | ||
* Guest로 설정한다 | ||
* | ||
* @param articleId | ||
* @param session | ||
* @return | ||
*/ | ||
@GetMapping("/{articleId}") | ||
public ResponseDto getArticle( | ||
@PathVariable int articleId, HttpSession session | ||
) { | ||
ArticleDto article = articleService.getArticleInfo( | ||
articleId, SessionUtils.getSessionUserId(session) | ||
); | ||
|
||
return ResponseUtils.makeToResponseOkDto(article); | ||
} | ||
|
||
/** | ||
* 게시물 등록 | ||
* | ||
* @param articleDto | ||
* @return | ||
*/ | ||
@UserLoginCheck | ||
@PostMapping("/") | ||
public ResponseDto insertArticle( | ||
@Valid @RequestBody ArticleInsertRequestDto articleDto, HttpSession session | ||
) { | ||
ArticleDto upsertArticle = new ArticleDto().builder() | ||
.bbsId(articleDto.getBbsId()) | ||
.articleTitle(articleDto.getArticleTitle()) | ||
.articleContent(articleDto.getArticleContent()) | ||
.articleReadCount(articleDto.getArticleReadCount()) | ||
.status(articleDto.getStatus()) | ||
.createdUserId(SessionUtils.getSessionUserId(session)) | ||
.createdAt(articleDto.getCreatedAt()) | ||
.updatedAt(articleDto.getUpdatedAt()) | ||
.build(); | ||
|
||
boolean upsertResult = articleService.upsertArticle(upsertArticle, session, true); | ||
|
||
return ResponseUtils.makeToResponseOkDto(upsertResult); | ||
} | ||
|
||
/** | ||
* 게시물 수정 | ||
* | ||
* @param articleDto | ||
* @return | ||
*/ | ||
@UserLoginCheck | ||
@PutMapping("/") | ||
public ResponseDto updateArticle( | ||
@Valid @RequestBody ArticleUpdateRequestDto articleDto, HttpSession session | ||
) { | ||
ArticleDto upsertArticle = new ArticleDto().builder() | ||
.articleId(articleDto.getArticleId()) | ||
.bbsId(articleDto.getBbsId()) | ||
.articleTitle(articleDto.getArticleTitle()) | ||
.articleContent(articleDto.getArticleContent()) | ||
.status(articleDto.getStatus()) | ||
.build(); | ||
|
||
boolean upsertResult = articleService.upsertArticle(upsertArticle, session, false); | ||
|
||
return ResponseUtils.makeToResponseOkDto(upsertResult); | ||
} | ||
|
||
/** | ||
* 게시물 삭제 | ||
* | ||
* @param articleId | ||
* @param session | ||
* @return | ||
*/ | ||
@UserLoginCheck | ||
@DeleteMapping("/{articleId}") | ||
public ResponseDto deleteArticle(@PathVariable int articleId, HttpSession session) { | ||
return ResponseUtils.makeToResponseOkDto(articleService.deleteArticle(articleId, session)); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/nooblol/board/controller/ArticleStatusController.java
This file contains 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,61 @@ | ||
package com.nooblol.board.controller; | ||
|
||
import com.nooblol.board.service.ArticleStatusService; | ||
import com.nooblol.global.annotation.UserLoginCheck; | ||
import com.nooblol.global.dto.ResponseDto; | ||
import com.nooblol.global.utils.ResponseUtils; | ||
import javax.servlet.http.HttpSession; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/article/status") | ||
@RequiredArgsConstructor | ||
public class ArticleStatusController { | ||
|
||
private final ArticleStatusService articleStatusService; | ||
|
||
/** | ||
* 파라미터로 제공한 게시물의 추천, 비추천 갯수를 Return한다 | ||
* | ||
* @param articleId | ||
* @return | ||
*/ | ||
@GetMapping("/{articleId}") | ||
public ResponseDto likeAndNotLikeArticle(@PathVariable int articleId) { | ||
return ResponseUtils.makeToResponseOkDto(articleStatusService.likeAndNotListStatus(articleId)); | ||
} | ||
|
||
/** | ||
* 게시물 추천 | ||
* | ||
* @param articleId | ||
* @param session | ||
* @return | ||
*/ | ||
@UserLoginCheck | ||
@PostMapping("/like/{articleId}") | ||
public ResponseDto likeArticle(@PathVariable int articleId, HttpSession session) { | ||
return ResponseUtils.makeToResponseOkDto(articleStatusService.likeArticle(articleId, session)); | ||
} | ||
|
||
/** | ||
* 게시물 비추천 | ||
* | ||
* @param articleId | ||
* @param session | ||
* @return | ||
*/ | ||
@UserLoginCheck | ||
@PostMapping("/notLike/{articleId}") | ||
public ResponseDto notLikeArticle(@PathVariable int articleId, HttpSession session) { | ||
return ResponseUtils.makeToResponseOkDto( | ||
articleStatusService.notLikeArticle(articleId, session)); | ||
} | ||
} |
This file contains 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.nooblol.board.dto; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ArticleDto { | ||
|
||
/* | ||
Integer로 변경하는 이유는 기본값 0이 들어감으로 인해서 Mybatis에서 NullCheck를 못하는 경우를 제외하기 위해 변경 | ||
*/ | ||
|
||
private Integer articleId; | ||
private Integer bbsId; | ||
private String articleTitle; | ||
private int articleReadCount; | ||
private String articleContent; | ||
private Integer status; | ||
private String createdUserId; | ||
private LocalDateTime createdAt; | ||
private LocalDateTime updatedAt; | ||
private String authMessage; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/nooblol/board/dto/ArticleInsertRequestDto.java
This file contains 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.nooblol.board.dto; | ||
|
||
import java.time.LocalDateTime; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ArticleInsertRequestDto extends ArticleRequestBaseDto { | ||
|
||
private String createdUserId; | ||
private Integer articleReadCount = 0; | ||
private LocalDateTime createdAt = LocalDateTime.now(); | ||
private LocalDateTime updatedAt = LocalDateTime.now(); | ||
} | ||
|
29 changes: 29 additions & 0 deletions
29
src/main/java/com/nooblol/board/dto/ArticleRequestBaseDto.java
This file contains 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,29 @@ | ||
package com.nooblol.board.dto; | ||
|
||
|
||
import com.nooblol.board.utils.ArticleMessage; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ArticleRequestBaseDto { | ||
|
||
@NotNull(message = ArticleMessage.BBS_ID_NULL) | ||
private Integer bbsId; | ||
|
||
@NotBlank(message = ArticleMessage.ARTICLE_TITLE_NULL) | ||
private String articleTitle; | ||
|
||
@NotBlank(message = ArticleMessage.ARTICLE_CONTENT_NULL) | ||
private String articleContent; | ||
|
||
@NotNull(message = ArticleMessage.ARTICLE_STATUS_NULL) | ||
private Integer status; | ||
} |
This file contains 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,26 @@ | ||
package com.nooblol.board.dto; | ||
|
||
import com.nooblol.board.utils.ArticleLikeStatusEnum; | ||
import com.nooblol.board.utils.ArticleStatusEnum; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ArticleStatusDto { | ||
|
||
private int articleId; | ||
|
||
private String userId; | ||
|
||
private ArticleLikeStatusEnum likeType; | ||
|
||
private LocalDateTime createdAt = LocalDateTime.now(); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/nooblol/board/dto/ArticleUpdateRequestDto.java
This file contains 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,25 @@ | ||
package com.nooblol.board.dto; | ||
|
||
import com.nooblol.board.utils.ArticleMessage; | ||
import java.time.LocalDateTime; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ArticleUpdateRequestDto extends ArticleRequestBaseDto { | ||
|
||
@NotNull(message = ArticleMessage.ARTICLE_ID_NULL) | ||
private Integer articleId; | ||
|
||
|
||
private LocalDateTime updatedAt = LocalDateTime.now(); | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
src/main/java/com/nooblol/board/dto/LikeAndNotLikeResponseDto.java
This file contains 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,19 @@ | ||
package com.nooblol.board.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class LikeAndNotLikeResponseDto { | ||
|
||
private int likeCnt; | ||
private int notLikeCnt; | ||
|
||
} |
This file contains 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,22 @@ | ||
package com.nooblol.board.mapper; | ||
|
||
import com.nooblol.board.dto.ArticleDto; | ||
import com.nooblol.board.dto.ArticleStatusDto; | ||
import com.nooblol.board.dto.LikeAndNotLikeResponseDto; | ||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
@Mapper | ||
public interface ArticleMapper { | ||
|
||
ArticleDto selectArticleByArticleId(int articleId); | ||
|
||
void addReadCount(int articleId); | ||
|
||
int selectUserAuth(String userId); | ||
|
||
int upsertArticle(ArticleDto articleDto); | ||
|
||
String selectCreatedUserId(int articleId); | ||
|
||
int deleteArticleByArticleId(int articleId); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/nooblol/board/mapper/ArticleStatusMapper.java
This file contains 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,18 @@ | ||
package com.nooblol.board.mapper; | ||
|
||
import com.nooblol.board.dto.ArticleStatusDto; | ||
import com.nooblol.board.dto.LikeAndNotLikeResponseDto; | ||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
@Mapper | ||
public interface ArticleStatusMapper { | ||
|
||
ArticleStatusDto selectArticleStatusByArticleIdAndUserId(ArticleStatusDto articleStatusDto); | ||
|
||
LikeAndNotLikeResponseDto selectArticleAllStatusByArticleId(int articleId); | ||
|
||
int insertArticleStatus(ArticleStatusDto articleStatusDto); | ||
|
||
int deleteArticleStatus(ArticleStatusDto articleStatusDto); | ||
|
||
} |
Oops, something went wrong.