Skip to content

Commit 54f3109

Browse files
authored
Merge pull request #261 from Clokey-dev/develop
[deploy] 배포 (#105)
2 parents 0f10994 + b9f1898 commit 54f3109

53 files changed

Lines changed: 1318 additions & 25 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/dev-cd.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ jobs:
9898
9999
export SWAGGER_USERNAME=${{ secrets.SWAGGER_USERNAME }}
100100
export SWAGGER_PASSWORD=${{ secrets.SWAGGER_PASSWORD }}
101+
102+
export MEILISEARCH_ENDPOINT=${{ secrets.MEILISEARCH_ENDPOINT }}
103+
export MEILISEARCH_KEY=${{ secrets.MEILISEARCH_KEY }}
101104
102105
sudo mkdir -p /home/ubuntu/secrets
103106
echo "${{ secrets.FIREBASE_SA_JSON_B64 }}" | base64 -d | sudo tee /home/ubuntu/secrets/firebase-sa.json > /dev/null
@@ -112,4 +115,4 @@ jobs:
112115
113116
echo "Cleaning up dangling Docker images..."
114117
docker image prune -f
115-
118+

.github/workflows/prod-cd.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ jobs:
108108
109109
export SWAGGER_USERNAME=${{ secrets.SWAGGER_USERNAME }}
110110
export SWAGGER_PASSWORD=${{ secrets.SWAGGER_PASSWORD }}
111+
112+
export MEILISEARCH_ENDPOINT=${{ secrets.MEILISEARCH_ENDPOINT }}
113+
export MEILISEARCH_KEY=${{ secrets.MEILISEARCH_KEY }}
111114
112115
sudo mkdir -p /home/ubuntu/secrets
113116
echo "${{ secrets.FIREBASE_SA_JSON_B64 }}" | base64 -d | sudo tee /home/ubuntu/secrets/firebase-sa.json > /dev/null
@@ -122,4 +125,4 @@ jobs:
122125
123126
echo "Cleaning up dangling Docker images..."
124127
docker image prune -f
125-
128+

clokey-api/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ dependencies {
1919
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
2020

2121
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
22+
23+
implementation 'io.vanslog:spring-data-meilisearch:0.7.3'
2224
}

clokey-api/dev-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ services:
5151
SWAGGER_USERNAME: ${SWAGGER_USERNAME}
5252
SWAGGER_PASSWORD: ${SWAGGER_PASSWORD}
5353

54+
# MeilieSearch
55+
MEILISEARCH_ENDPOINT: ${MEILISEARCH_ENDPOINT}
56+
MEILISEARCH_KEY: ${MEILISEARCH_KEY}
57+
5458
volumes:
5559
- /home/ubuntu/secrets/firebase-sa.json:/run/secrets/firebase-sa.json:ro
5660

clokey-api/prod-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ services:
5151
SWAGGER_USERNAME: ${SWAGGER_USERNAME}
5252
SWAGGER_PASSWORD: ${SWAGGER_PASSWORD}
5353

54+
# MeilieSearch
55+
MEILISEARCH_ENDPOINT: ${MEILISEARCH_ENDPOINT}
56+
MEILISEARCH_KEY: ${MEILISEARCH_KEY}
57+
5458
volumes:
5559
- /home/ubuntu/secrets/firebase-sa.json:/run/secrets/firebase-sa.json:ro
5660

clokey-api/src/main/java/org/clokey/domain/auth/service/AuthServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.clokey.domain.member.repository.PendingFollowRepository;
3636
import org.clokey.domain.notification.repository.CodiveNotificationRepository;
3737
import org.clokey.domain.report.repository.ReportRepository;
38+
import org.clokey.domain.search.event.MemberDeleteEvent;
3839
import org.clokey.domain.term.repository.MemberTermRepository;
3940
import org.clokey.exception.BaseCustomException;
4041
import org.clokey.global.util.MemberUtil;
@@ -322,6 +323,9 @@ public void withdrawMemberById(Long memberId) {
322323

323324
// 15. Member 삭제
324325
memberRepository.delete(currentMember);
326+
327+
// 16. MeiliSearch에 동기화
328+
eventPublisher.publishEvent(MemberDeleteEvent.of(memberId, historyIds));
325329
}
326330

327331
private Member getMember(RefreshTokenDto refreshTokenDto) {

clokey-api/src/main/java/org/clokey/domain/auth/service/CustomOAuth2UserService.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
package org.clokey.domain.auth.service;
22

33
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
45
import org.clokey.domain.auth.util.UniqueUtil;
56
import org.clokey.domain.member.repository.MemberRepository;
7+
import org.clokey.domain.search.event.MeiliSearchSyncEvent;
68
import org.clokey.global.security.CustomPrincipal;
79
import org.clokey.member.entity.Member;
810
import org.clokey.member.entity.OauthInfo;
911
import org.clokey.member.enums.OauthProvider;
12+
import org.springframework.context.ApplicationEventPublisher;
1013
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest;
1114
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService;
1215
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
1316
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
1417
import org.springframework.stereotype.Service;
18+
import org.springframework.transaction.annotation.Transactional;
1519

20+
@Slf4j
1621
@Service
1722
@RequiredArgsConstructor
1823
public class CustomOAuth2UserService extends OidcUserService {
1924

2025
private final MemberRepository memberRepository;
2126
private final UniqueUtil uniqueUtil;
27+
private final ApplicationEventPublisher eventPublisher;
2228

2329
@Override
30+
@Transactional
2431
public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
2532
OidcUser oidcUser = super.loadUser(userRequest);
2633

@@ -42,7 +49,12 @@ public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2Authenticatio
4249
uniqueUtil.generateRandomId(),
4350
uniqueUtil.generateRandomNickname(),
4451
oauthInfo);
45-
return memberRepository.save(newMember);
52+
memberRepository.save(newMember);
53+
eventPublisher.publishEvent(
54+
MeiliSearchSyncEvent.of(
55+
MeiliSearchSyncEvent.EntityType.MEMBER,
56+
newMember.getId()));
57+
return newMember;
4658
});
4759

4860
return new CustomPrincipal(member, oidcUser.getAttributes(), oidcUser.getIdToken());

clokey-api/src/main/java/org/clokey/domain/cloth/service/ClothServiceImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.clokey.domain.coordinate.repository.CoordinateClothRepository;
2121
import org.clokey.domain.history.repository.HistoryClothTagRepository;
2222
import org.clokey.domain.image.event.ImageDeleteEvent;
23+
import org.clokey.domain.search.event.ClothDeleteEvent;
24+
import org.clokey.domain.search.event.MeiliSearchSyncEvent;
2325
import org.clokey.enums.ImageType;
2426
import org.clokey.exception.BaseCustomException;
2527
import org.clokey.global.paging.SortDirection;
@@ -159,13 +161,26 @@ public void updateCloth(Long clothId, ClothUpdateRequest request) {
159161
eventPublisher.publishEvent(ImageDeleteEvent.of(cloth.getClothImageUrl()));
160162
}
161163

164+
// Category 변경 여부 확인
165+
boolean categoryChanged = !cloth.getCategory().getId().equals(category.getId());
166+
162167
cloth.updateCloth(
163168
request.clothImageUrl(),
164169
request.clothUrl(),
165170
request.name(),
166171
request.brand(),
167172
request.seasons(),
168173
category);
174+
175+
// Category 변경 시 해당 Cloth를 사용하는 History들 검색엔진 동기화
176+
if (categoryChanged) {
177+
List<Long> historyIds = historyClothTagRepository.findHistoryIdsByClothId(clothId);
178+
for (Long historyId : historyIds) {
179+
eventPublisher.publishEvent(
180+
MeiliSearchSyncEvent.of(
181+
MeiliSearchSyncEvent.EntityType.HISTORY, historyId));
182+
}
183+
}
169184
}
170185

171186
/**
@@ -181,11 +196,17 @@ public void deleteCloth(Long clothId) {
181196

182197
validateClothOwnership(cloth, currentMember.getId());
183198

199+
List<Long> historyIds = historyClothTagRepository.findHistoryIdsByClothId(clothId);
200+
184201
coordinateClothRepository.deleteAllByClothId(cloth.getId());
185202
historyClothTagRepository.deleteAllByClothId(cloth.getId());
186203

187204
eventPublisher.publishEvent(ImageDeleteEvent.of(cloth.getClothImageUrl()));
188205
clothRepository.delete(cloth);
206+
207+
if (!historyIds.isEmpty()) {
208+
eventPublisher.publishEvent(ClothDeleteEvent.of(clothId, historyIds));
209+
}
189210
}
190211

191212
private Map<Long, Category> getCategoryMapByIds(Set<Long> ids) {

clokey-api/src/main/java/org/clokey/domain/history/repository/HistoryClothTagRepository.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public interface HistoryClothTagRepository
1111
extends JpaRepository<HistoryClothTag, Long>, HistoryClothTagRepositoryCustom {
1212
List<HistoryClothTag> findByHistoryImageId(Long historyImageId);
1313

14-
List<HistoryClothTag> findAllByClothId(Long clothId);
15-
1614
@Modifying
1715
@Query("DELETE FROM HistoryClothTag hct WHERE hct.cloth.id = :clothId")
1816
void deleteAllByClothId(Long clothId);
@@ -26,4 +24,8 @@ public interface HistoryClothTagRepository
2624
+ "join fetch hct.cloth "
2725
+ "where hct.historyImage.id = :historyImageId")
2826
List<HistoryClothTag> findAllByHistoryImageIdWithCloth(Long historyImageId);
27+
28+
@Query(
29+
"SELECT DISTINCT hct.historyImage.history.id FROM HistoryClothTag hct WHERE hct.cloth.id = :clothId")
30+
List<Long> findHistoryIdsByClothId(@Param("clothId") Long clothId);
2931
}

clokey-api/src/main/java/org/clokey/domain/history/repository/HistoryRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ and FUNCTION('MONTH', h.historyDate) = :month
2323
""")
2424
List<History> findByMemberIdAndYearAndMonthNotBanned(Long memberId, int year, int month);
2525

26+
@Query("SELECT h.id FROM History h WHERE h.member.id = :memberId")
27+
List<Long> findAllIdsByMemberId(Long memberId);
28+
29+
@Query("SELECT h.id FROM History h")
30+
List<Long> findAllIds();
31+
2632
@Query(
2733
"""
2834
select new org.clokey.domain.history.repository.HistoryRepository$HistorySituationInfo(

0 commit comments

Comments
 (0)