Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .github/workflows/cd-for-no-es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CD - upload to EC2 with no elasticsearch

on:
push:
branches:
- develop-no-es

jobs:
upload-to-ec2 :
runs-on: ubuntu-latest

services:
postgres:
image: postgres:16
env:
POSTGRES_DB: ${{ secrets.DB_DATABASE_NAME }}
POSTGRES_USER: ${{ secrets.DB_USERNAME }}
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: 소스 코드 Checkout
uses: actions/checkout@v4

- name: Redis 실행
uses: supercharge/[email protected]

- name: .env 설정
run: |
echo "SPRING_PROFILES_ACTIVE=ci" >> $GITHUB_ENV
echo "DB_URL=${{ secrets.DB_URL }}" >> $GITHUB_ENV
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> $GITHUB_ENV
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> $GITHUB_ENV
echo "REDIS_HOST=${{ secrets.REDIS_HOST }}" >> $GITHUB_ENV
echo "REDIS_PORT=${{ secrets.REDIS_PORT }}" >> $GITHUB_ENV
echo "JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}" >> $GITHUB_ENV
echo "JWT_VALIDATION_TIME=${{ secrets.JWT_VALIDATION_TIME }}" >> $GITHUB_ENV
echo "SOCIAL_CLIENT_ID=${{ secrets.SOCIAL_CLIENT_ID }}" >> $GITHUB_ENV
echo "SOCIAL_SECRET=${{ secrets.SOCIAL_SECRET }}" >> $GITHUB_ENV
echo "API_KEY=${{ secrets.API_KEY }}" >> $GITHUB_ENV
echo "API_SECRET=${{ secrets.API_SECRET }}" >> $GITHUB_ENV
echo "S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }}" >> $GITHUB_ENV
echo "S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }}" >> $GITHUB_ENV
echo "S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}" >> $GITHUB_ENV
echo "S3_BUCKET_URL=${{ secrets.S3_BUCKET_URL }}" >> $GITHUB_ENV
echo "LOGSTASH_URL=${{ secrets.LOGSTASH_URL }}" >> $GITHUB_ENV
echo "OCR_JSON=${{ secrets.OCR_JSON }}" >> $GITHUB_ENV
echo "FIRE_BASE_JSON=${{ secrets.FIRE_BASE_JSON }}" >> $GITHUB_ENV
echo "GOOGLE_MAIL=${{ secrets.GOOGLE_MAIL }}" >> $GITHUB_ENV
echo "GOOGLE_MAIL_PASSWORD=${{ secrets.GOOGLE_MAIL_PASSWORD }}" >> $GITHUB_ENV

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: 실행 권한 부여
run: chmod +x ./gradlew

- name: firebase.json 복원
run: |
echo "${{ secrets.FIRE_BASE_BASE_64_JSON }}" | base64 -d > src/main/resources/firebase.json

- name: 빌드 테스트
run: ./gradlew clean build -x test

- name: Docker Hub 로그인
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Build 후 Docker image push
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/badata:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/badata:latest

- name: EC2 배포
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ubuntu

echo "기존 컨테이너 중지 및 제거"
sudo docker stop badata_be || true
sudo docker rm badata_be || true

echo "새로운 이미지 빌드"
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/badata:latest
sudo docker run --add-host host.docker.internal:host-gateway --env-file ~/be_badata/.env -v ~/be_badata${{ secrets.OCR_JSON }}:/BaData/src${{ secrets.OCR_JSON }} -d -p 8080:8080 --name badata_be ${{ secrets.DOCKER_USERNAME }}/badata:latest

echo "배포 완료"

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import com.TwoSeaU.BaData.domain.trade.entity.Gifticon;
import com.TwoSeaU.BaData.domain.trade.entity.Payment;
import com.TwoSeaU.BaData.domain.trade.entity.Post;
import com.TwoSeaU.BaData.domain.trade.entity.PostDocument;
import com.TwoSeaU.BaData.domain.trade.enums.PayMethod;
import com.TwoSeaU.BaData.domain.trade.enums.PaymentStatus;
import com.TwoSeaU.BaData.domain.trade.exception.TradeException;
import com.TwoSeaU.BaData.domain.trade.repository.PaymentRepository;
import com.TwoSeaU.BaData.domain.trade.repository.PostDocumentRepository;
import com.TwoSeaU.BaData.domain.trade.repository.PostRepository;
import com.TwoSeaU.BaData.domain.user.entity.CoinHistory;
import com.TwoSeaU.BaData.domain.user.entity.User;
Expand Down Expand Up @@ -42,7 +40,6 @@
@Transactional
public class PaymentService {
private final PaymentRepository paymentRepository;
private final PostDocumentRepository postDocumentRepository;
private final UserRepository userRepository;
private final PostRepository postRepository;
private final CoinHistoryRepository coinHistoryRepository;
Expand Down Expand Up @@ -164,9 +161,6 @@ public GetValidatePaymentResponse validateIamport(final String impUid, final Lon

payment.updatePaymentStatus(PaymentStatus.PAID);

final PostDocument postDocument = PostDocument.from(post);
postDocumentRepository.delete(postDocument);

user.updateUsedCoin(payment.getUseCoin().intValue());

if (payment.getUseCoin().intValue() > 0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import co.elastic.clients.elasticsearch._types.query_dsl.TextQueryType;
import com.TwoSeaU.BaData.domain.trade.dto.response.PostResponse;
import com.TwoSeaU.BaData.domain.trade.entity.Post;
import com.TwoSeaU.BaData.domain.trade.entity.PostDocument;
import com.TwoSeaU.BaData.domain.trade.exception.TradeException;
import com.TwoSeaU.BaData.domain.trade.repository.PostLikesRepository;
import com.TwoSeaU.BaData.domain.trade.repository.PostRepository;
Expand Down Expand Up @@ -95,61 +94,13 @@ private Query getQuery(final String query) {
._toQuery();
}

public CursorPageResponse<PostResponse> searchByTitleAndComment(final String userQuery, final String username, final Long cursor, final int size) {
final User user = username == null ? null : userRepository.findByUsername(username)
.orElseThrow(() -> new GeneralException(UserException.USER_NOT_FOUND));

final NativeQueryBuilder nativeQueryBuilder = new NativeQueryBuilder()
.withQuery(getQuery(userQuery))
.withSort(
SortOptions.of(
s -> s.field(f -> f.field("id").order(Desc))
)
)
.withMaxResults(size + 1);

if (cursor != null) {
nativeQueryBuilder.withSearchAfter(List.of(cursor));
}

final SearchHits<PostDocument> searchHits = elasticsearchOperations.search(
nativeQueryBuilder.build(),
PostDocument.class,
IndexCoordinates.of(INDEX_NAME)
);

final boolean hasNext = searchHits.getSearchHits().size() > size;

final List<SearchHit<PostDocument>> postDocuments = hasNext ? searchHits.getSearchHits().subList(0, size) : searchHits.getSearchHits();

final Long nextCursor = postDocuments.isEmpty() ? null : postDocuments.get(postDocuments.size() - 1).getContent().getId();

final List<Long> postIds = postDocuments.stream()
.map(hit -> hit.getContent().getId())
.toList();

final Map<Long, Post> postMap = postRepository.findAllById(postIds).stream()
.collect(Collectors.toMap(Post::getId, post -> post));
public CursorPageResponse<PostResponse> searchByTitleAndComment(final String query, final String username, final Long cursor, final int size) {

final Map<Long, Integer> postLikesCountMap = postLikesRepository.countByPostIds(postIds);

final Set<Long> likedPostIds = username != null ? postLikesRepository.findLikedPostIdsByUserIdAndPostIds(user.getId(), postIds) : Set.of();

final List<PostResponse> responseList = postDocuments.stream()
.map(hit -> {
final Long postId = hit.getContent().getId();
final Post post = postMap.get(postId);
if (post == null) {
throw new GeneralException(TradeException.POST_NOT_FOUND);
}
return PostResponse.from(
post,
postLikesCountMap.getOrDefault(postId, 0),
likedPostIds.contains(postId)
);
})
.toList();
if (query != null && !query.isEmpty()) {
log.info("event-keyword-search, {}", query);
saveSearchHistoryIfUserExists(username, query);
}

return CursorPageResponse.of(responseList, nextCursor, hasNext);
return postRepository.searchPostsByKeyword(query, username, cursor, size);
}
}
Loading