Skip to content

Commit e24a941

Browse files
authored
Merge pull request #153 from Next-Room/feature/timer-image
[FEAT] 타이머 이미지 기능 수정
2 parents f0e0518 + 30c7b4e commit e24a941

4 files changed

Lines changed: 57 additions & 10 deletions

File tree

src/main/java/com/nextroom/nextRoomServer/controller/HintController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ public ResponseEntity<BaseResponse> removeHint(@RequestBody @Valid HintDto.Remov
8787
}
8888

8989
@Operation(
90-
summary = "PreSigned Url 요청",
90+
summary = "힌트 or 정답 이미지 PreSigned Url 요청",
9191
description = """
9292
s3 url /{profile}/{shopId}/{themeId}/{type}/{num}_uuid.png
9393
94-
ex) "/dev/1/3/hint/1_2e20b6a9-e24b-45a8-a974-005c14f9f44f.png/"
94+
ex) "/dev/1/3/hint/1_2e20b6a9-e24b-45a8-a974-005c14f9f44f.png"
9595
""",
9696
responses = {
9797
@ApiResponse(responseCode = "200", description = "OK"),

src/main/java/com/nextroom/nextRoomServer/controller/ThemeController.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,64 @@ public ResponseEntity<BaseResponse> removeTheme(@RequestBody @Valid ThemeDto.Rem
9494
return ResponseEntity.ok(new BaseResponse(OK));
9595
}
9696

97+
@Operation(
98+
summary = "테마 타이머 배경 이미지 PreSigned Url 요청",
99+
description = """
100+
s3 url /{profile}/{shopId}/{themeId}/{type}/{num}_uuid.png
101+
102+
ex) "/dev/1/3/timer/1_2e20b6a9-e24b-45a8-a974-005c14f9f44f.png"
103+
""",
104+
responses = {
105+
@ApiResponse(responseCode = "200", description = "OK"),
106+
@ApiResponse(responseCode = "401", description = "TOKEN_UNAUTHORIZED"),
107+
@ApiResponse(responseCode = "403", description = "NOT_PERMITTED"),
108+
@ApiResponse(responseCode = "404", description = "TARGET_THEME_NOT_FOUND")
109+
}
110+
)
97111
@GetMapping("/timer/url/{themeId}")
98112
public ResponseEntity<DataResponse<ThemeUrlResponse>> getUrl(@PathVariable Long themeId) {
99113
return ResponseEntity.ok(new DataResponse<>(OK, themeService.getTimerUrl(themeId)));
100114
}
101115

116+
@Operation(
117+
summary = "테마 타이머 배경 이미지 추가",
118+
responses = {
119+
@ApiResponse(responseCode = "200", description = "OK"),
120+
@ApiResponse(responseCode = "401", description = "TOKEN_UNAUTHORIZED"),
121+
@ApiResponse(responseCode = "403", description = "NOT_PERMITTED"),
122+
@ApiResponse(responseCode = "404", description = "TARGET_THEME_NOT_FOUND")
123+
}
124+
)
102125
@PostMapping("/timer")
103126
public ResponseEntity<BaseResponse> addThemeTimerImage(@RequestBody @Valid ThemeDto.ThemeUrlRequest request) {
104127
themeService.addThemeTimerImage(request);
105128
return ResponseEntity.ok(new BaseResponse(OK));
106129
}
107130

131+
@Operation(
132+
summary = "테마 타이머 배경 이미지 삭제",
133+
responses = {
134+
@ApiResponse(responseCode = "200", description = "OK"),
135+
@ApiResponse(responseCode = "401", description = "TOKEN_UNAUTHORIZED"),
136+
@ApiResponse(responseCode = "403", description = "NOT_PERMITTED"),
137+
@ApiResponse(responseCode = "404", description = "TARGET_THEME_NOT_FOUND")
138+
}
139+
)
108140
@DeleteMapping("/timer/{themeId}")
109141
public ResponseEntity<BaseResponse> removeTheme(@PathVariable Long themeId) {
110142
themeService.removeThemeTimerImage(themeId);
111143
return ResponseEntity.ok(new BaseResponse(OK));
112144
}
113145

146+
@Operation(
147+
summary = "(앱) 테마 타이머 배경 on/off 설정",
148+
responses = {
149+
@ApiResponse(responseCode = "200", description = "OK"),
150+
@ApiResponse(responseCode = "401", description = "TOKEN_UNAUTHORIZED"),
151+
@ApiResponse(responseCode = "403", description = "NOT_PERMITTED"),
152+
@ApiResponse(responseCode = "404", description = "TARGET_THEME_NOT_FOUND")
153+
}
154+
)
114155
@PutMapping("/timer/active")
115156
public ResponseEntity<BaseResponse> activeTimerUrl(@RequestBody @Valid ThemeDto.ThemeActiveUrlRequest request) {
116157
themeService.activeThemeTimerUrl(request);

src/main/java/com/nextroom/nextRoomServer/service/ThemeService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.nextroom.nextRoomServer.service;
22

3-
import static com.nextroom.nextRoomServer.exceptions.StatusCode.NOT_PERMITTED;
43
import static com.nextroom.nextRoomServer.exceptions.StatusCode.TARGET_SHOP_NOT_FOUND;
54
import static com.nextroom.nextRoomServer.exceptions.StatusCode.TARGET_THEME_NOT_FOUND;
65

@@ -82,8 +81,8 @@ public List<ThemeDto.ThemeListResponse> getThemeList() {
8281
List<Theme> themeList = themeRepository.findAllByShopId(SecurityUtil.getCurrentShopId());
8382
return themeList.stream()
8483
.map(it -> {
85-
String timerImage = s3Component.generatePresignedUrlsForUpload(it.getShop().getId(), it.getId(), TYPE_TIMER);
86-
return new ThemeDto.ThemeListResponse(it, timerImage);
84+
String timerImageUrl = s3Component.generatePresignedUrlForDownLoad(it.getShop().getId(), it.getId(), TYPE_TIMER, it.getTimerImageUrl());
85+
return new ThemeDto.ThemeListResponse(it, timerImageUrl);
8786
})
8887
.toList();
8988
}
@@ -103,7 +102,7 @@ public ThemeUrlResponse getTimerUrl(Long themeId) {
103102
Long shopId = this.validateThemeAndShop(themeId)
104103
.getShop()
105104
.getId();
106-
String timerUrl = s3Component.generatePresignedUrlsForUpload(shopId, themeId, TYPE_TIMER);
105+
String timerUrl = s3Component.generatePresignedUrlForUpload(shopId, themeId, TYPE_TIMER);
107106

108107
return new ThemeUrlResponse(themeId, timerUrl);
109108
}

src/main/java/com/nextroom/nextRoomServer/util/aws/S3Component.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public List<String> generatePresignedUrlsForUpload(Long shopId, Long themeId, St
4141

4242
List<String> imageUrlList = new ArrayList<>();
4343
for (int i = 1; i <= imageCount; i++) {
44-
imageUrlList.add(generatePresignedUrlsForUpload(shopId, themeId, type));
44+
imageUrlList.add(this.generatePresignedUrlForUpload(shopId, themeId, type));
4545
}
4646
return imageUrlList;
4747
}
4848

49-
public String generatePresignedUrlsForUpload(Long shopId, Long themeId, String type) {
49+
public String generatePresignedUrlForUpload(Long shopId, Long themeId, String type) {
5050
String fileName = this.createFileNameForUpload(shopId, themeId, type, System.nanoTime());
5151
return this.createPresignedPutUrl(fileName);
5252
}
@@ -58,12 +58,19 @@ public List<String> generatePresignedUrlsForDownLoad(Long shopId, Long themeId,
5858

5959
List<String> imageUrlList = new ArrayList<>();
6060
for (String s : uuidList) {
61-
String fileName = this.createFileNameForDownLoad(shopId, themeId, type, s);
62-
imageUrlList.add(this.createPresignedGetUrl(fileName));
61+
imageUrlList.add(this.generatePresignedUrlForDownLoad(shopId, themeId, type, s));
6362
}
6463
return imageUrlList;
6564
}
6665

66+
public String generatePresignedUrlForDownLoad(Long shopId, Long themeId, String type, String timerImageUrl) {
67+
if (timerImageUrl == null || timerImageUrl.isEmpty()) {
68+
return null;
69+
}
70+
String fileName = this.createFileNameForDownLoad(shopId, themeId, type, timerImageUrl);
71+
return this.createPresignedGetUrl(fileName);
72+
}
73+
6774
public void deleteObjects(Long shopId, Long themeId, String type, List<String> imageList) {
6875
if (imageList == null || imageList.isEmpty()) {
6976
return;

0 commit comments

Comments
 (0)