-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd38549
commit dccca59
Showing
59 changed files
with
259 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
app/api/user-api/src/main/java/org/example/config/UserApiConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/api/user-api/src/main/java/org/example/file/component/FileComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.example.file.component; | ||
|
||
import java.util.Optional; | ||
import org.springframework.core.io.Resource; | ||
|
||
public interface FileComponent { | ||
|
||
Optional<String> getImageUrl(int id); | ||
|
||
Resource getProfileResource(int id); | ||
} |
57 changes: 57 additions & 0 deletions
57
app/api/user-api/src/main/java/org/example/file/component/FileLocalComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.example.file.component; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.example.file.property.FileRootUrlProperty; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.UrlResource; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FileLocalComponent implements FileComponent { | ||
|
||
private final FileRootUrlProperty fileRootUrlProperty; | ||
private static final String IMAGE_URL_TEMPLATE = "/profile-image/"; | ||
private static final String IMAGE_RESOURCE_LOCATION = "static/image/profileImage"; | ||
private static final String IMAGE_EXTENSION = ".png"; | ||
|
||
/** | ||
* 이미지 ID를 받아서 URL을 반환하는 메서드 | ||
* | ||
* @param id 이미지 ID (1 ~ 16) | ||
* @return 이미지 URL | ||
*/ | ||
@Override | ||
public Optional<String> getImageUrl(int id) { | ||
// ID가 범위를 벗어난 경우 빈 값을 반환 | ||
if (id < 1 || id > 16) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(fileRootUrlProperty.rootUrl() + IMAGE_URL_TEMPLATE + id); | ||
} | ||
|
||
@Override | ||
@Cacheable(value = "profileImages", key = "#id") | ||
public Resource getProfileResource(int id) { | ||
Resource resource; | ||
try { | ||
String resourcePath = IMAGE_RESOURCE_LOCATION + id + IMAGE_EXTENSION; | ||
resource = new UrlResource( | ||
Objects.requireNonNull(getClass().getClassLoader().getResource(resourcePath)) | ||
.toURI()); | ||
if (!resource.exists() && !resource.isReadable()) { | ||
throw new IllegalArgumentException(); | ||
} | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
|
||
return resource; | ||
} | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
app/api/user-api/src/main/java/org/example/file/controller/FileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.example.file.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.file.component.FileLocalComponent; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.ContentDisposition; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/files") | ||
public class FileController { | ||
|
||
private final FileLocalComponent fileLocalComponent; | ||
|
||
@GetMapping("/profile-image/{id}") | ||
public ResponseEntity<Resource> getUserProfileImage(@PathVariable int id) { | ||
Resource resource = fileLocalComponent.getProfileResource(id); | ||
|
||
return ResponseEntity.ok() | ||
.contentType(MediaType.IMAGE_PNG) | ||
.header( | ||
HttpHeaders.CONTENT_DISPOSITION, | ||
ContentDisposition.inline().filename(resource.getFilename()).toString()) | ||
.body(resource); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
app/api/user-api/src/main/java/org/example/file/property/FileRootUrlProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.example.file.property; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "file") | ||
public record FileRootUrlProperty( | ||
String rootUrl | ||
) { | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
...rg/example/client/AlarmClientManager.java → ...ample/user/client/AlarmClientManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...g/example/controller/AdminController.java → ...mple/user/controller/AdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...ample/controller/UserAlarmController.java → .../user/controller/UserAlarmController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...dto/param/SimpleNotificationApiParam.java → ...dto/param/SimpleNotificationApiParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ler/dto/request/AdminLoginApiRequest.java → ...ler/dto/request/AdminLoginApiRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...ntroller/dto/request/LoginApiRequest.java → ...ntroller/dto/request/LoginApiRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nse/HasUnreadNotificationApiResponse.java → ...nse/HasUnreadNotificationApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...roller/dto/response/LoginApiResponse.java → ...roller/dto/response/LoginApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...esponse/NotificationExistApiResponse.java → ...esponse/NotificationExistApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...to/response/NotificationsApiResponse.java → ...to/response/NotificationsApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ller/dto/response/ReissueApiResponse.java → ...ller/dto/response/ReissueApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
.../dto/response/UserProfileApiResponse.java → .../dto/response/UserProfileApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../java/org/example/pub/UserFcmMessage.java → .../org/example/user/pub/UserFcmMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.example.pub; | ||
package org.example.user.pub; | ||
|
||
import java.util.UUID; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...org/example/pub/UserMessagePublisher.java → ...xample/user/pub/UserMessagePublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.example.pub; | ||
package org.example.user.pub; | ||
|
||
public interface UserMessagePublisher { | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
...ava/org/example/service/AdminService.java → ...rg/example/user/service/AdminService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.