Skip to content

Commit 326dec0

Browse files
committed
feat: 응원 등록 서비스 로직 개선
1 parent bb70160 commit 326dec0

File tree

5 files changed

+27
-118
lines changed

5 files changed

+27
-118
lines changed
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package eatda.controller.cheer;
22

33
import eatda.domain.cheer.Cheer;
4-
import eatda.domain.cheer.CheerTag;
54
import eatda.domain.cheer.CheerTagName;
65
import eatda.domain.store.Store;
76
import java.util.List;
@@ -14,19 +13,13 @@ public record CheerResponse(
1413
List<CheerTagName> tags
1514
) {
1615

17-
public CheerResponse(Cheer cheer, List<CheerTag> cheerTags, Store store, String imageUrl) {
16+
public CheerResponse(Cheer cheer, Store store, String imageUrl) {
1817
this(
1918
store.getId(),
2019
cheer.getId(),
2120
imageUrl,
2221
cheer.getDescription(),
23-
toTagNames(cheerTags)
22+
cheer.getCheerTagNames()
2423
);
2524
}
26-
27-
private static List<CheerTagName> toTagNames(List<CheerTag> cheerTags) {
28-
return cheerTags.stream()
29-
.map(CheerTag::getName)
30-
.toList();
31-
}
3225
}

src/main/java/eatda/domain/cheer/CheerTagNames.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/java/eatda/service/cheer/CheerService.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import eatda.controller.cheer.CheersResponse;
99
import eatda.domain.ImageKey;
1010
import eatda.domain.cheer.Cheer;
11-
import eatda.domain.cheer.CheerTag;
12-
import eatda.domain.cheer.CheerTagNames;
1311
import eatda.domain.member.Member;
1412
import eatda.domain.store.Store;
1513
import eatda.domain.store.StoreSearchResult;
@@ -43,15 +41,15 @@ public CheerResponse registerCheer(CheerRegisterRequest request,
4341
StoreSearchResult result,
4442
ImageKey imageKey,
4543
long memberId) {
46-
CheerTagNames cheerTagNames = new CheerTagNames(request.tags());
4744
Member member = memberRepository.getById(memberId);
4845
validateRegisterCheer(member, request.storeKakaoId());
4946

5047
Store store = storeRepository.findByKakaoId(result.kakaoId())
5148
.orElseGet(() -> storeRepository.save(result.toStore())); // TODO 상점 조회/저장 동시성 이슈 해결
52-
Cheer cheer = cheerRepository.save(new Cheer(member, store, request.description(), imageKey));
53-
List<CheerTag> cheerTags = cheerTagRepository.saveAll(cheerTagNames.toCheerTags(cheer));
54-
return new CheerResponse(cheer, cheerTags, store, imageStorage.getPreSignedUrl(imageKey));
49+
Cheer cheer = new Cheer(member, store, request.description(), imageKey);
50+
cheer.setCheerTags(request.tags());
51+
Cheer savedCheer = cheerRepository.save(cheer);
52+
return new CheerResponse(savedCheer, store, imageStorage.getPreSignedUrl(imageKey));
5553
}
5654

5755
private void validateRegisterCheer(Member member, String storeKakaoId) {

src/test/java/eatda/domain/cheer/CheerTagNamesTest.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/test/java/eatda/service/cheer/CheerServiceTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,27 @@ class RegisterCheer {
145145
CheerTagName.GOOD_FOR_DATING, CheerTagName.CLEAN_RESTROOM)
146146
);
147147
}
148+
149+
@Test
150+
void 해당_응원의_응원_태그가_비어있어도_응원을_저장할_수_있다() {
151+
Member member = memberGenerator.generate("123");
152+
153+
CheerRegisterRequest request = new CheerRegisterRequest("123", "농민백암순대 본점", "맛있어요!", List.of());
154+
StoreSearchResult result = new StoreSearchResult(
155+
"123", StoreCategory.KOREAN, "02-755-5232", "농민백암순대 본점", "http://place.map.kakao.com/123",
156+
"서울시 강남구 역삼동 123-45", "서울시 강남구 역삼동 123-45", District.GANGNAM, 37.5665, 126.9780);
157+
ImageKey imageKey = new ImageKey("image-key");
158+
159+
CheerResponse response = cheerService.registerCheer(request, result, imageKey, member.getId());
160+
161+
Store foundStore = storeRepository.findByKakaoId("123").orElseThrow();
162+
assertAll(
163+
() -> assertThat(response.storeId()).isEqualTo(foundStore.getId()),
164+
() -> assertThat(response.cheerDescription()).isEqualTo("맛있어요!"),
165+
() -> assertThat(response.imageUrl()).isNotBlank(),
166+
() -> assertThat(response.tags()).isEmpty()
167+
);
168+
}
148169
}
149170

150171
@Nested

0 commit comments

Comments
 (0)