-
Notifications
You must be signed in to change notification settings - Fork 0
링크 조회 API 및 링크 목록 조회 API 응답 개선 #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/sofa/linkiving/domain/link/dto/internal/LinkDto.java
This file contains hidden or 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,10 @@ | ||
| package com.sofa.linkiving.domain.link.dto.internal; | ||
|
|
||
| import com.sofa.linkiving.domain.link.entity.Link; | ||
| import com.sofa.linkiving.domain.link.entity.Summary; | ||
|
|
||
| public record LinkDto( | ||
| Link link, | ||
| Summary summary | ||
minibr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) { | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
src/main/java/com/sofa/linkiving/domain/link/dto/internal/LinksDto.java
This file contains hidden or 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,10 @@ | ||
| package com.sofa.linkiving.domain.link.dto.internal; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record LinksDto( | ||
| List<LinkDto> linkDtos, | ||
| boolean hasNext | ||
| ) { | ||
| } | ||
|
|
2 changes: 1 addition & 1 deletion
2
...a/linkiving/domain/link/dto/OgTagDto.java → ...ng/domain/link/dto/internal/OgTagDto.java
This file contains hidden or 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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/sofa/linkiving/domain/link/dto/response/LinkCardsRes.java
This file contains hidden or 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,57 @@ | ||
| package com.sofa.linkiving.domain.link.dto.response; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.sofa.linkiving.domain.link.dto.internal.LinkDto; | ||
| import com.sofa.linkiving.domain.link.dto.internal.LinksDto; | ||
| import com.sofa.linkiving.domain.link.entity.Link; | ||
| import com.sofa.linkiving.domain.link.entity.Summary; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record LinkCardsRes( | ||
| @Schema(description = "링크 목록") | ||
| List<LinkCardRes> links, | ||
| @Schema(description = "다음 페이지 존재 여부") | ||
| boolean hasNext, | ||
| @Schema(description = "마지막 메시지 ID (다음 요청 커서용)") | ||
| Long lastId | ||
| ) { | ||
| public static LinkCardsRes of(LinksDto linksDto) { | ||
| List<LinkCardRes> links = linksDto.linkDtos().stream().map(LinkCardRes::from).toList(); | ||
| Long lastId = links.isEmpty() ? null : links.get(links.size() - 1).id(); | ||
|
|
||
| return new LinkCardsRes(links, linksDto.hasNext(), lastId); | ||
| } | ||
|
|
||
| public record LinkCardRes( | ||
| @Schema(description = "링크 ID") | ||
| Long id, | ||
|
|
||
| @Schema(description = "링크 URL", example = "https://example.com") | ||
| String url, | ||
|
|
||
| @Schema(description = "링크 제목", example = "유용한 개발 자료") | ||
| String title, | ||
|
|
||
| @Schema(description = "이미지 URL", example = "https://example.com/image.jpg") | ||
| String imageUrl, | ||
|
|
||
| @Schema(description = "요약 정보") | ||
| String summary | ||
| ) { | ||
| public static LinkCardRes from(LinkDto dto) { | ||
| return of(dto.link(), dto.summary()); | ||
| } | ||
|
|
||
| public static LinkCardRes of(Link link, Summary summary) { | ||
| return new LinkCardRes( | ||
| link.getId(), | ||
| link.getUrl(), | ||
| link.getTitle(), | ||
| link.getImageUrl(), | ||
| summary == null ? null : summary.getContent() | ||
| ); | ||
| } | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/sofa/linkiving/domain/link/dto/response/LinkDetailRes.java
This file contains hidden or 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,56 @@ | ||
| package com.sofa.linkiving.domain.link.dto.response; | ||
|
|
||
| import com.sofa.linkiving.domain.link.dto.internal.LinkDto; | ||
| import com.sofa.linkiving.domain.link.entity.Link; | ||
| import com.sofa.linkiving.domain.link.entity.Summary; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record LinkDetailRes( | ||
| @Schema(description = "링크 ID") | ||
| Long id, | ||
|
|
||
| @Schema(description = "링크 URL", example = "https://example.com") | ||
| String url, | ||
|
|
||
| @Schema(description = "링크 제목", example = "유용한 개발 자료") | ||
| String title, | ||
|
|
||
| @Schema(description = "메모", example = "나중에 읽어볼 것") | ||
| String memo, | ||
|
|
||
| @Schema(description = "이미지 URL", example = "https://example.com/image.jpg") | ||
| String imageUrl, | ||
|
|
||
| @Schema(description = "요약 정보") | ||
| SummaryRes summary | ||
| ) { | ||
| public static LinkDetailRes from(LinkDto dto) { | ||
| return of(dto.link(), dto.summary()); | ||
| } | ||
|
|
||
| public static LinkDetailRes of(Link link, Summary summary) { | ||
| return new LinkDetailRes( | ||
| link.getId(), | ||
| link.getUrl(), | ||
| link.getTitle(), | ||
| link.getMemo(), | ||
| link.getImageUrl(), | ||
| SummaryRes.from(summary) | ||
| ); | ||
| } | ||
|
|
||
| public record SummaryRes( | ||
| @Schema(description = "요약 ID") | ||
| Long id, | ||
| @Schema(description = "요약 내용", example = "이 링크는 예시 링크입니다.") | ||
| String content | ||
| ) { | ||
| public static SummaryRes from(Summary summary) { | ||
| if (summary == null) { | ||
| return null; | ||
| } | ||
| return new SummaryRes(summary.getId(), summary.getContent()); | ||
| } | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/sofa/linkiving/domain/link/dto/response/MetaScrapeRes.java
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
39 changes: 35 additions & 4 deletions
39
src/main/java/com/sofa/linkiving/domain/link/repository/LinkRepository.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,24 +1,55 @@ | ||
| package com.sofa.linkiving.domain.link.repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| 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 com.sofa.linkiving.domain.link.dto.internal.LinkDto; | ||
| import com.sofa.linkiving.domain.link.entity.Link; | ||
| import com.sofa.linkiving.domain.member.entity.Member; | ||
|
|
||
| public interface LinkRepository extends JpaRepository<Link, Long> { | ||
|
|
||
| Optional<Link> findByIdAndMember(Long id, Member member); | ||
|
|
||
| Page<Link> findByMemberAndIsDeleteFalse(Member member, Pageable pageable); | ||
|
|
||
| boolean existsByMemberAndUrlAndIsDeleteFalse(Member member, String url); | ||
|
|
||
| @Query("SELECT l.id FROM Link l WHERE l.member = :member AND l.url = :url AND l.isDelete = false") | ||
| @Query(""" | ||
| SELECT l.id | ||
| FROM Link l | ||
| WHERE l.member = :member AND l.url = :url AND l.isDelete = false | ||
| """) | ||
| Optional<Long> findIdByMemberAndUrlAndIsDeleteFalse(@Param("member") Member member, @Param("url") String url); | ||
|
|
||
| @Query(""" | ||
| SELECT new com.sofa.linkiving.domain.link.dto.internal.LinkDto(l, s) | ||
| FROM Link l | ||
| LEFT JOIN Summary s ON s.link = l AND s.selected = true | ||
| WHERE l.id = :id | ||
| AND l.member = :member | ||
| AND l.isDelete = false | ||
| """) | ||
| Optional<LinkDto> findByIdAndMemberWithSummaryAndIsDeleteFalse( | ||
| @Param("id") Long id, | ||
| @Param("member") Member member | ||
| ); | ||
|
|
||
| @Query(""" | ||
| SELECT new com.sofa.linkiving.domain.link.dto.internal.LinkDto(l, s) | ||
| FROM Link l | ||
| LEFT JOIN Summary s ON s.link = l AND s.selected = true | ||
| WHERE l.member = :member | ||
| AND l.isDelete = false | ||
| AND (:lastId IS NULL OR l.id < :lastId) | ||
| ORDER BY l.id DESC | ||
| """) | ||
| List<LinkDto> findAllByMemberWithSummaryAndCursorAndIsDeleteFalse( | ||
| @Param("member") Member member, | ||
| @Param("lastId") Long lastId, | ||
| Pageable pageable | ||
| ); | ||
Goder-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.