-
Notifications
You must be signed in to change notification settings - Fork 1
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
4주차-과제/정답 #17
Open
HwanGonJang
wants to merge
1
commit into
main
Choose a base branch
from
4주차-과제/정답
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "4\uC8FC\uCC28-\uACFC\uC81C/\uC815\uB2F5"
Open
4주차-과제/정답 #17
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
51 changes: 51 additions & 0 deletions
51
src/main/java/com/example/urlshortener/domain/url/controller/Week4Controller.java
This file contains 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,51 @@ | ||
package com.example.urlshortener.domain.url.controller; | ||
|
||
import com.example.urlshortener.common.dto.Response; | ||
import com.example.urlshortener.domain.url.dto.ShortenedUrlDto; | ||
import com.example.urlshortener.domain.url.service.UrlService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/short-links/list") | ||
@Tag(name = "🍃 4주차 과제", description = "4주차 과제입니다.") | ||
public class Week4Controller { | ||
|
||
private final UrlService urlService; | ||
|
||
@Operation( | ||
summary = "Data JPA로 URL 조회하기", | ||
responses = { | ||
@ApiResponse(responseCode = "200", description = "OK"), | ||
@ApiResponse(responseCode = "500", description = "INTERNAL_SERVER_ERROR") | ||
} | ||
) | ||
@GetMapping("/jpa") | ||
public Response<List<ShortenedUrlDto>> getShortUrlsWithJpa(@NotBlank @RequestParam("inquiry") String inquiry) { | ||
List<ShortenedUrlDto> shortenedUrls = urlService.getShortUrlsWithJpa(inquiry); | ||
return Response.data(shortenedUrls); | ||
} | ||
|
||
@Operation( | ||
summary = "QueryDsl로 URL 조회하기", | ||
responses = { | ||
@ApiResponse(responseCode = "200", description = "OK"), | ||
@ApiResponse(responseCode = "500", description = "INTERNAL_SERVER_ERROR") | ||
} | ||
) | ||
@GetMapping("/query-dsl") | ||
public Response<List<ShortenedUrlDto>> getShortUrl(@NotBlank @RequestParam("inquiry") String inquiry) { | ||
List<ShortenedUrlDto> shortenedUrls = urlService.getShortUrlsWithQueryDsl(inquiry); | ||
return Response.data(shortenedUrls); | ||
} | ||
} |
This file contains 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
26 changes: 26 additions & 0 deletions
26
...main/java/com/example/urlshortener/domain/url/repository/ShortenedUrlQueryRepository.java
This file contains 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,26 @@ | ||
package com.example.urlshortener.domain.url.repository; | ||
|
||
import com.example.urlshortener.domain.url.dto.ShortenedUrlDto; | ||
import com.example.urlshortener.domain.url.entity.QShortenedUrl; | ||
import com.example.urlshortener.domain.url.entity.ShortenedUrl; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ShortenedUrlQueryRepository { | ||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public List<ShortenedUrlDto> getShortUrlsWithQueryDsl(String inquiry) { | ||
QShortenedUrl shortenedUrl = QShortenedUrl.shortenedUrl; | ||
List<ShortenedUrl> shortenedUrls = jpaQueryFactory | ||
.selectFrom(shortenedUrl) | ||
.where(shortenedUrl.originUrl.contains(inquiry)) | ||
.fetch(); | ||
|
||
return ShortenedUrlDto.from(shortenedUrls); | ||
} | ||
} |
This file contains 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 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 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 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,6 +1,6 @@ | ||
INSERT INTO shortened_url (short_url, origin_url, created_at) VALUES | ||
('http://short.url/abc', 'http://example.com/page1', '2024-04-01 10:00:00'), | ||
('http://short.url/def', 'http://example.com/page2', '2024-04-02 12:00:00'), | ||
('http://short.url/ghi', 'http://example.com/page3', '2024-04-03 14:00:00'), | ||
('http://short.url/jkl', 'http://example.com/page4', '2024-04-04 16:00:00'), | ||
('http://short.url/mno', 'http://example.com/page5', '2024-04-05 18:00:00'); | ||
('abc', 'http://example.com/page1', '2024-04-01 10:00:00'), | ||
('def', 'http://example.com/page2', '2024-04-02 12:00:00'), | ||
('ghi', 'http://example.com/page3', '2024-04-03 14:00:00'), | ||
('jkl', 'http://example.com/page4', '2024-04-04 16:00:00'), | ||
('mno', 'http://example.com/page5', '2024-04-05 18:00:00'); |
This file contains 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
물어봤던 질문: Service 어노테이션이 들어온건 어떤 관점의 차이가 있어서인걸까요??