From 51a354d4db4fc6c6d97f59f7d23b28e26ac1c405 Mon Sep 17 00:00:00 2001 From: s-yeong Date: Fri, 23 Sep 2022 07:02:33 +0900 Subject: [PATCH] =?UTF-8?q?FEAT:=20=EC=9E=91=EA=B0=80=EB=85=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EC=97=86=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20default=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArtistStatementController.java | 85 +++++++++---------- .../artistStatement/ArtistStatementDao.java | 12 +++ .../ArtistStatementProvider.java | 43 ---------- .../ArtistStatementService.java | 73 ++++++++++++---- 4 files changed, 111 insertions(+), 102 deletions(-) delete mode 100644 src/main/java/com/there/src/artistStatement/ArtistStatementProvider.java diff --git a/src/main/java/com/there/src/artistStatement/ArtistStatementController.java b/src/main/java/com/there/src/artistStatement/ArtistStatementController.java index a1d3429..e3a32da 100644 --- a/src/main/java/com/there/src/artistStatement/ArtistStatementController.java +++ b/src/main/java/com/there/src/artistStatement/ArtistStatementController.java @@ -25,7 +25,6 @@ public class ArtistStatementController { final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final ArtistStatementProvider artistStatementProvider; private final ArtistStatementService artistStatementService; private final JwtService jwtService; @@ -44,7 +43,7 @@ public class ArtistStatementController { public BaseResponse getArtistStatement(@PathVariable("userIdx") int userIdx) { try { - GetArtistStatementRes getArtistStatementRes = artistStatementProvider.retrieveStatement(userIdx); + GetArtistStatementRes getArtistStatementRes = artistStatementService.retrieveStatement(userIdx); return new BaseResponse<>(getArtistStatementRes); } catch (BaseException exception) { @@ -52,47 +51,47 @@ public BaseResponse getArtistStatement(@PathVariable("use } } - /** - * 작가노트 작성 API - * [POST] /statements/users/:userIdx - */ - @ApiOperation(value="작가노트 작성 API", notes="유저의 작가노트를 작성합니다.") - @ApiResponses({ - @ApiResponse(code = 1000, message = "요청에 성공하였습니다."), - @ApiResponse(code = 2003, message = "권한이 없는 유저의 접근입니다."), - @ApiResponse(code = 2110, message = "이미 작성된 작가노트가 있습니다."), - @ApiResponse(code = 2111, message = "자기소개 글자 수를 확인해주세요."), - @ApiResponse(code = 2112, message = "추구하는 작품 소개 글자 수를 확인해주세요."), - @ApiResponse(code = 2113, message = "연락처 글자 수를 확인해주세요."), - @ApiResponse(code = 4000, message = "데이터베이스 연결에 실패하였습니다.") - }) - @ResponseBody - @PostMapping("/users/{userIdx}") - public BaseResponse createArtistStatement(@PathVariable("userIdx") int userIdx, - @RequestBody PostArtistStatementReq postArtistStatementReq) { - try { - - int userIdxByJwt = jwtService.getUserIdx1(jwtService.getJwt()); - if (userIdxByJwt != userIdx) return new BaseResponse<>(INVALID_USER_JWT); - - if(postArtistStatementReq.getSelfIntroduction().length() > 300) { - return new BaseResponse<>(STATEMENTS_INVALID_SELFINTRO); - } - - if(postArtistStatementReq.getWorkIntroduction().length() > 300) { - return new BaseResponse<>(STATEMENTS_INVALID_WORKINTRO); - } - - if(postArtistStatementReq.getContact().length() > 50) { - return new BaseResponse<>(STATEMENTS_INVALID_CONTACT); - } - PostArtistStatementRes postArtistStatementRes = artistStatementService.createStatement(userIdx, postArtistStatementReq); - return new BaseResponse<>(postArtistStatementRes); - - } catch (BaseException exception) { - return new BaseResponse<>((exception.getStatus())); - } - } +// /** +// * 작가노트 작성 API +// * [POST] /statements/users/:userIdx +// */ +// @ApiOperation(value="작가노트 작성 API", notes="유저의 작가노트를 작성합니다.") +// @ApiResponses({ +// @ApiResponse(code = 1000, message = "요청에 성공하였습니다."), +// @ApiResponse(code = 2003, message = "권한이 없는 유저의 접근입니다."), +// @ApiResponse(code = 2110, message = "이미 작성된 작가노트가 있습니다."), +// @ApiResponse(code = 2111, message = "자기소개 글자 수를 확인해주세요."), +// @ApiResponse(code = 2112, message = "추구하는 작품 소개 글자 수를 확인해주세요."), +// @ApiResponse(code = 2113, message = "연락처 글자 수를 확인해주세요."), +// @ApiResponse(code = 4000, message = "데이터베이스 연결에 실패하였습니다.") +// }) +// @ResponseBody +// @PostMapping("/users/{userIdx}") +// public BaseResponse createArtistStatement(@PathVariable("userIdx") int userIdx, +// @RequestBody PostArtistStatementReq postArtistStatementReq) { +// try { +// +// int userIdxByJwt = jwtService.getUserIdx1(jwtService.getJwt()); +// if (userIdxByJwt != userIdx) return new BaseResponse<>(INVALID_USER_JWT); +// +// if(postArtistStatementReq.getSelfIntroduction().length() > 300) { +// return new BaseResponse<>(STATEMENTS_INVALID_SELFINTRO); +// } +// +// if(postArtistStatementReq.getWorkIntroduction().length() > 300) { +// return new BaseResponse<>(STATEMENTS_INVALID_WORKINTRO); +// } +// +// if(postArtistStatementReq.getContact().length() > 50) { +// return new BaseResponse<>(STATEMENTS_INVALID_CONTACT); +// } +// PostArtistStatementRes postArtistStatementRes = artistStatementService.createStatement(userIdx, postArtistStatementReq); +// return new BaseResponse<>(postArtistStatementRes); +// +// } catch (BaseException exception) { +// return new BaseResponse<>((exception.getStatus())); +// } +// } /** * 작가노트 수정 API diff --git a/src/main/java/com/there/src/artistStatement/ArtistStatementDao.java b/src/main/java/com/there/src/artistStatement/ArtistStatementDao.java index 7ca7c25..2613e0c 100644 --- a/src/main/java/com/there/src/artistStatement/ArtistStatementDao.java +++ b/src/main/java/com/there/src/artistStatement/ArtistStatementDao.java @@ -97,4 +97,16 @@ public int deleteStatement(int userIdx) { return this.jdbcTemplate.update(deleteStatementQuery, deleteStatementParam); } + // 작가노트 defulat 생성 + public int insertDefaultStatement(int userIdx) { + String insertDefaultStatementQuery = "insert ArtistStatement(userIdx) values(?);"; + int insertDefaultStatementParam = userIdx; + + this.jdbcTemplate.update(insertDefaultStatementQuery, + insertDefaultStatementParam); + + String lastInsertIdxQuery = "select last_insert_id()"; + return this.jdbcTemplate.queryForObject(lastInsertIdxQuery, int.class); + + } } diff --git a/src/main/java/com/there/src/artistStatement/ArtistStatementProvider.java b/src/main/java/com/there/src/artistStatement/ArtistStatementProvider.java deleted file mode 100644 index 2c76ae8..0000000 --- a/src/main/java/com/there/src/artistStatement/ArtistStatementProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.there.src.artistStatement; - -import com.there.config.BaseException; -import com.there.src.artistStatement.model.GetArtistStatementRes; -import lombok.RequiredArgsConstructor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import static com.there.config.BaseResponseStatus.DATABASE_ERROR; - -@Service -@RequiredArgsConstructor -public class ArtistStatementProvider { - - private final ArtistStatementDao artistStatementDao; - - final Logger logger = LoggerFactory.getLogger(this.getClass()); - - - // 작가노트 조회 - public GetArtistStatementRes retrieveStatement(int userIdx) throws BaseException { - try { - GetArtistStatementRes getArtistStatementRes = artistStatementDao.selectStatement(userIdx); - return getArtistStatementRes; - - } catch (Exception exception) { - throw new BaseException(DATABASE_ERROR); - } - } - - - // 작가노트 체크 - public int checkStatementExist(int userIdx) throws BaseException { - try { - return artistStatementDao.checkStatementExist(userIdx); - - } catch (Exception exception) { - throw new BaseException(DATABASE_ERROR); - } - } - -} diff --git a/src/main/java/com/there/src/artistStatement/ArtistStatementService.java b/src/main/java/com/there/src/artistStatement/ArtistStatementService.java index ad70406..b985cb0 100644 --- a/src/main/java/com/there/src/artistStatement/ArtistStatementService.java +++ b/src/main/java/com/there/src/artistStatement/ArtistStatementService.java @@ -1,6 +1,7 @@ package com.there.src.artistStatement; import com.there.config.BaseException; +import com.there.src.artistStatement.model.GetArtistStatementRes; import com.there.src.artistStatement.model.PatchArtistStatementReq; import com.there.src.artistStatement.model.PostArtistStatementReq; import com.there.src.artistStatement.model.PostArtistStatementRes; @@ -22,33 +23,49 @@ public class ArtistStatementService { final Logger logger = LoggerFactory.getLogger(this.getClass()); private final ArtistStatementDao artistStatementDao; - private final ArtistStatementProvider artistStatementProvider; + // 작가노트 조회 + public GetArtistStatementRes retrieveStatement(int userIdx) throws BaseException { + try { + if(checkStatementExist(userIdx) == 0) { + createDefaultStatement(userIdx); + } - // 작가노트 작성 - public PostArtistStatementRes createStatement(int userIdx, PostArtistStatementReq postArtistStatementReq) - throws BaseException { - - if(artistStatementProvider.checkStatementExist(userIdx) == 1){ - throw new BaseException(STATEMENTS_EXIST); - } + GetArtistStatementRes getArtistStatementRes = artistStatementDao.selectStatement(userIdx); - try{ + return getArtistStatementRes; - int statementIdx = artistStatementDao.insertStatement(userIdx, postArtistStatementReq); - return new PostArtistStatementRes(statementIdx); - } - catch (Exception exception) { + } catch (Exception exception) { + System.out.println(exception); throw new BaseException(DATABASE_ERROR); - } } + + // 작가노트 작성 +// public PostArtistStatementRes createStatement(int userIdx, PostArtistStatementReq postArtistStatementReq) +// throws BaseException { +// +// if(artistStatementProvider.checkStatementExist(userIdx) == 1){ +// throw new BaseException(STATEMENTS_EXIST); +// } +// +// try{ +// +// int statementIdx = artistStatementDao.insertStatement(userIdx, postArtistStatementReq); +// return new PostArtistStatementRes(statementIdx); +// } +// catch (Exception exception) { +// throw new BaseException(DATABASE_ERROR); +// +// } +// } + // 작가노트 수정 public void modifyStatement(int userIdx, PatchArtistStatementReq patchArtistStatementReq) throws BaseException { - if(artistStatementProvider.checkStatementExist(userIdx) == 0) { + if(checkStatementExist(userIdx) == 0) { throw new BaseException(STATEMENTS_EMPTY); } @@ -81,7 +98,7 @@ public void modifyStatement(int userIdx, PatchArtistStatementReq patchArtistStat // 작가노트 삭제 public void deleteStatement(int userIdx) throws BaseException{ - if(artistStatementProvider.checkStatementExist(userIdx) == 0) { + if(checkStatementExist(userIdx) == 0) { throw new BaseException(STATEMENTS_EMPTY); } @@ -97,5 +114,29 @@ public void deleteStatement(int userIdx) throws BaseException{ } } + // 작가노트 체크 + public int checkStatementExist(int userIdx) throws BaseException { + try { + return artistStatementDao.checkStatementExist(userIdx); + + } catch (Exception exception) { + throw new BaseException(DATABASE_ERROR); + } + } + + // 작가노트 default 생성 + public int createDefaultStatement(int userIdx) + throws BaseException { + + try{ + + int statementIdx = artistStatementDao.insertDefaultStatement(userIdx); + return statementIdx; + } + catch (Exception exception) { + throw new BaseException(DATABASE_ERROR); + + } + } } \ No newline at end of file