Skip to content
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

[5기 박유진] Shorten-URL 과제 제출합니다. #70

Open
wants to merge 35 commits into
base: eugene
Choose a base branch
from

Conversation

eugene225
Copy link

@eugene225 eugene225 commented Dec 17, 2023

📌 과제 설명

Screenshot 2023-12-17 at 7 08 46 PM

domain

  • Url : id, shortenKey, originUrl, shortenUrl, count
  • UrlRepository

service

  • UrlService
    • save : 저장
    • shortenUrlByMurMur / shortenUrlByBase62 : 인코딩 방식
    • addLink : encodingType에 따른 shortenUrl 저장
    • getUrlByKey : key 이용해서 Url 찾고 redirect count 증가
  • EncodingType : 인코딩 방식 저장 Enum
  • EnumConverter : String -> Enum 변환
  • RadixConverter : 2진수, 16진수 변환
  • Base62Encoding : Base62Encoding 구현

controller

  • UrlRestController
  • UrlWebController
  • dto : UrlRequestDto

👩‍💻 요구 사항과 구현 내용

  • URL 입력폼 제공 및 결과 출력
  • URL Shortening Key는 8 Character 이내로 생성
  • 단축된 URL 요청시 원래 URL로 리다이렉트
  • 단축된 URL에 대한 요청 수 정보저장 (optional)
  • Shortening Key를 생성하는 알고리즘 2개 이상 제공하며 애플리케이션 실행중 동적으로 변경 가능 (optional)

✅ 피드백 반영사항

✅ PR 포인트 & 궁금한 점

  • 라이브러리를 사용한 인코딩 방식에 성능적인 문제가 있을지 궁금합니다.

Copy link

@SangHyunGil SangHyunGil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

작성해주시느라 너무 고생많으셨어요.
간단한 코멘트 남겼으니 확인부탁해요.

  • 테스트 코드가 없는 것 같은데요. 적어도 도메인 로직과 서비스 로직과 같은 중요한 비즈니스 로직을 다루는 영역에 대한 테스트는 작성하는걸 권장해요.
  • 레이아웃이 조금 틀어진 부분이 있었는데 수정해주시면 좋을 것 같아요.
  • 라이브러리를 다룰때 단순 인코딩이라면 성능적인 부분을 고려하기 위해서는 부하테스트 같은걸 통해서 검증을 해야할 것 같아 추후에 한 번 관련하여 진행해보시면 좋을 것 같아요.

pom.xml Outdated
Comment on lines 20 to 23
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

레디스가 왜 필요한 걸까요?
제거해주신 것 봤습니다!

Comment on lines 26 to 30
servlet:
encoding:
charset: UTF-8
enabled: true
force: true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 적용하신건가요?


@NonNull
@Column(name = "orgin_url")
private String originUrl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originUrl은 유니크하지 않아도 되는건가요?
만약, 유니크해야한다면 유니크 제약 조건을 걸어보면 좋을 것 같네요.

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Url {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생성일시 / 업데이트일시도 있으면 좋을 것 같네요.


import java.util.Optional;

public interface UrlRepository extends JpaRepository<Url, String> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 ID 값에 String이 들어간걸까요?

.originUrl(originUrl).build());
}

public static String shortenUrlByMurMur(@NonNull Url url) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인코딩 관련 책임들이 여러곳에 분산되어있는 것 같아요.

  • 실제 인코딩하는 로직은 서비스에 존재해요.
  • 인코딩 관련 관리는 EncodingType을 통해서 관리해요.
  • 이넘을 사용해 변환하는건 EnumConverter을 통해 처리해요.

코드를 응집도 있게 관리하는 부분을 고민해보시면 좋을 것 같아요.
인코딩 수행하는 로직은 Url 서비스가 가져야할 책임이 아닌 것 같아요. 별도의 인코딩 로직만 수행하는 객체가 존재(별도 클래스 혹은 이넘)하고 UrlService는 이를 호출만하면 될 것 같아요.

서비스 레이어에서 하는 역할이 무엇일지 고민해봐주시면 더욱 좋을 것 같아요.

}

public static String shortenUrlByMurMur(@NonNull Url url) {
return Hashing.murmur3_32_fixed().hashString(url.getOriginUrl(), Charset.defaultCharset()).toString();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하신 이유가 궁금해요!

if (isValidUrl(originUrl)) {
this.originUrl = originUrl;
} else {
throw new IllegalArgumentException("Invalid URL: " + originUrl);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

간단의견) 나중에는 CustomException을 적용해봐도 좋을 것 같아요.

public String getUrlByKey(@NonNull String key) {
Url url = urlRepository.findByShortenKey(key)
.orElseThrow(UrlNotFoundException::new);
url.updateCount();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

동시에 요청이 들어오면 동시성 이슈가 생길 수 있을 것 같아요.
어떻게 처리할지 고민하고 생각을 공유해주세요.

@@ -0,0 +1,27 @@
package com.prgrms.shortenurl.service;

public class Base62Encoding {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 base64가 아닌 base62를 사용하셨나요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants