Skip to content

Commit

Permalink
aws s3 의존성 충돌 및 og html 코드 수정합니다. (#217)
Browse files Browse the repository at this point in the history
* fix: aws s3 Jackson 의존성 충돌 해결 (#216)

* fix: 버전 정보 1.2.1 -> 1.2.2로 변경 (#216)

* fix: logback 삭제 (#216)

* fix: preview 제목, 내용 변경 및 자바스크립트 요청 코드 변경 (#216)

* fix: baseUrl(서버 도메인), ogURl(요청 url), sharedUrl(공유 코드) 추가 (#216)

* fix: 그리기 점수를 소수점 1번째까지 자르는 로직 작성 (#216)
  • Loading branch information
violet-mj authored Aug 25, 2024
1 parent 91dd658 commit e747156
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 27 deletions.
21 changes: 16 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ repositories {
mavenCentral()
}

dependencyManagement {
imports {
mavenBom "com.amazonaws:aws-java-sdk-bom:1.12.472"
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
Expand All @@ -31,8 +37,16 @@ dependencies {
// template engine
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

// Json
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.15.3'
implementation 'org.json:json:20210307'

// aws
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'com.amazonaws:aws-java-sdk-sts'


// db
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
Expand All @@ -55,9 +69,6 @@ dependencies {
// Apache Commons
implementation 'org.apache.commons:commons-lang3:3.12.0'

// Json
implementation 'org.json:json:20210307'

// Actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator'

Expand All @@ -73,4 +84,4 @@ dependencies {
tasks.named('test') {
jvmArgs = ["-Dspring.profiles.active=test"]
useJUnitPlatform()
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.2.1
version=1.2.2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
Expand All @@ -21,6 +22,9 @@ public class PreviewController {

private final PreviewService previewService;

@Value("${domain.url}")
private String baseUrl;

@Tag(name = "Drawing Lottery")
@Operation(summary = "미리 보기용 html 반환", description = """
# open graph html 반환
Expand All @@ -41,11 +45,13 @@ public String preview(
@Validated PreviewRequest previewRequest,
Model model
) {
EventUser eventUser = previewService.preview(previewRequest);
EventUser eventUser = previewService.preview(previewRequest, model);

model.addAttribute("resultImgUrl", eventUser.getResultImgUrl());
model.addAttribute("name", eventUser.getUser().getName());
model.addAttribute("score", eventUser.getGameScore());
model.addAttribute("apiUrl", baseUrl + "/api/v1");
model.addAttribute("ogUrl", baseUrl + "/api/v1/lottery/drawing/preview?sharedUrl=" + previewRequest.getSharedUrl());
model.addAttribute("sharedUrl", previewRequest.getSharedUrl());

return "preview";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import com.hyundai.softeer.backend.domain.lottery.drawing.exception.DrawingEventNotParticipantException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

@Service
@RequiredArgsConstructor
public class PreviewService {

private final EventUserRepository eventUserRepository;

public EventUser preview(PreviewRequest previewRequest) {
public EventUser preview(PreviewRequest previewRequest, Model model) {
String sharedUrl = previewRequest.getSharedUrl();

EventUser eventUser = eventUserRepository.findBySharedUrl(sharedUrl)
Expand All @@ -24,6 +25,30 @@ public EventUser preview(PreviewRequest previewRequest) {
throw new DrawingEventNotParticipantException();
}

double scoreGame1 = getGameScore(eventUser.getScores().get("1_game_score"));
model.addAttribute("score", String.format("%.1f", scoreGame1));

return eventUser;
}

private double getGameScore(Object rawGameScore) {
double scoreGame1;
if (rawGameScore != null) {
if (rawGameScore instanceof String) {
try {
scoreGame1 = Double.parseDouble((String) rawGameScore);
} catch (NumberFormatException e) {
scoreGame1 = 0.0;
}
} else if (rawGameScore instanceof Number) {
scoreGame1 = ((Number) rawGameScore).doubleValue();
} else {
scoreGame1 = 0.0;
}
} else {
scoreGame1 = 0.0;
}

return scoreGame1;
}
}
12 changes: 0 additions & 12 deletions src/main/resources/logback-spring.xml

This file was deleted.

38 changes: 32 additions & 6 deletions src/main/resources/templates/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,43 @@
<title>웹페이지 제목</title>

<!-- Open Graph 메타 태그 -->
<meta property="og:title" content="드로잉 이벤트~!!">
<meta property="og:description" th:content="${name} + '님은 ' + ${score} + '를 얻으셨어요~~ 한번 도전 해보실래요?'">
<meta property="og:title" content="일상과 낭만 사이, 디 올 뉴 싼타페와 함께">
<meta property="og:description" th:content="'[' + ${name} + ']' + '님의 점수는 ' + ${score} + '점입니다.'">
<meta property="og:image" th:content="${resultImgUrl}">
<meta property="og:url">
<meta property="og:url" th:content="${ogUrl}">
<meta property="og:type" content="website">

<!-- 추가적인 Open Graph 태그 -->
<meta property="og:locale" content="ko_KR">
</head>
<body>
<h1>웹페이지 내용</h1>
<p>이곳에 실제 웹페이지 내용을 작성합니다.</p>
<script th:inline="javascript">
/*<![CDATA[*/
window.addEventListener('load', function() {
const baseUrl = /*[[${apiUrl}]]*/ '';
const sharedUrl = /*[[${sharedUrl}]]*/ '';
const url = `${baseUrl}/url/${sharedUrl}`;
// fetch를 사용하여 GET 요청 보내기
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.json();
})
.then(data => {
console.log('Success:', data);
if (data.data && data.data.redirectUrl) {
window.location.href = data.data.redirectUrl;
} else {
console.error('Redirect URL not found in response');
}
})
.catch(error => {
console.error('Error:', error);
});
});
/*]]>*/
</script>
</body>
</html>
</html>

0 comments on commit e747156

Please sign in to comment.