diff --git a/.github/workflows/android-cd.yml b/.github/workflows/android-cd.yml index ff40666dc..413857c5e 100644 --- a/.github/workflows/android-cd.yml +++ b/.github/workflows/android-cd.yml @@ -2,8 +2,7 @@ name: Android CI/CD for release on: push: - branches: [ "main" ] - pull_request: + paths: 'android/**' branches: [ "main" ] env: diff --git a/.github/workflows/android-ci-cd-demo-apk.yml b/.github/workflows/android-ci-cd-demo-apk.yml.disabled similarity index 98% rename from .github/workflows/android-ci-cd-demo-apk.yml rename to .github/workflows/android-ci-cd-demo-apk.yml.disabled index 8d1bf76ac..79dfd12f1 100644 --- a/.github/workflows/android-ci-cd-demo-apk.yml +++ b/.github/workflows/android-ci-cd-demo-apk.yml.disabled @@ -2,8 +2,7 @@ name: Android CI/CD for generating demo APK on: push: - branches: [ "develop" ] - pull_request: + paths: 'android/**' branches: [ "develop" ] env: diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 3c3258493..baeac0ce0 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -1,9 +1,8 @@ name: Android CI for develop-an on: - push: - branches: [ "develop-an" ] pull_request: + paths: 'android/**' branches: [ "develop-an" ] env: @@ -68,70 +67,11 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Clean test - run: ./gradlew clean test - - build: - needs: test - name: Build and Run - runs-on: ubuntu-latest - - defaults: - run: - shell: bash - working-directory: ./android/Staccato_AN - - permissions: - contents: read - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: gradle - - - name: Create local.properties - run: | - touch local.properties - shell: bash - - - name: Set Base Url in local.properties - run: | - echo "base_url=\"$BASE_URL\"" >> local.properties - shell: bash - - - name: Create google-services.json - run: | - echo $GOOGLE_SERVICES_JSON > ./app/google-services.json - shell: bash - - - name: Create secrets.properties - run: | - echo $SECRETS_PROPERTIES > secrets.properties - shell: bash - - - name: Create local.defaults.properties - run: | - echo $LOCAL_DEFAULTS_PROPERTIES > local.defaults.properties - shell: bash - - - name: Create KeyStore File and Properties - run: | - mkdir -p ./app/signing - echo "$UPLOAD_KEY_STORE_JKS" | base64 --decode > ./app/signing/upload_key_store.jks - echo "$KEY_STORE_PROPERTIES" > ./app/signing/keystore.properties - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Run ktlint run: ./gradlew ktlintCheck + - name: Run test + run: ./gradlew test + - name: Build with Gradle run: ./gradlew build diff --git a/.github/workflows/backend-ci-cd-dev.yml b/.github/workflows/backend-ci-cd-dev.yml index c92e4f4cb..0099e7967 100644 --- a/.github/workflows/backend-ci-cd-dev.yml +++ b/.github/workflows/backend-ci-cd-dev.yml @@ -2,6 +2,7 @@ name: Backend CI/CD dev on: pull_request: + paths: 'backend/**' branches: [ "develop-be", "develop" ] jobs: diff --git a/.github/workflows/backend-ci-cd-prod.yml b/.github/workflows/backend-ci-cd-prod.yml index ec42030b7..e91eaa781 100644 --- a/.github/workflows/backend-ci-cd-prod.yml +++ b/.github/workflows/backend-ci-cd-prod.yml @@ -2,6 +2,7 @@ name: Backend CI/CD prod on: push: + paths: 'backend/**' branches: ["main"] jobs: diff --git a/.github/workflows/backend-ci-cd-stage.yml b/.github/workflows/backend-ci-cd-stage.yml index 70c341f41..999fff3e5 100644 --- a/.github/workflows/backend-ci-cd-stage.yml +++ b/.github/workflows/backend-ci-cd-stage.yml @@ -2,6 +2,7 @@ name: Backend CI/CD stage on: push: + paths: 'backend/**' branches: [ "develop-be", "develop" ] jobs: diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml index 6cb242694..44e07d7b6 100644 --- a/.github/workflows/backend-ci.yml +++ b/.github/workflows/backend-ci.yml @@ -2,6 +2,7 @@ name: Backend CI on: pull_request: + paths: 'backend/**' branches: [ "develop-be", "develop", "main" ] permissions: write-all diff --git a/backend/src/main/java/com/staccato/memory/repository/MemoryMemberRepository.java b/backend/src/main/java/com/staccato/memory/repository/MemoryMemberRepository.java index b21768370..dd7ac4b17 100644 --- a/backend/src/main/java/com/staccato/memory/repository/MemoryMemberRepository.java +++ b/backend/src/main/java/com/staccato/memory/repository/MemoryMemberRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import com.staccato.member.domain.Member; import com.staccato.memory.domain.MemoryMember; public interface MemoryMemberRepository extends JpaRepository { @@ -19,4 +20,6 @@ public interface MemoryMemberRepository extends JpaRepository findAllByMemberIdAndIncludingDateOrderByCreatedAtDesc(@Param("memberId") long memberId, @Param("date") LocalDate date); + + boolean existsByMemberAndMemoryTitle(Member member, String title); } diff --git a/backend/src/main/java/com/staccato/memory/repository/MemoryRepository.java b/backend/src/main/java/com/staccato/memory/repository/MemoryRepository.java index 76e006028..3d2fd7114 100644 --- a/backend/src/main/java/com/staccato/memory/repository/MemoryRepository.java +++ b/backend/src/main/java/com/staccato/memory/repository/MemoryRepository.java @@ -5,5 +5,4 @@ import com.staccato.memory.domain.Memory; public interface MemoryRepository extends JpaRepository { - boolean existsByTitle(String title); } diff --git a/backend/src/main/java/com/staccato/memory/service/MemoryService.java b/backend/src/main/java/com/staccato/memory/service/MemoryService.java index 6cc89e30c..df4221475 100644 --- a/backend/src/main/java/com/staccato/memory/service/MemoryService.java +++ b/backend/src/main/java/com/staccato/memory/service/MemoryService.java @@ -34,8 +34,8 @@ public class MemoryService { @Transactional public MemoryIdResponse createMemory(MemoryRequest memoryRequest, Member member) { - validateMemoryTitle(memoryRequest.memoryTitle()); Memory memory = memoryRequest.toMemory(); + validateMemoryTitle(memory, member); memory.addMemoryMember(member); memoryRepository.save(memory); return new MemoryIdResponse(memory.getId()); @@ -83,10 +83,10 @@ private String getMomentThumbnail(Moment moment) { public void updateMemory(MemoryRequest memoryRequest, Long memoryId, Member member) { Memory originMemory = getMemoryById(memoryId); validateOwner(originMemory, member); + Memory updatedMemory = memoryRequest.toMemory(); if (originMemory.isNotSameTitle(memoryRequest.memoryTitle())) { - validateMemoryTitle(memoryRequest.memoryTitle()); + validateMemoryTitle(updatedMemory, member); } - Memory updatedMemory = memoryRequest.toMemory(); List moments = momentRepository.findAllByMemoryIdOrderByVisitedAt(memoryId); originMemory.update(updatedMemory, moments); } @@ -96,8 +96,8 @@ private Memory getMemoryById(long memoryId) { .orElseThrow(() -> new StaccatoException("요청하신 추억을 찾을 수 없어요.")); } - private void validateMemoryTitle(String title) { - if (memoryRepository.existsByTitle(title)) { + private void validateMemoryTitle(Memory memory, Member member) { + if (memoryMemberRepository.existsByMemberAndMemoryTitle(member, memory.getTitle())) { throw new StaccatoException("같은 이름을 가진 추억이 있어요. 다른 이름으로 설정해주세요."); } } diff --git a/backend/src/test/java/com/staccato/memory/service/MemoryServiceTest.java b/backend/src/test/java/com/staccato/memory/service/MemoryServiceTest.java index 13739d7df..ac3ac7585 100644 --- a/backend/src/test/java/com/staccato/memory/service/MemoryServiceTest.java +++ b/backend/src/test/java/com/staccato/memory/service/MemoryServiceTest.java @@ -82,7 +82,7 @@ void createMemory() { ); } - @DisplayName("이미 존재하는 추억 이름으로 추억을 생성할 수 없다.") + @DisplayName("사용자의 추억 중 이미 존재하는 추억 이름으로 추억을 생성할 수 없다.") @Test void cannotCreateMemoryByDuplicatedTitle() { // given @@ -96,6 +96,19 @@ void cannotCreateMemoryByDuplicatedTitle() { .hasMessage("같은 이름을 가진 추억이 있어요. 다른 이름으로 설정해주세요."); } + @DisplayName("다른 사용자의 이미 존재하는 추억 이름으로 추억을 생성할 수 있다.") + @Test + void canCreateMemoryByDuplicatedTitleOfOther() { + // given + MemoryRequest memoryRequest = MemoryRequestFixture.create(LocalDate.of(2024, 7, 1), LocalDate.of(2024, 7, 10)); + Member member = memberRepository.save(MemberFixture.create()); + Member otherMember = memberRepository.save(MemberFixture.create("other")); + memoryService.createMemory(memoryRequest, otherMember); + + // when & then + assertThatNoException().isThrownBy(() -> memoryService.createMemory(memoryRequest, member)); + } + @DisplayName("현재 날짜를 포함하는 모든 추억 목록을 조회한다.") @MethodSource("dateProvider") @ParameterizedTest