Skip to content

Commit

Permalink
[FIX] 링크 URL 길이 제한 변경 (#958)
Browse files Browse the repository at this point in the history
* fix: DB url 칼럼 charset을 ascii로 변경, 길이도 늘림

* fix: url 길이에 대한 에러 코드 추가

* fix: url 길이에 대한 응답 코드 변경 (414)

* fix: pick 타이틀 길이 제한 해제

* fix: pick 타이틀 길이 제한 검사 코드 제거
  • Loading branch information
kimminkyeu authored Jan 13, 2025
1 parent c58fdc0 commit 759ff97
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import baguni.api.application.pick.dto.PickApiResponse;
import baguni.api.application.pick.dto.PickSliceResponse;
import baguni.domain.infrastructure.pick.dto.PickResult;
import baguni.domain.exception.pick.ApiPickException;
import baguni.api.service.pick.service.PickSearchService;
import baguni.api.service.pick.service.PickService;
import baguni.common.event.events.PickCreateEvent;
Expand Down Expand Up @@ -164,9 +163,6 @@ public ResponseEntity<PickApiResponse.Pick> getPick(@LoginUserId Long userId,
})
public ResponseEntity<PickApiResponse.Pick> savePick(@LoginUserId Long userId,
@Valid @RequestBody PickApiRequest.Create request) {
if (!Objects.isNull(request.title()) && 200 < request.title().length()) {
throw ApiPickException.PICK_TITLE_TOO_LONG();
}
var command = pickApiMapper.toCreateCommand(userId, request);
var result = pickService.saveNewPick(command);
var event = new PickCreateEvent(userId, result.id(), result.linkInfo().url());
Expand Down Expand Up @@ -237,9 +233,6 @@ public ResponseEntity<PickApiResponse.Pick> updatePickFromChromeExtension(
@LoginUserId Long userId,
@Valid @RequestBody PickApiRequest.UpdateFromExtension request
) {
if (Objects.nonNull(request.title()) && (200 < request.title().length())) {
throw ApiPickException.PICK_TITLE_TOO_LONG();
}
var command = pickApiMapper.toUpdateCommand(userId, request);
var result = pickService.updatePick(command);
var response = pickApiMapper.toApiResponse(result);
Expand All @@ -255,9 +248,6 @@ public ResponseEntity<PickApiResponse.Pick> updatePick(
@LoginUserId Long userId,
@Valid @RequestBody PickApiRequest.Update request
) {
if (Objects.nonNull(request.title()) && (200 < request.title().length())) {
throw ApiPickException.PICK_TITLE_TOO_LONG();
}
var command = pickApiMapper.toUpdateCommand(userId, request);
var result = pickService.updatePick(command);
var response = pickApiMapper.toApiResponse(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum ApiLinkErrorCode implements ApiErrorCode {
LINK_OG_TAG_UPDATE_FAILURE
("LI-003", HttpStatus.NOT_FOUND, "OG 태그 업데이트를 위한 크롤링 요청 실패", ErrorLevel.CAN_HAPPEN()),

LINK_URL_TOO_LONG
("LI-004", HttpStatus.URI_TOO_LONG, "저장 가능한 URL 길이 초과 [< 2048]", ErrorLevel.CAN_HAPPEN()),
;

// ------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public static ApiLinkException LINK_ALREADY_EXISTS() {
public static ApiLinkException LINK_OG_TAG_UPDATE_FAILURE() {
return new ApiLinkException(ApiLinkErrorCode.LINK_OG_TAG_UPDATE_FAILURE);
}

public static ApiLinkException LINK_URL_TOO_LONG() {
return new ApiLinkException(ApiLinkErrorCode.LINK_URL_TOO_LONG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public enum ApiPickErrorCode implements ApiErrorCode {
("PK-003", HttpStatus.UNAUTHORIZED, "잘못된 Pick 접근, 폴더가 아닌 Root에 접근", ErrorLevel.SHOULD_NOT_HAPPEN()),
PICK_DELETE_NOT_ALLOWED
("PK-004", HttpStatus.NOT_ACCEPTABLE, "휴지통이 아닌 폴더에서 픽 삭제는 허용되지 않음", ErrorLevel.SHOULD_NOT_HAPPEN()),
PICK_TITLE_TOO_LONG
("PK-005", HttpStatus.BAD_REQUEST, "픽 제목이 허용된 최대 길이를 초과했습니다", ErrorLevel.CAN_HAPPEN()),
;

private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@ public static ApiPickException PICK_UNAUTHORIZED_ROOT_ACCESS() {
public static ApiPickException PICK_DELETE_NOT_ALLOWED() {
return new ApiPickException(ApiPickErrorCode.PICK_DELETE_NOT_ALLOWED);
}

public static ApiPickException PICK_TITLE_TOO_LONG() {
return new ApiPickException(ApiPickErrorCode.PICK_TITLE_TOO_LONG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.apache.commons.lang3.StringUtils;

import baguni.domain.exception.link.ApiLinkException;
import baguni.domain.model.common.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -27,12 +28,8 @@ public class Link extends BaseEntity {
@Column(name = "id")
private Long id;

// URL
// TODO: VARCHAR 최대 크기를 몇으로 할지 토의 필요합니다.
// The index key prefix length limit is 3072 bytes for InnoDB -> VARCHAR(1000) + utf8 = 4000byte
// 일단 medium 기준 가장 길었던 url 320 글자의 약 2배인 VARCHAR(600)으로 변경
// Baguni 노션 기술 부채에 VARCHAR, TEXT 부분 참고.
@Column(name = "url", nullable = false, columnDefinition = "VARCHAR(600)", unique = true)
// url로 검색이 자주 되므로 text가 아닌 varchar를 사용 + unique
@Column(name = "url", nullable = false, columnDefinition = "VARCHAR(2048)", unique = true)
private String url;

// title이 한글 200자 이상인 경우가 있어 text타입으로 변경
Expand Down Expand Up @@ -87,6 +84,9 @@ public boolean isValidLink() {

@Builder
private Link(String url, String title, String description, String imageUrl, LocalDateTime invalidatedAt) {
if (2048 < url.length()) {
throw ApiLinkException.LINK_URL_TOO_LONG();
}
this.url = url;
this.title = title;
this.description = description;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE baguni_db.link
MODIFY url VARCHAR(2048) CHARACTER SET ascii NOT NULL UNIQUE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE baguni_db.pick
MODIFY title TEXT;

0 comments on commit 759ff97

Please sign in to comment.