Skip to content

Commit

Permalink
Merge pull request #54 from UniBond-jijijin/fix/53-fix-letter-rooms-api
Browse files Browse the repository at this point in the history
[fix/53-fix-letter-rooms-api] 편지방 API 수정
  • Loading branch information
5jisoo authored Dec 30, 2023
2 parents 87cc86d + a525198 commit 3e0c640
Show file tree
Hide file tree
Showing 20 changed files with 1,702 additions and 34 deletions.
8 changes: 4 additions & 4 deletions unibond/BOOT-INF/classes/static/docs/disease.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ <h1>Member API</h1>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_modify_member_info">Modify Member Info</a>
<li><a href="#_search_disease_by_name">Search Disease By Name</a>
<ul class="sectlevel2">
<li><a href="#_request">Request</a></li>
<li><a href="#_response">Response</a></li>
Expand All @@ -459,10 +459,10 @@ <h1>Member API</h1>
</div>
<div id="content">
<div class="sect1">
<h2 id="_modify_member_info"><a class="link" href="#_modify_member_info">Modify Member Info</a></h2>
<h2 id="_search_disease_by_name"><a class="link" href="#_search_disease_by_name">Search Disease By Name</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>멤버 정보 수정하기</p>
<p>한글 또는 영어 이름을 통해 질병 검색하기</p>
</div>
<div class="sect2">
<h3 id="_request"><a class="link" href="#_request">Request</a></h3>
Expand Down Expand Up @@ -622,7 +622,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 2023-12-31 03:37:25 +0900
Last updated 2023-12-31 03:53:40 +0900
</div>
</div>
</body>
Expand Down
18 changes: 17 additions & 1 deletion unibond/BOOT-INF/classes/static/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ <h1>UniBond API Document</h1>
<li><a href="#_member">Member</a></li>
<li><a href="#_disease">Disease</a></li>
<li><a href="#_community">Community</a></li>
<li><a href="#_letter">Letter</a></li>
<li><a href="#_letter_rooms">Letter Rooms</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -533,13 +535,27 @@ <h3 id="_community"><a class="link" href="#_community">Community</a></h3>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_letter"><a class="link" href="#_letter">Letter</a></h3>

</div>
<div class="sect2">
<h3 id="_letter_rooms"><a class="link" href="#_letter_rooms">Letter Rooms</a></h3>
<div class="ulist">
<ul>
<li>
<p><a href="letter-rooms.html">Letter Rooms API</a></p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-12-31 03:38:04 +0900
Last updated 2023-12-31 04:06:59 +0900
</div>
</div>
</body>
Expand Down
634 changes: 634 additions & 0 deletions unibond/BOOT-INF/classes/static/docs/letter-rooms.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion unibond/BOOT-INF/classes/static/docs/member.html
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : {
"profileImage" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/c650763a-4f5d-4242-8cb1-5b6d1f130526test_profile_img.jpg",
"profileImage" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/5ee7f42a-219f-4d27-8978-cb6d1b8186edtest_profile_img.jpg",
"nickname" : "5jizzi",
"gender" : "MALE",
"diseaseName" : "1번 염색체 장완 21.3 부분의 미세결손 증후군",
Expand Down
8 changes: 7 additions & 1 deletion unibond/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ Lucy Oh;

=== Community

* link:experience-community.html[Experience Recording Community API]
* link:experience-community.html[Experience Recording Community API]

=== Letter

=== Letter Rooms

* link:letter-rooms.html[Letter Rooms API]
42 changes: 42 additions & 0 deletions unibond/src/docs/asciidoc/letter-rooms.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
= Member API
Lucy Oh;
:doctype: book
:icons: font
:source-highlighter: highlishtjs
:toc: left
:toclevels: 4
:sectlinks:

ifndef::snippets[]
:snippets: ./build/generated-snippets
endif::[]

== Get All Letter Rooms

현재 참여중인 모든 편지방 가져오기

=== Request
include::{snippets}/get_all_letter-rooms/http-request.adoc[]
include::{snippets}/get_all_letter-rooms/query-parameters.adoc[]


=== Response

include::{snippets}/get_all_letter-rooms/http-response.adoc[]
include::{snippets}/get_all_letter-rooms/request-headers.adoc[]
include::{snippets}/get_all_letter-rooms/response-fields.adoc[]

== Get All Letters in Letter Rooms

참여 중인 편지방 내부의 편지들 가져오기

=== Request
include::{snippets}/get_all_letters_in_letter-rooms/http-request.adoc[]
include::{snippets}/get_all_letters_in_letter-rooms/request-headers.adoc[]
include::{snippets}/get_all_letters_in_letter-rooms/query-parameters.adoc[]


=== Response

include::{snippets}/get_all_letters_in_letter-rooms/http-response.adoc[]
include::{snippets}/get_all_letters_in_letter-rooms/response-fields.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ChildCommentsPagingResDto {

public ChildCommentsPagingResDto(Page<Comment> commentPage) {

this.childCommentList = commentPage.stream().map(
this.childCommentList = commentPage.getContent().stream().map(
ChildCommentsDto::new
).collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SearchDiseaseResDto {

public SearchDiseaseResDto(Page<Disease> diseasePage) {
this.pageInfo = new PageInfo(diseasePage);
for (Disease disease : diseasePage.stream().toList()) {
for (Disease disease : diseasePage.getContent()) {
SearchedDisease searchedDisease = SearchedDisease.builder()
.diseaseNameKor(disease.getDiseaseNameKor())
.diseaseNameEng(disease.getDiseaseNameEng())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.unibond.unibond.letter.domain.Letter;
import com.unibond.unibond.member.domain.Member;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,10 +28,9 @@ Optional<Letter> findByReceiverAndLetterId(@Param("receiver") Member receiver,
"join fetch l.receiver " +
"join fetch l.receiver.disease " +
"where l.letterRoom.id = :letterRoom " +
"and ( (l.receiver.id = :participant and l.letterStatus = 'ARRIVED' ) " +
"or " +
"(l.sender.id = :participant))" +
"and l.status = 'ACTIVE'")
List<Letter> findLettersByLetterRoomAndReceiverOrSender(@Param("letterRoom") Long letterRoomId,
@Param("participant") Long participantId);
"and ( (l.receiver.id = :participant and l.letterStatus = 'ARRIVED' ) or (l.sender.id = :participant) )" +
"and l.status = 'ACTIVE'" +
"order by l.createdDate desc")
Page<Letter> findLettersByLetterRoomAndReceiverOrSender(@Param("letterRoom") Long letterRoomId,
@Param("participant") Long participantId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public BaseResponse<?> getAllLetterRooms(@RequestHeader("Authorization") Long lo

@GetMapping("/{letterRoomId}")
public BaseResponse<?> getAllLetters(@PathVariable("letterRoomId") Long letterRoomId,
@RequestHeader("Authorization") Long loginId) {
@RequestHeader("Authorization") Long loginId,
@PageableDefault(size = 30) Pageable pageable) {
try {
return new BaseResponse<>(letterRoomService.getAllLetters(letterRoomId, loginId));
return new BaseResponse<>(letterRoomService.getAllLetters(letterRoomId, pageable));
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.unibond.unibond.letter_room.dto;

import com.unibond.unibond.common.PageInfo;
import com.unibond.unibond.letter.domain.Letter;
import com.unibond.unibond.member.domain.Member;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -18,15 +21,16 @@ public class GetLetterRoomDetailResDto {
private String receiverName;
private String receiverDiseaseName;
private LocalDate receiverDiagnosisTiming;

private PageInfo pageInfo;
private List<LetterPreviewResDto> letterList;

public GetLetterRoomDetailResDto(Member receiver, List<Letter> letterList) {
public GetLetterRoomDetailResDto(Member receiver, Page<Letter> letterPage) {
this.receiverProfileImg = receiver.getProfileImage();
this.receiverName = receiver.getNickname();
this.receiverDiseaseName = receiver.getDisease().getDiseaseNameKor();
this.receiverDiagnosisTiming = receiver.getDiagnosisTiming();
this.letterList = letterList.stream().map(
this.pageInfo = new PageInfo(letterPage);
this.letterList = letterPage.getContent().stream().map(
LetterPreviewResDto::new
).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ public class LetterRoomService {
private final LetterRoomRepository letterRoomRepository;
private final LetterRepository letterRepository;

public GetLetterRoomDetailResDto getAllLetters(Long letterRoomId, Long loginId) throws BaseException {
public GetLetterRoomDetailResDto getAllLetters(Long letterRoomId, Pageable pageable) throws BaseException {
try {
List<Letter> letterList = letterRepository
.findLettersByLetterRoomAndReceiverOrSender(letterRoomId, loginId);
if (letterList.isEmpty()) {
Long loginId = loginInfoService.getLoginMemberId();
Page<Letter> letterPage = letterRepository
.findLettersByLetterRoomAndReceiverOrSender(letterRoomId, loginId, pageable);
if (letterPage.getContent().isEmpty()) {
throw new BaseException(INVALID_LETTER_ROOM_ID);
}
Member receiver = findAnotherParticipant(letterList.get(0), loginId);
return new GetLetterRoomDetailResDto(receiver, letterList);
Member receiver = findAnotherParticipant(letterPage.getContent().get(0), loginId);
return new GetLetterRoomDetailResDto(receiver, letterPage);
} catch (BaseException e) {
throw e;
} catch (Exception e) {
Expand Down
4 changes: 2 additions & 2 deletions unibond/src/main/resources/static/docs/disease.html
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ <h3 id="_request"><a class="link" href="#_request">Request</a></h3>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">GET /api/v1/diseases/search?lan=kor&amp;query=8%EB%B2%88+%EC%97%BC%EC%83%89%EC%B2%B4&amp;page=0 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Host: docs.api.com:8080</code></pre>
Host: localhost:8080</code></pre>
</div>
</div>
<table class="tableblock frame-all grid-all stretch">
Expand Down Expand Up @@ -622,7 +622,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 2023-12-31 03:39:38 +0900
Last updated 2023-12-31 03:53:40 +0900
</div>
</div>
</body>
Expand Down
18 changes: 17 additions & 1 deletion unibond/src/main/resources/static/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ <h1>UniBond API Document</h1>
<li><a href="#_member">Member</a></li>
<li><a href="#_disease">Disease</a></li>
<li><a href="#_community">Community</a></li>
<li><a href="#_letter">Letter</a></li>
<li><a href="#_letter_rooms">Letter Rooms</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -533,13 +535,27 @@ <h3 id="_community"><a class="link" href="#_community">Community</a></h3>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_letter"><a class="link" href="#_letter">Letter</a></h3>

</div>
<div class="sect2">
<h3 id="_letter_rooms"><a class="link" href="#_letter_rooms">Letter Rooms</a></h3>
<div class="ulist">
<ul>
<li>
<p><a href="letter-rooms.html">Letter Rooms API</a></p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-12-31 03:38:04 +0900
Last updated 2023-12-31 04:06:59 +0900
</div>
</div>
</body>
Expand Down
Loading

0 comments on commit 3e0c640

Please sign in to comment.