Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -44,55 +43,55 @@ public class ArtistStatementController {
public BaseResponse<GetArtistStatementRes> getArtistStatement(@PathVariable("userIdx") int userIdx) {
try {

GetArtistStatementRes getArtistStatementRes = artistStatementProvider.retrieveStatement(userIdx);
GetArtistStatementRes getArtistStatementRes = artistStatementService.retrieveStatement(userIdx);
return new BaseResponse<>(getArtistStatementRes);

} 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<PostArtistStatementRes> 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<PostArtistStatementRes> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);

}
}

}