Skip to content

Commit

Permalink
Merge pull request #65 from UniBond-jijijin/feature/4-experience-v1-api
Browse files Browse the repository at this point in the history
[feature/4-experience-v1-api]
  • Loading branch information
5jisoo authored Jan 9, 2024
2 parents 9e8a705 + 301d715 commit 2c91e3d
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ <h3 id="_response_2"><a class="link" href="#_response_2">Response</a></h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-01-08 20:48:26 +0900
Last updated 2024-01-08 21:14:50 +0900
</div>
</div>
</body>
Expand Down
12 changes: 9 additions & 3 deletions unibond/BOOT-INF/classes/static/docs/letter-rooms.html
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,20 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 1248
Content-Length: 1599

{
"isSuccess" : true,
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : {
"letterRoomList" : [ {
"senderProfileImg" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/025cc515-c832-4c29-9fe0-9e77f0afea7d6808929_emoji_emoticon_emotion_expression_face_icon.png",
"senderNick" : "서울의가을",
"senderId" : 28,
"recentLetterSentDate" : "2024-01-08T19:33:37.078678",
"letterRoomId" : 12
}, {
"senderProfileImg" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/3b6fc68f-808c-4e22-97e8-9447d6916bc5cat-2068462_640.jpg",
"senderNick" : "눈송이네 베이킹",
"senderId" : 30,
Expand All @@ -538,10 +544,10 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
"letterRoomId" : 18
} ],
"pageInfo" : {
"numberOfElements" : 3,
"numberOfElements" : 4,
"lastPage" : true,
"totalPages" : 1,
"totalElements" : 3,
"totalElements" : 4,
"size" : 30
}
}
Expand Down
4 changes: 2 additions & 2 deletions unibond/BOOT-INF/classes/static/docs/member.html
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
"isSuccess" : true,
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : 65
"result" : 68
}</code></pre>
</div>
</div>
Expand Down Expand Up @@ -1436,7 +1436,7 @@ <h3 id="_response_5"><a class="link" href="#_response_5">Response</a></h3>
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : {
"profileImage" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/dc45f826-fb80-46d9-9121-ae0a0816a9e4test_profile_img.jpg",
"profileImage" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/00f348b2-0669-4007-a6ff-6e4129b71023test_profile_img.jpg",
"nickname" : "병원장",
"gender" : "MALE",
"diseaseName" : "1번 염색체 장완 21.3 부분의 미세결손 증후군",
Expand Down
19 changes: 15 additions & 4 deletions unibond/BOOT-INF/classes/static/docs/question-community.html
Original file line number Diff line number Diff line change
Expand Up @@ -517,18 +517,18 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 1437
Content-Length: 2067

{
"isSuccess" : true,
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : {
"pageInfo" : {
"numberOfElements" : 2,
"numberOfElements" : 3,
"lastPage" : true,
"totalPages" : 1,
"totalElements" : 2,
"totalElements" : 3,
"size" : 30
},
"postPreviewList" : [ {
Expand All @@ -542,6 +542,17 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
"contentPreview" : "급하게 친구들끼리 여행을 가게 될 일이 생겼어요. 사실 이동하는 게 많이 어려워서",
"boardType" : "QNA",
"isEnd" : false
}, {
"createdDate" : "2023-11-12T00:57:12.641472",
"ownerId" : 28,
"ownerProfileImg" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/025cc515-c832-4c29-9fe0-9e77f0afea7d6808929_emoji_emoticon_emotion_expression_face_icon.png",
"ownerNick" : "서울의가을",
"disease" : "10번 염색체 장완 말단부의 단일염색체증",
"postId" : 62,
"postImg" : null,
"contentPreview" : "학교에 다니면서 친구들한테 어떻게 이 병에 대해 솔직하게 털어놨는지 다들 계기가 ",
"boardType" : "QNA",
"isEnd" : false
}, {
"createdDate" : "2023-10-03T00:41:51.650698",
"ownerId" : 30,
Expand Down Expand Up @@ -686,7 +697,7 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-01-08 20:49:25 +0900
Last updated 2024-01-08 21:14:50 +0900
</div>
</div>
</body>
Expand Down
20 changes: 18 additions & 2 deletions unibond/src/docs/asciidoc/experience-community.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,25 @@ include::{snippets}/get-experience-community/query-parameters.adoc[]
include::{snippets}/get-experience-community/http-response.adoc[]
include::{snippets}/get-experience-community/response-fields.adoc[]

== Upload Posts on Experience Community
== Upload Posts on Experience Community- V1

경험 기록 게시판에 게시물 업로드하기
경험 기록 게시판에 게시물 업로드하기 (v1)

=== Request

include::{snippets}/post-experience-community_v1/http-request.adoc[]

include::{snippets}/post-experience-community_v1/request-headers.adoc[]
include::{snippets}/post-experience-community_v1/request-fields.adoc[]

=== Response

include::{snippets}/post-experience-community/http-response.adoc[]
include::{snippets}/post-experience-community/response-fields.adoc[]

== Upload Posts on Experience Community- V2

경험 기록 게시판에 게시물 업로드하기 (v2)

=== Request

Expand Down
2 changes: 1 addition & 1 deletion unibond/src/docs/asciidoc/question-community.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Experience Community API
= Q&A Community API
Lucy Oh;
:doctype: book
:icons: font
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,33 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/community/experience")
public class ExperiencePostController {
private final PostService postService;

@PostMapping(value = "", consumes = {APPLICATION_JSON_VALUE, MULTIPART_FORM_DATA_VALUE})
@PostMapping(value = "/api/v1/community/experience")
public BaseResponse<?> createPost(@RequestHeader("Authorization") Long loginId,
@RequestBody PostUploadReqDto request) {
try {
postService.createPost(request, EXPERIENCE);
return new BaseResponse<>(SUCCESS);
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

@PostMapping(value = "/api/v2/community/experience", consumes = {APPLICATION_JSON_VALUE, MULTIPART_FORM_DATA_VALUE})
public BaseResponse<?> createPost(@RequestHeader("Authorization") Long loginId,
@RequestPart MultipartFile postImg,
@RequestPart PostUploadReqDto request) {
try {
request.setBoardType(EXPERIENCE);
postService.createPost(request, postImg);
return new BaseResponse<>(SUCCESS);
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

@GetMapping("")
@GetMapping("/api/v1/community/experience")
public BaseResponse<?> getExperienceCommunityPosts(@PageableDefault(size = 30) Pageable pageable) {
try {
return new BaseResponse<>(postService.getCommunityContent(EXPERIENCE, pageable));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class QuestionPostController {
public BaseResponse<?> createPost(@RequestHeader("Authorization") Long loginId,
@RequestBody PostUploadReqDto reqDto) {
try {
reqDto.setBoardType(QNA);
postService.createPost(reqDto, null);
postService.createPost(reqDto, QNA);
return new BaseResponse<>(SUCCESS);
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@
import com.unibond.unibond.post.domain.BoardType;
import com.unibond.unibond.post.domain.Post;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.unibond.unibond.post.domain.BoardType.EXPERIENCE;
import static com.unibond.unibond.post.domain.BoardType.QNA;

@Data
@NoArgsConstructor
public class PostUploadReqDto {
private String content;

// null
private Member owner;
private BoardType boardType;

public Post toEntity(Member owner, String postImgUrl) {
this.owner = owner;
public Post toEntity(Member owner, BoardType boardType, String postImgUrl) {
if (boardType.equals(QNA)) {
return createQNAPost();
return createQNAPost(owner);
} else {
return createExperiencePost(postImgUrl);
return createExperiencePost(owner, postImgUrl);
}
}

private Post createQNAPost() {
private Post createQNAPost(Member owner) {
return Post.createQnAPost()
.owner(owner)
.boardType(boardType)
.boardType(QNA)
.content(content)
.build();
}

private Post createExperiencePost(String postImgUrl) {
private Post createExperiencePost(Member owner, String postImgUrl) {
return Post.createExperiencePost()
.owner(owner)
.boardType(boardType)
.boardType(EXPERIENCE)
.content(content)
.postImageUrl(postImgUrl)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.web.multipart.MultipartFile;

import static com.unibond.unibond.common.BaseResponseStatus.*;
import static com.unibond.unibond.post.domain.BoardType.EXPERIENCE;

@Service
@RequiredArgsConstructor
Expand All @@ -33,6 +34,19 @@ public class PostService {
private final PostBlockRepository postBlockRepository;
private final CommentRepository commentRepository;

@Transactional
public void createPost(PostUploadReqDto reqDto, BoardType boardType) throws BaseException {
try {
Member loginMember = loginInfoService.getLoginMember();
Post newPost = reqDto.toEntity(loginMember, boardType, null);
postRepository.save(newPost);
} catch (BaseException e) {
throw e;
} catch (Exception e) {
throw new BaseException(DATABASE_ERROR);
}
}

@Transactional
public void createPost(PostUploadReqDto reqDto, MultipartFile multipartFile) throws BaseException {
try {
Expand All @@ -41,7 +55,7 @@ public void createPost(PostUploadReqDto reqDto, MultipartFile multipartFile) thr
if (multipartFile != null) {
imgUrl = s3Uploader.upload(multipartFile, "post");
}
Post newPost = reqDto.toEntity(loginMember, imgUrl);
Post newPost = reqDto.toEntity(loginMember, EXPERIENCE, imgUrl);
postRepository.save(newPost);
} catch (BaseException e) {
throw e;
Expand Down
Loading

0 comments on commit 2c91e3d

Please sign in to comment.