66import com .swyp .app .domain .battle .entity .BattleOption ;
77import com .swyp .app .domain .battle .entity .BattleOptionTag ;
88import com .swyp .app .domain .battle .enums .BattleCreatorType ;
9- import com .swyp .app .domain .battle .enums .BattleStatus ;
109import com .swyp .app .domain .battle .repository .BattleOptionTagRepository ;
1110import com .swyp .app .domain .tag .entity .Tag ;
1211import com .swyp .app .domain .tag .enums .TagType ;
1312import com .swyp .app .domain .user .entity .User ;
13+ import com .swyp .app .global .infra .s3 .service .S3UploadService ;
1414import lombok .RequiredArgsConstructor ;
1515import org .springframework .stereotype .Component ;
1616
17+ import java .time .Duration ;
1718import java .util .List ;
1819
1920@ Component
@@ -37,7 +38,7 @@ public Battle toEntity(AdminBattleCreateRequest request, User admin) {
3738 .thumbnailUrl (request .thumbnailUrl ())
3839 .type (request .type ())
3940 .targetDate (request .targetDate ())
40- .status (BattleStatus . PENDING )
41+ .status (request . status () )
4142 .creatorType (BattleCreatorType .ADMIN )
4243 .creator (admin )
4344 .build ();
@@ -74,15 +75,23 @@ public BattleSimpleResponse toSimpleResponse(Battle b) {
7475 );
7576 }
7677
77- public AdminBattleDetailResponse toAdminDetailResponse (Battle b , List <Tag > tags , List <BattleOption > opts ) {
78+ // 관리자용 상세 응답 변환 (보안 URL 적용)
79+ public AdminBattleDetailResponse toAdminDetailResponse (
80+ Battle b , List <Tag > tags , List <BattleOption > opts , S3UploadService s3Service ) {
81+
82+ // 썸네일 보안 URL
83+ String secureThumbnail = (b .getThumbnailUrl () != null && !b .getThumbnailUrl ().isBlank ())
84+ ? s3Service .getPresignedUrl (b .getThumbnailUrl (), Duration .ofMinutes (10 ))
85+ : null ;
86+
7887 return new AdminBattleDetailResponse (
7988 b .getId (),
8089 b .getTitle (),
8190 b .getTitlePrefix (),
8291 b .getTitleSuffix (),
8392 b .getSummary (),
8493 b .getDescription (),
85- b . getThumbnailUrl () ,
94+ secureThumbnail ,
8695 b .getType (),
8796 b .getItemA (),
8897 b .getItemADesc (),
@@ -92,20 +101,29 @@ public AdminBattleDetailResponse toAdminDetailResponse(Battle b, List<Tag> tags,
92101 b .getStatus (),
93102 b .getCreatorType (),
94103 toTagResponses (tags , null ),
95- toOptionResponses (opts ),
104+ toOptionResponses (opts , s3Service ),
96105 b .getCreatedAt (),
97106 b .getUpdatedAt ()
98107 );
99108 }
100109
101- public BattleUserDetailResponse toUserDetailResponse (Battle b , List <Tag > tags , List <BattleOption > opts , Long partCount , String voteStatus ) {
110+ // 유저 상세 응답 변환
111+ public BattleUserDetailResponse toUserDetailResponse (
112+ Battle b , List <Tag > tags , List <BattleOption > opts ,
113+ Long partCount , String voteStatus , String secureThumbnail ,
114+ S3UploadService s3Service ) {
115+
102116 BattleSummaryResponse summary = new BattleSummaryResponse (
103- b .getId (), b .getTitle (), b .getSummary (), b .getThumbnailUrl (), b .getType (),
117+ b .getId (),
118+ b .getTitle (),
119+ b .getSummary (),
120+ secureThumbnail ,
121+ b .getType (),
104122 b .getViewCount () == null ? 0 : b .getViewCount (),
105123 partCount == null ? 0L : partCount ,
106124 b .getAudioDuration () == null ? 0 : b .getAudioDuration (),
107125 toTagResponses (tags , null ),
108- toOptionResponses (opts )
126+ toOptionResponses (opts , s3Service )
109127 );
110128
111129 return new BattleUserDetailResponse (
@@ -125,34 +143,48 @@ public BattleUserDetailResponse toUserDetailResponse(Battle b, List<Tag> tags, L
125143 );
126144 }
127145
128- private List <BattleOptionResponse > toOptionResponses (List <BattleOption > options ) {
146+ // 철학자 이미지 보안 처리를 포함한 옵션 응답 변환
147+ private List <BattleOptionResponse > toOptionResponses (List <BattleOption > options , S3UploadService s3Service ) {
129148 if (options == null ) return List .of ();
149+
130150 return options .stream ()
131151 .map (o -> {
132152 List <Tag > optionTags = optionTagRepository .findByBattleOption (o ).stream ()
133153 .map (BattleOptionTag ::getTag )
134154 .toList ();
135155
156+ // 철학자 이미지 방어 로직 (null/공백일 경우 s3Service 호출 안 함)
157+ String securePhilosopherImg = (o .getImageUrl () != null && !o .getImageUrl ().isBlank ())
158+ ? s3Service .getPresignedUrl (o .getImageUrl (), Duration .ofMinutes (10 ))
159+ : null ;
160+
136161 return new BattleOptionResponse (
137- o .getId (), o .getLabel (), o .getTitle (), o .getStance (),
138- o .getRepresentative (), o .getQuote (), o .getImageUrl (),
162+ o .getId (),
163+ o .getLabel (),
164+ o .getTitle (),
165+ o .getStance (),
166+ o .getRepresentative (),
167+ o .getQuote (),
168+ securePhilosopherImg ,
139169 toTagResponses (optionTags , null )
140170 );
141171 }).toList ();
142172 }
143173
174+ // 투데이 옵션 응답 변환
144175 private List <TodayOptionResponse > toTodayOptionResponses (List <BattleOption > options ) {
145176 if (options == null ) return List .of ();
146177 return options .stream ().map (o -> new TodayOptionResponse (
147178 o .getId (), o .getLabel (), o .getTitle (), o .getRepresentative (), o .getStance (), o .getImageUrl ()
148179 )).toList ();
149180 }
150181
182+ // 태그 응답 변환
151183 private List <BattleTagResponse > toTagResponses (List <Tag > tags , TagType targetType ) {
152184 if (tags == null ) return List .of ();
153185 return tags .stream ()
154186 .filter (t -> targetType == null || t .getType () == targetType )
155187 .map (t -> new BattleTagResponse (t .getId (), t .getName (), t .getType ()))
156188 .toList ();
157189 }
158- }
190+ }
0 commit comments