Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
[BE] fix: 티스토리 예약 기능 오류 수정 (#462)
Browse files Browse the repository at this point in the history
fix: 티스토리 예약 기능 오류 수정

- 티스토리 published 파라미터 long으로 변경
- LocalDateTime에서 유닉스 timestamp로 변경
  • Loading branch information
cheon-eunjeong authored Sep 21, 2023
1 parent ded4635 commit cf70b10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.NoSuchElementException;

import static org.donggle.backend.domain.blog.BlogType.TISTORY;
Expand Down Expand Up @@ -141,16 +143,21 @@ private MemberCredentials getMemberCredentials(final Long memberId) {
return memberCredentials;
}

private String makePublishTime(final String publishTime) {
private Long makePublishTime(final String publishTime) {
if (publishTime.isBlank()) {
return String.valueOf(LocalDateTime.now());
return Instant.now().getEpochSecond();
}
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
final LocalDateTime publishLocalDateTime = LocalDateTime.parse(publishTime, formatter);
if (publishLocalDateTime.isBefore(LocalDateTime.now())) {
throw new InvalidPublishRequestException("현재 시간보다 과거의 시간은 입력될 수 없습니다.");
final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
try {
final Date date = formatter.parse(publishTime);
final Instant instant = date.toInstant();
if (instant.isBefore(Instant.now())) {
throw new InvalidPublishRequestException("현재 시간보다 과거의 시간은 입력될 수 없습니다.");
}
return instant.getEpochSecond();
} catch (ParseException e) {
throw new InvalidPublishRequestException("예약 시간 입력 형식이 잘못되었습니다.");
}
return publishTime;
}

public String findDefaultBlogName(final String access_token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public record TistoryPublishRequest(
String content,
int visibility,
String category,
String published,
Long published,
List<String> slogan,
String tag,
String acceptComment,
Expand Down

0 comments on commit cf70b10

Please sign in to comment.