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
48 changes: 37 additions & 11 deletions .github/workflows/dev-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ name: dev-CI

on:
pull_request:
branches:
- develop
types:
- opened
- synchronize
- reopened
branches: [ "develop" ]

jobs:
dev-ci:
# Using Environment - dev 환경
environment: dev

# Operating system - ubuntu-22.04
Expand All @@ -31,14 +28,43 @@ jobs:

# gradle caching - 빌드 시간 향상
- name: Gradle Caching
uses: gradle/actions/setup-gradle@v4
uses: actions/cache@v3
with:
gradle-home-cache-cleanup: true
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

# Inject environment variables - application-secret.properties 생성
- name: Inject application-secret.properties
# Inject environment variables - 환경 변수를 yml 파일에 주입
- name: Inject environment variables into application-dev.yml
env:
DEV_DB_URL: ${{ secrets.DEV_DB_URL }}
DEV_DB_USERNAME: ${{ secrets.DEV_DB_USERNAME }}
DEV_DB_PASSWORD: ${{ secrets.DEV_DB_PASSWORD }}
DEV_JWT_SECRET: ${{ secrets.DEV_JWT_SECRET }}
DEV_KAKAO_CLIENT_ID: ${{ secrets.DEV_KAKAO_CLIENT_ID }}
DEV_KAKAO_CLIENT_SECRET: ${{ secrets.DEV_KAKAO_CLIENT_SECRET }}
DEV_KAKAO_REDIRECT_URI: ${{ secrets.DEV_KAKAO_REDIRECT_URI }}
DEV_REDIS_HOST: ${{ secrets.DEV_REDIS_HOST }}
DEV_REDIS_PORT: ${{ secrets.DEV_REDIS_PORT }}
DEV_REDIS_PASSWORD: ${{ secrets.DEV_REDIS_PASSWORD }}
DEV_S3_ACCESS_KEY: ${{ secrets.DEV_S3_ACCESS_KEY }}
DEV_S3_SECRET_KEY: ${{ secrets.DEV_S3_SECRET_KEY }}
DEV_COOLSMS_KEY: ${{ secrets.DEV_COOLSMS_KEY }}
DEV_COOLSMS_NUMBER: ${{ secrets.DEV_COOLSMS_NUMBER }}
DEV_COOLSMS_SECRET: ${{ secrets.DEV_COOLSMS_SECRET }}
DEV_ACCESS_TOKEN_EXPIRE_TIME: ${{ secrets.DEV_ACCESS_TOKEN_EXPIRE_TIME }}
DEV_REFRESH_TOKEN_EXPIRE_TIME: ${{ secrets.DEV_REFRESH_TOKEN_EXPIRE_TIME }}
DEV_ALLOWED_ORIGINS: ${{ secrets.DEV_ALLOWED_ORIGINS }}
DEV_SERVER_URL: ${{ secrets.DEV_SERVER_URL }}
DEV_ACTUATOR_PORT: ${{ secrets.DEV_ACTUATOR_PORT }}
DEV_ACTUATOR_PATH: ${{ secrets.DEV_ACTUATOR_PATH }}
DEV_SLACK_WEBHOOK_URL: ${{ secrets.DEV_SLACK_WEBHOOK_URL }}
run: |
echo "${{ secrets.APPLICATION_SECRET_SPRING }}" > src/main/resources/application-secret.properties
cd ./src/main/resources
envsubst < application-dev.yml > application-dev.tmp.yml && mv application-dev.tmp.yml application-dev.yml

# gradle build - 테스트 없이 gradle 빌드
- name: Build with Gradle
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ Temporary Items
# End of https://www.toptal.com/developers/gitignore/api/intellij,java,macos.gradle/
.idea/

# Ignore application profile
# Ignore application-local.yml
src/main/resources/application-local.yml
src/main/resources/application-secret.properties

## Ignore Qclass
src/main/generated/querydsl
26 changes: 12 additions & 14 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pipeline {
agent any

environment {
// PORT
EXTERNAL_PORT_BLUE = credentials('EXTERNAL_PORT_BLUE')
EXTERNAL_PORT_GREEN = credentials('EXTERNAL_PORT_GREEN')
// PORT
EXTERNAL_PORT_BLUE = credentials('EXTERNAL_PORT_BLUE')
EXTERNAL_PORT_GREEN = credentials('EXTERNAL_PORT_GREEN')
}

stages {
Expand All @@ -23,7 +23,6 @@ pipeline {
// DOCKER
DOCKER_HUB_DEV_CREDENTIAL_ID = 'DOCKER_HUB_DEV_CREDENTIALS'
DOCKER_HUB_PROD_CREDENTIAL_ID = 'DOCKER_HUB_PROD_CREDENTIALS'
DOCKER_HUB_CREDENTIAL_ID = BRANCH_NAME.equals(PROD_BRANCH) ? DOCKER_HUB_PROD_CREDENTIAL_ID : DOCKER_HUB_DEV_CREDENTIAL_ID

// SSH
SSH_CREDENTIAL_ID = OPERATION_ENV.toUpperCase() + '_SSH'
Expand All @@ -32,20 +31,10 @@ pipeline {

// ENVIRONMENT CONFIG FILE
ENVIRONMENT_CONFIG_FILE = 'application-' + OPERATION_ENV + '.yml'

echo "Branch: ${BRANCH_NAME}, Environment: ${OPERATION_ENV}"
}
}
}

stage('Git Checkout') {
steps {
echo 'Checkout Remote Repository'
git branch: "${env.BRANCH_NAME}",
url: REPOSITORY_URL
}
}

stage('Parse Internal Port') {
steps {
script {
Expand All @@ -55,10 +44,19 @@ pipeline {
}
}

stage('Git Checkout') {
steps {
echo 'Checkout Remote Repository'
git branch: "${env.BRANCH_NAME}",
url: REPOSITORY_URL
}
}

stage('Deploy to Server') {
steps {
echo 'Deploy to Server'
script {
def DOCKER_HUB_CREDENTIAL_ID = BRANCH_NAME.equals(PROD_BRANCH) ? DOCKER_HUB_PROD_CREDENTIAL_ID : DOCKER_HUB_DEV_CREDENTIAL_ID
withCredentials([
usernamePassword(credentialsId: DOCKER_HUB_CREDENTIAL_ID,
usernameVariable: 'DOCKER_HUB_ID',
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/beat/domain/booking/dao/BookingRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.data.repository.query.Param;

import com.beat.domain.booking.domain.Booking;
import com.beat.domain.booking.domain.BookingStatus;

public interface BookingRepository extends JpaRepository<Booking, Long> {
@Query("SELECT b FROM Booking b " +
Expand All @@ -34,9 +33,6 @@ Optional<Booking> findFirstByBookerNameAndBookerPhoneNumberAndBirthDateAndPasswo

List<Booking> findByUsersId(Long userId);

@Query("SELECT COUNT(b) > 0 FROM Booking b WHERE b.schedule.id IN :scheduleIds AND b.bookingStatus NOT IN :excludedStatuses")
boolean existsActiveBookingByScheduleIds(
@Param("scheduleIds") List<Long> scheduleIds,
@Param("excludedStatuses") List<BookingStatus> excludedStatuses
);
}
@Query("SELECT COUNT(b) > 0 FROM Booking b WHERE b.schedule.id IN :scheduleIds AND b.bookingStatus != 'BOOKING_CANCELLED'")
boolean existsByScheduleIdIn(@Param("scheduleIds") List<Long> scheduleIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.beat.domain.booking.dao.BookingRepository;
import com.beat.domain.booking.domain.BookingStatus;
import com.beat.domain.cast.dao.CastRepository;
import com.beat.domain.cast.domain.Cast;
import com.beat.domain.member.dao.MemberRepository;
Expand Down Expand Up @@ -96,7 +96,7 @@ public PerformanceResponse createPerformance(Long memberId, PerformanceRequest r
performance
);
})
.toList();
.collect(Collectors.toList());

performance.assignScheduleNumbers(schedules);
scheduleRepository.saveAll(schedules);
Expand All @@ -105,7 +105,7 @@ public PerformanceResponse createPerformance(Long memberId, PerformanceRequest r

List<LocalDateTime> performanceDates = schedules.stream()
.map(Schedule::getPerformanceDate)
.toList();
.collect(Collectors.toList());
performance.updatePerformancePeriod(performanceDates);
performanceRepository.save(performance);

Expand All @@ -116,7 +116,7 @@ public PerformanceResponse createPerformance(Long memberId, PerformanceRequest r
castRequest.castPhoto(),
performance
))
.toList();
.collect(Collectors.toList());
castRepository.saveAll(casts);

List<Staff> staffs = request.staffList().stream()
Expand All @@ -126,15 +126,15 @@ public PerformanceResponse createPerformance(Long memberId, PerformanceRequest r
staffRequest.staffPhoto(),
performance
))
.toList();
.collect(Collectors.toList());
staffRepository.saveAll(staffs);

List<PerformanceImage> performanceImageList = request.performanceImageList().stream()
.map(performanceImageRequest -> PerformanceImage.create(
performanceImageRequest.performanceImage(),
performance
))
.toList();
.collect(Collectors.toList());
performanceImageRepository.saveAll(performanceImageList);

return mapToPerformanceResponse(performance, schedules, casts, staffs, performanceImageList);
Expand All @@ -150,7 +150,7 @@ private PerformanceResponse mapToPerformanceResponse(Performance performance, Li
calculateDueDate(schedule.getPerformanceDate().toLocalDate()),
schedule.getScheduleNumber()
))
.toList();
.collect(Collectors.toList());

List<CastResponse> castResponses = casts.stream()
.map(cast -> CastResponse.of(
Expand All @@ -159,7 +159,7 @@ private PerformanceResponse mapToPerformanceResponse(Performance performance, Li
cast.getCastRole(),
cast.getCastPhoto()
))
.toList();
.collect(Collectors.toList());

List<StaffResponse> staffResponses = staffs.stream()
.map(staff -> StaffResponse.of(
Expand All @@ -168,14 +168,14 @@ private PerformanceResponse mapToPerformanceResponse(Performance performance, Li
staff.getStaffRole(),
staff.getStaffPhoto()
))
.toList();
.collect(Collectors.toList());

List<PerformanceImageResponse> performanceImageResponses = performanceImages.stream()
.map(image -> PerformanceImageResponse.of(
image.getId(),
image.getPerformanceImageUrl()
))
.toList();
.collect(Collectors.toList());

return PerformanceResponse.of(
performance.getUsers().getId(),
Expand Down Expand Up @@ -226,10 +226,9 @@ public void deletePerformance(Long memberId, Long performanceId) {

List<Long> scheduleIds = scheduleRepository.findIdsByPerformanceId(performanceId);

List<BookingStatus> statusesToExclude = List.of(BookingStatus.BOOKING_CANCELLED, BookingStatus.BOOKING_DELETED);
boolean isBookerExist = bookingRepository.existsActiveBookingByScheduleIds(scheduleIds, statusesToExclude);
boolean hasBookings = bookingRepository.existsByScheduleIdIn(scheduleIds);

if (isBookerExist) {
if (hasBookings) {
throw new ForbiddenException(PerformanceErrorCode.PERFORMANCE_DELETE_FAILED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.beat.domain.booking.dao.BookingRepository;
import com.beat.domain.booking.domain.BookingStatus;
import com.beat.domain.cast.dao.CastRepository;
import com.beat.domain.cast.domain.Cast;
import com.beat.domain.cast.exception.CastErrorCode;
Expand Down Expand Up @@ -73,9 +73,7 @@ public PerformanceModifyResponse modifyPerformance(Long memberId, PerformanceMod
validateOwnership(userId, performance);

List<Long> scheduleIds = scheduleRepository.findIdsByPerformanceId(request.performanceId());

List<BookingStatus> statusesToExclude = List.of(BookingStatus.BOOKING_CANCELLED, BookingStatus.BOOKING_DELETED);
boolean isBookerExist = bookingRepository.existsActiveBookingByScheduleIds(scheduleIds, statusesToExclude);
boolean isBookerExist = bookingRepository.existsByScheduleIdIn(scheduleIds);

if (isBookerExist && request.ticketPrice() != performance.getTicketPrice()) {
log.error("Ticket price update failed due to existing bookings for performanceId: {}", performance.getId());
Expand Down Expand Up @@ -150,7 +148,7 @@ private void updatePerformanceDetails(Performance performance, PerformanceModify

List<LocalDateTime> performanceDates = request.scheduleModifyRequests().stream()
.map(ScheduleModifyRequest::performanceDate)
.toList();
.collect(Collectors.toList());
performance.updatePerformancePeriod(performanceDates);

if (!isBookerExist) {
Expand All @@ -169,11 +167,11 @@ private List<ScheduleModifyResponse> processSchedules(List<ScheduleModifyRequest
List<Long> requestScheduleIds = scheduleRequests.stream()
.map(ScheduleModifyRequest::scheduleId)
.filter(Objects::nonNull)
.toList();
.collect(Collectors.toList());

List<Long> schedulesToDelete = existingScheduleIds.stream()
.filter(id -> !requestScheduleIds.contains(id))
.toList();
.collect(Collectors.toList());

deleteRemainingSchedules(schedulesToDelete);

Expand All @@ -193,7 +191,7 @@ private List<ScheduleModifyResponse> processSchedules(List<ScheduleModifyRequest

return schedule;
})
.toList();
.collect(Collectors.toList());

performance.assignScheduleNumbers(schedules);

Expand All @@ -205,7 +203,7 @@ private List<ScheduleModifyResponse> processSchedules(List<ScheduleModifyRequest
calculateDueDate(schedule.getPerformanceDate()),
schedule.getScheduleNumber()
))
.toList();
.collect(Collectors.toList());
}

private Schedule addSchedule(ScheduleModifyRequest request, Performance performance) {
Expand Down Expand Up @@ -411,7 +409,7 @@ private List<StaffModifyResponse> processStaffs(List<StaffModifyRequest> staffRe
return updateStaff(request, performance);
}
})
.toList();
.collect(Collectors.toList());

deleteRemainingStaffs(existingStaffIds);

Expand Down
Loading