33import jakarta .persistence .NoResultException ;
44import jakarta .validation .constraints .NotBlank ;
55import lombok .RequiredArgsConstructor ;
6+ import lombok .extern .slf4j .Slf4j ;
67import org .hibernate .validator .constraints .Length ;
8+ import org .springframework .beans .factory .annotation .Value ;
79import org .springframework .dao .DataIntegrityViolationException ;
810import org .springframework .stereotype .Service ;
911import org .springframework .transaction .annotation .Transactional ;
12+ import org .springframework .util .StringUtils ;
1013import org .springframework .web .multipart .MultipartFile ;
1114import org .tuna .zoopzoop .backend .domain .datasource .repository .DataSourceRepository ;
1215import org .tuna .zoopzoop .backend .domain .datasource .repository .TagRepository ;
1821import org .tuna .zoopzoop .backend .global .aws .S3Service ;
1922import org .tuna .zoopzoop .backend .global .clients .liveblocks .LiveblocksClient ;
2023
24+ @ Slf4j
2125@ Service
2226@ RequiredArgsConstructor
2327public class SpaceService {
@@ -28,6 +32,9 @@ public class SpaceService {
2832 private final TagRepository tagRepository ;
2933 private final DataSourceRepository dataSourceRepository ;
3034
35+ @ Value ("${spring.cloud.aws.s3.prefix}" )
36+ private String s3Prefix ;
37+
3138 // ======================== 스페이스 조회 ======================== //
3239
3340 /**
@@ -174,9 +181,10 @@ public void updateSpaceThumbnail(Integer spaceId, Member requester, MultipartFil
174181 }
175182
176183 try {
177- //String fileName = "space/" + spaceId + "/ thumbnail/" + System.currentTimeMillis() + "_" +
184+ //String fileName = "space- thumbnail/prefix/space_id.jpg";
178185 // S3 저장 시 파일 이름 고정 (덮어쓰기)
179- String fileName = "space-thumbnail/space_" + spaceId ;
186+ String extension = StringUtils .getFilenameExtension (image .getOriginalFilename ());
187+ String fileName = "space-thumbnail/" + s3Prefix + "/space_" + spaceId + "." + extension ;
180188 String baseImageUrl = s3Service .upload (image , fileName );
181189
182190 // DB 용으로 현재 시간을 쿼리 파라미터에 추가 (캐시 무효화)
@@ -186,6 +194,7 @@ public void updateSpaceThumbnail(Integer spaceId, Member requester, MultipartFil
186194 space .setThumbnailUrl (finalImageUrl );
187195 spaceRepository .save (space );
188196 } catch (Exception e ) {
197+ log .error ("Space thumbnail upload failed: " , e );
189198 throw new RuntimeException ("스페이스 썸네일 이미지 업로드에 실패했습니다." );
190199 }
191200 }
0 commit comments