From 21e297ae129af13b9bcf89e99ba8a332d92efd38 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 15:44:24 +0900 Subject: [PATCH 01/18] =?UTF-8?q?feat:=20cicd=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-dev.yml | 26 ++++++++++++++++++++++++++ .github/workflows/ci-dev.yml | 36 ++++++++++++++++++++++++++++++++++++ backend/Dockerfile | 9 +++++++++ backend/docker-compose.yml | 11 +++++++++++ 4 files changed, 82 insertions(+) create mode 100644 .github/workflows/cd-dev.yml create mode 100644 .github/workflows/ci-dev.yml create mode 100644 backend/Dockerfile create mode 100644 backend/docker-compose.yml diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml new file mode 100644 index 000000000..602663d9f --- /dev/null +++ b/.github/workflows/cd-dev.yml @@ -0,0 +1,26 @@ +name: cd-dev + +on: + push: + branches: + - develop-backend + +jobs: + deploy: + runs-on: self-hosted + steps: + - name: change permission + run: | + sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-mouda + + - name: DockerHub login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Docker Compose up + run: | + docker compose -f docker-compose.yml down cd + docker compose -f docker-compose.yml pull cd + docker compose -f docker-compose.yml up -d cd diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml new file mode 100644 index 000000000..ce95d8342 --- /dev/null +++ b/.github/workflows/ci-dev.yml @@ -0,0 +1,36 @@ +name: cd-dev + +on: + pull_request: + branches: + - develop-backend + +jobs: + build: + runs-on: ubuntu-24.04 + steps: + - name: 레포지토리 체크아웃 + uses: actions/checkout@v4 + + - name: JDK 17을 설치 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'corretto' + + - name: gradlew 권한 부여 + run: chmod +x ./gradlew + + - name: Gradle 빌드 + run: ./gradlew clean build -x test + + - name: DockerHub 로그인 + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: 도커 이미지 빌드 및 푸시 + run: | + docker build -t 2024mouda/cd:latest . + docker push 2024mouda/cd:latest diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 000000000..5874a9baf --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,9 @@ +FROM openjdk:17-jdk + +ARG JAR_FILE=./build/libs/backend-0.0.1-SNAPSHOT.jar + +COPY ${JAR_FILE} /app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "/app.jar"] diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml new file mode 100644 index 000000000..0dbfde141 --- /dev/null +++ b/backend/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.7" # 파일 규격 버전 +services: + mouda-be: + build: . + container_name: mouda-be # 컨테이너 이름 설정 + ports: + - "8080:8080" + command: + - run + - --cors + - "*" From 69b87d92812d76e9d28392c37f79238d545a0143 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 15:58:05 +0900 Subject: [PATCH 02/18] =?UTF-8?q?fix:=20working-directory=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-dev.yml | 6 ++++++ .github/workflows/ci-dev.yml | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml index 602663d9f..eaf9ce216 100644 --- a/.github/workflows/cd-dev.yml +++ b/.github/workflows/cd-dev.yml @@ -8,6 +8,12 @@ on: jobs: deploy: runs-on: self-hosted + + defaults: + run: + shell: bash + working-directory: ./backend + steps: - name: change permission run: | diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml index ce95d8342..355522cd7 100644 --- a/.github/workflows/ci-dev.yml +++ b/.github/workflows/ci-dev.yml @@ -8,6 +8,12 @@ on: jobs: build: runs-on: ubuntu-24.04 + + defaults: + run: + shell: bash + working-directory: ./backend + steps: - name: 레포지토리 체크아웃 uses: actions/checkout@v4 @@ -19,7 +25,7 @@ jobs: distribution: 'corretto' - name: gradlew 권한 부여 - run: chmod +x ./gradlew + run: chmod +x ./backend/gradlew - name: Gradle 빌드 run: ./gradlew clean build -x test From 9085cabbf4720d99c6a1efa07d37e114c50a43d8 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 15:58:46 +0900 Subject: [PATCH 03/18] =?UTF-8?q?fix:=20working-directory=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml index 355522cd7..ca35fc8d7 100644 --- a/.github/workflows/ci-dev.yml +++ b/.github/workflows/ci-dev.yml @@ -25,7 +25,7 @@ jobs: distribution: 'corretto' - name: gradlew 권한 부여 - run: chmod +x ./backend/gradlew + run: chmod +x ./gradlew - name: Gradle 빌드 run: ./gradlew clean build -x test From e517fc2a2bec3cd52a41b160f8e8499a9a2c92e1 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 16:07:40 +0900 Subject: [PATCH 04/18] =?UTF-8?q?fix:=20working-directory=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-dev.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml index eaf9ce216..e9d1087c2 100644 --- a/.github/workflows/cd-dev.yml +++ b/.github/workflows/cd-dev.yml @@ -9,11 +9,6 @@ jobs: deploy: runs-on: self-hosted - defaults: - run: - shell: bash - working-directory: ./backend - steps: - name: change permission run: | @@ -27,6 +22,6 @@ jobs: - name: Docker Compose up run: | - docker compose -f docker-compose.yml down cd - docker compose -f docker-compose.yml pull cd - docker compose -f docker-compose.yml up -d cd + docker compose -f ./backend/docker-compose.yml down cd + docker compose -f ./backend/docker-compose.yml pull cd + docker compose -f ./backend/docker-compose.yml up -d cd From 39b91d56f220221584d99168be231d99fd6ca230 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 16:18:09 +0900 Subject: [PATCH 05/18] =?UTF-8?q?fix:=20docker-compose=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-dev.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml index e9d1087c2..32902094a 100644 --- a/.github/workflows/cd-dev.yml +++ b/.github/workflows/cd-dev.yml @@ -22,6 +22,6 @@ jobs: - name: Docker Compose up run: | - docker compose -f ./backend/docker-compose.yml down cd - docker compose -f ./backend/docker-compose.yml pull cd - docker compose -f ./backend/docker-compose.yml up -d cd + docker compose -f ./backend/docker-compose.yml down mouda-be + docker compose -f ./backend/docker-compose.yml pull mouda-be + docker compose -f ./backend/docker-compose.yml up -d mouda-be From 8c546ba8de854a7f42bbe8d39a6f241ede67fe8a Mon Sep 17 00:00:00 2001 From: SungKyum Kim Date: Wed, 17 Jul 2024 16:50:25 +0900 Subject: [PATCH 06/18] =?UTF-8?q?fix:=20Moim=20ID=20=EB=88=84=EB=9D=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/moim/dto/response/MoimFindAllResponse.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java b/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java index d52c95b82..2442de3e4 100644 --- a/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java +++ b/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java @@ -8,6 +8,7 @@ @Builder public record MoimFindAllResponse( + long id, String title, LocalDate date, LocalTime time, @@ -18,6 +19,7 @@ public record MoimFindAllResponse( ) { public static MoimFindAllResponse toResponse(Moim moim) { return MoimFindAllResponse.builder() + .id(moim.getId()) .title(moim.getTitle()) .date(moim.getDate()) .time(moim.getTime()) From dc0b48f1a36af9f146be267d9f8090c35fc88c2a Mon Sep 17 00:00:00 2001 From: SungKyum Kim Date: Wed, 17 Jul 2024 16:54:05 +0900 Subject: [PATCH 07/18] =?UTF-8?q?refactor:=20response=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/moim/dto/response/MoimFindAllResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java b/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java index 2442de3e4..d2de6f936 100644 --- a/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java +++ b/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java @@ -8,7 +8,7 @@ @Builder public record MoimFindAllResponse( - long id, + long moimId, String title, LocalDate date, LocalTime time, @@ -19,7 +19,7 @@ public record MoimFindAllResponse( ) { public static MoimFindAllResponse toResponse(Moim moim) { return MoimFindAllResponse.builder() - .id(moim.getId()) + .moimId(moim.getId()) .title(moim.getTitle()) .date(moim.getDate()) .time(moim.getTime()) From 17769b0a1f69009af673f0c6ab864a497924ff84 Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 17 Jul 2024 16:56:09 +0900 Subject: [PATCH 08/18] =?UTF-8?q?refactor:=20=ED=98=84=EC=9E=AC=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=20=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/mouda/backend/moim/domain/Moim.java | 2 ++ .../mouda/backend/moim/dto/response/MoimFindAllResponse.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/backend/src/main/java/mouda/backend/moim/domain/Moim.java b/backend/src/main/java/mouda/backend/moim/domain/Moim.java index 3f2fa508c..9739cef5e 100644 --- a/backend/src/main/java/mouda/backend/moim/domain/Moim.java +++ b/backend/src/main/java/mouda/backend/moim/domain/Moim.java @@ -30,6 +30,8 @@ public class Moim { private String place; + private int currentPeople; + private int maxPeople; private String authorNickname; diff --git a/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java b/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java index d52c95b82..03ff2a447 100644 --- a/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java +++ b/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java @@ -12,6 +12,7 @@ public record MoimFindAllResponse( LocalDate date, LocalTime time, String place, + int currentPeople, int maxPeople, String authorNickname, String description @@ -22,6 +23,7 @@ public static MoimFindAllResponse toResponse(Moim moim) { .date(moim.getDate()) .time(moim.getTime()) .place(moim.getPlace()) + .currentPeople(moim.getCurrentPeople()) .maxPeople(moim.getMaxPeople()) .authorNickname(moim.getAuthorNickname()) .description(moim.getDescription()) From e6f69be106b195def6c08318d740ce7058a21fdc Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 17 Jul 2024 16:56:34 +0900 Subject: [PATCH 09/18] =?UTF-8?q?feat:=20=EB=AA=A8=EC=9E=84=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/MoimDetailsFindResponse.java | 32 ++++ .../backend/moim/service/MoimService.java | 13 +- .../backend/moim/service/MoimServiceTest.java | 137 ++++++++++-------- 3 files changed, 120 insertions(+), 62 deletions(-) create mode 100644 backend/src/main/java/mouda/backend/moim/dto/response/MoimDetailsFindResponse.java diff --git a/backend/src/main/java/mouda/backend/moim/dto/response/MoimDetailsFindResponse.java b/backend/src/main/java/mouda/backend/moim/dto/response/MoimDetailsFindResponse.java new file mode 100644 index 000000000..e62ba6132 --- /dev/null +++ b/backend/src/main/java/mouda/backend/moim/dto/response/MoimDetailsFindResponse.java @@ -0,0 +1,32 @@ +package mouda.backend.moim.dto.response; + +import java.time.LocalDate; +import java.time.LocalTime; + +import lombok.Builder; +import mouda.backend.moim.domain.Moim; + +@Builder +public record MoimDetailsFindResponse( + String title, + LocalDate date, + LocalTime time, + String place, + int currentPeople, + int maxPeople, + String authorNickname, + String description +) { + public static MoimDetailsFindResponse toResponse(Moim moim) { + return MoimDetailsFindResponse.builder() + .title(moim.getTitle()) + .date(moim.getDate()) + .time(moim.getTime()) + .place(moim.getPlace()) + .currentPeople(moim.getCurrentPeople()) + .maxPeople(moim.getMaxPeople()) + .authorNickname(moim.getAuthorNickname()) + .description(moim.getDescription()) + .build(); + } +} diff --git a/backend/src/main/java/mouda/backend/moim/service/MoimService.java b/backend/src/main/java/mouda/backend/moim/service/MoimService.java index ccf2cf6ad..e8e117873 100644 --- a/backend/src/main/java/mouda/backend/moim/service/MoimService.java +++ b/backend/src/main/java/mouda/backend/moim/service/MoimService.java @@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor; import mouda.backend.moim.domain.Moim; import mouda.backend.moim.dto.request.MoimCreateRequest; +import mouda.backend.moim.dto.response.MoimDetailsFindResponse; import mouda.backend.moim.dto.response.MoimFindAllResponse; import mouda.backend.moim.dto.response.MoimFindAllResponses; import mouda.backend.moim.repository.MoimRepository; @@ -33,10 +34,18 @@ public MoimFindAllResponses findAllMoim() { ); } - public void deleteMoim(long id) { + @Transactional(readOnly = true) + public MoimDetailsFindResponse findMoimDetails(long id) { + Moim moim = moimRepository.findById(id) + .orElseThrow(IllegalArgumentException::new); + + return MoimDetailsFindResponse.toResponse(moim); + } + + public void deleteMoim(long id) { Moim moim = moimRepository.findById(id) .orElseThrow(IllegalArgumentException::new); moimRepository.delete(moim); - } + } } diff --git a/backend/src/test/java/mouda/backend/moim/service/MoimServiceTest.java b/backend/src/test/java/mouda/backend/moim/service/MoimServiceTest.java index 8eb24c3fa..0829de931 100644 --- a/backend/src/test/java/mouda/backend/moim/service/MoimServiceTest.java +++ b/backend/src/test/java/mouda/backend/moim/service/MoimServiceTest.java @@ -5,73 +5,90 @@ import java.time.LocalDate; import java.time.LocalTime; import java.util.List; -import mouda.backend.config.DatabaseCleaner; -import mouda.backend.moim.domain.Moim; -import mouda.backend.moim.dto.request.MoimCreateRequest; -import mouda.backend.moim.dto.response.MoimFindAllResponses; -import mouda.backend.moim.repository.MoimRepository; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import mouda.backend.config.DatabaseCleaner; +import mouda.backend.moim.domain.Moim; +import mouda.backend.moim.dto.request.MoimCreateRequest; +import mouda.backend.moim.dto.response.MoimDetailsFindResponse; +import mouda.backend.moim.dto.response.MoimFindAllResponses; +import mouda.backend.moim.repository.MoimRepository; + @SpringBootTest class MoimServiceTest { - @Autowired - private MoimService moimService; - - @Autowired - private MoimRepository moimRepository; - - @Autowired - private DatabaseCleaner databaseCleaner; - - @AfterEach - void cleanUp() { - databaseCleaner.cleanUp(); - } - - @DisplayName("모임을 생성한다.") - @Test - void createMoim() { - MoimCreateRequest moimCreateRequest = new MoimCreateRequest( - "title", LocalDate.now(), LocalTime.now(), "place", - 10, "안나", "설명" - ); - Moim moim = moimService.createMoim(moimCreateRequest); - assertThat(moim.getId()).isEqualTo(1L); - } - - @DisplayName("모임을 전체 조회한다.") - @Test - void findAllMoim() { - MoimCreateRequest moimCreateRequest = new MoimCreateRequest( - "title", LocalDate.now(), LocalTime.now(), "place", - 10, "안나", "설명" - ); - moimService.createMoim(moimCreateRequest); - moimService.createMoim(moimCreateRequest); - - MoimFindAllResponses moimResponses = moimService.findAllMoim(); - - assertThat(moimResponses).isNotNull(); - assertThat(moimResponses.moims()).hasSize(2); - } - - @DisplayName("모임을 삭제한다.") - @Test - void deleteMoim() { - MoimCreateRequest moimCreateRequest = new MoimCreateRequest( - "title", LocalDate.now(), LocalTime.now(), "place", - 10, "안나", "설명" - ); - moimService.createMoim(moimCreateRequest); - - moimService.deleteMoim(1L); - List moims = moimRepository.findAll(); - - assertThat(moims).hasSize(0); - } + @Autowired + private MoimService moimService; + + @Autowired + private MoimRepository moimRepository; + + @Autowired + private DatabaseCleaner databaseCleaner; + + @AfterEach + void cleanUp() { + databaseCleaner.cleanUp(); + } + + @DisplayName("모임을 생성한다.") + @Test + void createMoim() { + MoimCreateRequest moimCreateRequest = new MoimCreateRequest( + "title", LocalDate.now(), LocalTime.now(), "place", + 10, "안나", "설명" + ); + Moim moim = moimService.createMoim(moimCreateRequest); + assertThat(moim.getId()).isEqualTo(1L); + } + + @DisplayName("모임을 전체 조회한다.") + @Test + void findAllMoim() { + MoimCreateRequest moimCreateRequest = new MoimCreateRequest( + "title", LocalDate.now(), LocalTime.now(), "place", + 10, "안나", "설명" + ); + moimService.createMoim(moimCreateRequest); + moimService.createMoim(moimCreateRequest); + + MoimFindAllResponses moimResponses = moimService.findAllMoim(); + + assertThat(moimResponses).isNotNull(); + assertThat(moimResponses.moims()).hasSize(2); + } + + @DisplayName("모임 상세를 조회한다.") + @Test + void findMoimDetails() { + MoimCreateRequest moimCreateRequest = new MoimCreateRequest( + "title", LocalDate.now(), LocalTime.now(), "place", + 10, "안나", "설명" + ); + moimService.createMoim(moimCreateRequest); + + MoimDetailsFindResponse moimDetails = moimService.findMoimDetails(1L); + + assertThat(moimDetails.authorNickname()).isEqualTo("안나"); + } + + @DisplayName("모임을 삭제한다.") + @Test + void deleteMoim() { + MoimCreateRequest moimCreateRequest = new MoimCreateRequest( + "title", LocalDate.now(), LocalTime.now(), "place", + 10, "안나", "설명" + ); + moimService.createMoim(moimCreateRequest); + + moimService.deleteMoim(1L); + List moims = moimRepository.findAll(); + + assertThat(moims).hasSize(0); + } } From edec1a4a6772255d0f7dd6334136829a1b9909ed Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 17 Jul 2024 16:56:43 +0900 Subject: [PATCH 10/18] =?UTF-8?q?feat:=20=EB=AA=A8=EC=9E=84=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/moim/controller/MoimController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/src/main/java/mouda/backend/moim/controller/MoimController.java b/backend/src/main/java/mouda/backend/moim/controller/MoimController.java index 392a563ff..b06c7f9a0 100644 --- a/backend/src/main/java/mouda/backend/moim/controller/MoimController.java +++ b/backend/src/main/java/mouda/backend/moim/controller/MoimController.java @@ -16,6 +16,7 @@ import mouda.backend.common.RestResponse; import mouda.backend.moim.domain.Moim; import mouda.backend.moim.dto.request.MoimCreateRequest; +import mouda.backend.moim.dto.response.MoimDetailsFindResponse; import mouda.backend.moim.dto.response.MoimFindAllResponses; import mouda.backend.moim.service.MoimService; @@ -45,6 +46,15 @@ public ResponseEntity> findAllMoim() { return ResponseEntity.ok().body(new RestResponse<>(moimService.findAllMoim())); } + @Operation(summary = "모임 상세 조회", description = "모임 상세 조회한다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "모임 상세 조회 성공!"), + }) + @GetMapping("/{id}") + public ResponseEntity> findMoimDetails(@PathVariable long id) { + return ResponseEntity.ok().body(new RestResponse<>(moimService.findMoimDetails(id))); + } + @Operation(summary = "모임 삭제", description = "해당하는 id의 모임을 삭제한다.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "모임 삭제 성공!"), From 515b5392fbaa93792e2512c85beb65bc3158d608 Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 17 Jul 2024 17:05:07 +0900 Subject: [PATCH 11/18] =?UTF-8?q?refactor:=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/moim/controller/MoimController.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/mouda/backend/moim/controller/MoimController.java b/backend/src/main/java/mouda/backend/moim/controller/MoimController.java index b06c7f9a0..50037509b 100644 --- a/backend/src/main/java/mouda/backend/moim/controller/MoimController.java +++ b/backend/src/main/java/mouda/backend/moim/controller/MoimController.java @@ -50,17 +50,17 @@ public ResponseEntity> findAllMoim() { @ApiResponses({ @ApiResponse(responseCode = "200", description = "모임 상세 조회 성공!"), }) - @GetMapping("/{id}") - public ResponseEntity> findMoimDetails(@PathVariable long id) { - return ResponseEntity.ok().body(new RestResponse<>(moimService.findMoimDetails(id))); + @GetMapping("/{moimId}") + public ResponseEntity> findMoimDetails(@PathVariable long moimId) { + return ResponseEntity.ok().body(new RestResponse<>(moimService.findMoimDetails(moimId))); } @Operation(summary = "모임 삭제", description = "해당하는 id의 모임을 삭제한다.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "모임 삭제 성공!"), }) - @DeleteMapping("/{id}") - public void deleteMoim(@PathVariable long id) { - moimService.deleteMoim(id); + @DeleteMapping("/{moimId}") + public void deleteMoim(@PathVariable long moimId) { + moimService.deleteMoim(moimId); } } From 56b25b7d5fc2c02a1a97bd9f848567026d9f2361 Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Wed, 17 Jul 2024 17:10:00 +0900 Subject: [PATCH 12/18] =?UTF-8?q?feat:=20=EB=AA=A8=EC=9E=84=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/moim/controller/MoimController.java | 11 +++++++++++ .../src/main/java/mouda/backend/moim/domain/Moim.java | 7 +++++++ .../backend/moim/dto/request/MoimJoinRequest.java | 6 ++++++ .../java/mouda/backend/moim/service/MoimService.java | 11 +++++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/mouda/backend/moim/dto/request/MoimJoinRequest.java diff --git a/backend/src/main/java/mouda/backend/moim/controller/MoimController.java b/backend/src/main/java/mouda/backend/moim/controller/MoimController.java index 392a563ff..46674ca82 100644 --- a/backend/src/main/java/mouda/backend/moim/controller/MoimController.java +++ b/backend/src/main/java/mouda/backend/moim/controller/MoimController.java @@ -16,6 +16,7 @@ import mouda.backend.common.RestResponse; import mouda.backend.moim.domain.Moim; import mouda.backend.moim.dto.request.MoimCreateRequest; +import mouda.backend.moim.dto.request.MoimJoinRequest; import mouda.backend.moim.dto.response.MoimFindAllResponses; import mouda.backend.moim.service.MoimService; @@ -45,6 +46,16 @@ public ResponseEntity> findAllMoim() { return ResponseEntity.ok().body(new RestResponse<>(moimService.findAllMoim())); } + @Operation(summary = "모임 참여", description = "모임에 참여한다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "모임 참여 성공") + }) + @PostMapping + public ResponseEntity joinMoim(@RequestBody MoimJoinRequest moimJoinRequest) { + moimService.joinMoim(moimJoinRequest); + return ResponseEntity.ok().build(); + } + @Operation(summary = "모임 삭제", description = "해당하는 id의 모임을 삭제한다.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "모임 삭제 성공!"), diff --git a/backend/src/main/java/mouda/backend/moim/domain/Moim.java b/backend/src/main/java/mouda/backend/moim/domain/Moim.java index 3f2fa508c..43917513e 100644 --- a/backend/src/main/java/mouda/backend/moim/domain/Moim.java +++ b/backend/src/main/java/mouda/backend/moim/domain/Moim.java @@ -35,4 +35,11 @@ public class Moim { private String authorNickname; private String description; + + public void join() { + if (currentPeople == maxPeople) { + throw new IllegalArgumentException(); + } + currentPeople++; + } } diff --git a/backend/src/main/java/mouda/backend/moim/dto/request/MoimJoinRequest.java b/backend/src/main/java/mouda/backend/moim/dto/request/MoimJoinRequest.java new file mode 100644 index 000000000..cdaa6e296 --- /dev/null +++ b/backend/src/main/java/mouda/backend/moim/dto/request/MoimJoinRequest.java @@ -0,0 +1,6 @@ +package mouda.backend.moim.dto.request; + +public record MoimJoinRequest( + Long moimId +) { +} diff --git a/backend/src/main/java/mouda/backend/moim/service/MoimService.java b/backend/src/main/java/mouda/backend/moim/service/MoimService.java index ccf2cf6ad..65222397a 100644 --- a/backend/src/main/java/mouda/backend/moim/service/MoimService.java +++ b/backend/src/main/java/mouda/backend/moim/service/MoimService.java @@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor; import mouda.backend.moim.domain.Moim; import mouda.backend.moim.dto.request.MoimCreateRequest; +import mouda.backend.moim.dto.request.MoimJoinRequest; import mouda.backend.moim.dto.response.MoimFindAllResponse; import mouda.backend.moim.dto.response.MoimFindAllResponses; import mouda.backend.moim.repository.MoimRepository; @@ -33,10 +34,16 @@ public MoimFindAllResponses findAllMoim() { ); } - public void deleteMoim(long id) { + public void joinMoim(MoimJoinRequest moimJoinRequest) { + Moim moim = moimRepository.findById(moimJoinRequest.moimId()) + .orElseThrow(() -> new IllegalArgumentException("모임이 존재하지 않습니다.")); + moim.join(); + } + + public void deleteMoim(long id) { Moim moim = moimRepository.findById(id) .orElseThrow(IllegalArgumentException::new); moimRepository.delete(moim); - } + } } From 9ed8e7da97a83db6aa3f0f2c3f52f2466ad0cd0a Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Wed, 17 Jul 2024 17:21:34 +0900 Subject: [PATCH 13/18] =?UTF-8?q?feat:=20=EB=AA=A8=EC=9E=84=EC=97=90=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/moim/controller/MoimController.java | 11 +++++++++++ .../mouda/backend/moim/service/MoimService.java | 9 +++++++++ .../backend/moim/service/MoimServiceTest.java | 17 +++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/backend/src/main/java/mouda/backend/moim/controller/MoimController.java b/backend/src/main/java/mouda/backend/moim/controller/MoimController.java index 50037509b..6ff48247f 100644 --- a/backend/src/main/java/mouda/backend/moim/controller/MoimController.java +++ b/backend/src/main/java/mouda/backend/moim/controller/MoimController.java @@ -16,6 +16,7 @@ import mouda.backend.common.RestResponse; import mouda.backend.moim.domain.Moim; import mouda.backend.moim.dto.request.MoimCreateRequest; +import mouda.backend.moim.dto.request.MoimJoinRequest; import mouda.backend.moim.dto.response.MoimDetailsFindResponse; import mouda.backend.moim.dto.response.MoimFindAllResponses; import mouda.backend.moim.service.MoimService; @@ -55,6 +56,16 @@ public ResponseEntity> findMoimDetails(@Pa return ResponseEntity.ok().body(new RestResponse<>(moimService.findMoimDetails(moimId))); } + @Operation(summary = "모임 참여", description = "모임에 참여한다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "모임 참여 성공!") + }) + @PostMapping("/join") + public ResponseEntity> joinMoim(@RequestBody MoimJoinRequest moimJoinRequest) { + moimService.joinMoim(moimJoinRequest); + return ResponseEntity.ok().build(); + } + @Operation(summary = "모임 삭제", description = "해당하는 id의 모임을 삭제한다.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "모임 삭제 성공!"), diff --git a/backend/src/main/java/mouda/backend/moim/service/MoimService.java b/backend/src/main/java/mouda/backend/moim/service/MoimService.java index 65222397a..9f54fdc8b 100644 --- a/backend/src/main/java/mouda/backend/moim/service/MoimService.java +++ b/backend/src/main/java/mouda/backend/moim/service/MoimService.java @@ -9,6 +9,7 @@ import mouda.backend.moim.domain.Moim; import mouda.backend.moim.dto.request.MoimCreateRequest; import mouda.backend.moim.dto.request.MoimJoinRequest; +import mouda.backend.moim.dto.response.MoimDetailsFindResponse; import mouda.backend.moim.dto.response.MoimFindAllResponse; import mouda.backend.moim.dto.response.MoimFindAllResponses; import mouda.backend.moim.repository.MoimRepository; @@ -34,6 +35,14 @@ public MoimFindAllResponses findAllMoim() { ); } + @Transactional(readOnly = true) + public MoimDetailsFindResponse findMoimDetails(long id) { + Moim moim = moimRepository.findById(id) + .orElseThrow(IllegalArgumentException::new); + + return MoimDetailsFindResponse.toResponse(moim); + } + public void joinMoim(MoimJoinRequest moimJoinRequest) { Moim moim = moimRepository.findById(moimJoinRequest.moimId()) .orElseThrow(() -> new IllegalArgumentException("모임이 존재하지 않습니다.")); diff --git a/backend/src/test/java/mouda/backend/moim/service/MoimServiceTest.java b/backend/src/test/java/mouda/backend/moim/service/MoimServiceTest.java index 0829de931..66ca9ca59 100644 --- a/backend/src/test/java/mouda/backend/moim/service/MoimServiceTest.java +++ b/backend/src/test/java/mouda/backend/moim/service/MoimServiceTest.java @@ -15,6 +15,7 @@ import mouda.backend.config.DatabaseCleaner; import mouda.backend.moim.domain.Moim; import mouda.backend.moim.dto.request.MoimCreateRequest; +import mouda.backend.moim.dto.request.MoimJoinRequest; import mouda.backend.moim.dto.response.MoimDetailsFindResponse; import mouda.backend.moim.dto.response.MoimFindAllResponses; import mouda.backend.moim.repository.MoimRepository; @@ -77,6 +78,22 @@ void findMoimDetails() { assertThat(moimDetails.authorNickname()).isEqualTo("안나"); } + @DisplayName("모임에 참여한다.") + @Test + void joinMoim() { + MoimCreateRequest moimCreateRequest = new MoimCreateRequest( + "title", LocalDate.now(), LocalTime.now(), "place", + 10, "안나", "설명" + ); + moimService.createMoim(moimCreateRequest); + + MoimJoinRequest moimJoinRequest = new MoimJoinRequest(1L); + moimService.joinMoim(moimJoinRequest); + + MoimDetailsFindResponse moimDetails = moimService.findMoimDetails(1L); + assertThat(moimDetails.currentPeople()).isEqualTo(1); + } + @DisplayName("모임을 삭제한다.") @Test void deleteMoim() { From 46df8754f4075de10e789198d21b5b000bf9016b Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 17:31:09 +0900 Subject: [PATCH 14/18] =?UTF-8?q?fix:=20docker=20build=20platform=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml index ca35fc8d7..5bf3d4f8b 100644 --- a/.github/workflows/ci-dev.yml +++ b/.github/workflows/ci-dev.yml @@ -38,5 +38,5 @@ jobs: - name: 도커 이미지 빌드 및 푸시 run: | - docker build -t 2024mouda/cd:latest . - docker push 2024mouda/cd:latest + docker buildx build --platform=linux/amd64,linux/arm64 -t 2024mouda/mouda-be:latest . --push + docker push 2024mouda/mouda-be:latest From 63af698e1b99cf2dc8a0edb093e61cb4a86835e6 Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Wed, 17 Jul 2024 17:43:29 +0900 Subject: [PATCH 15/18] =?UTF-8?q?fix:=20=EB=AA=A8=EC=9E=84=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=20=EC=8B=9C=20=EC=B5=9C=EB=8C=80=20=EC=9D=B8=EC=9B=90?= =?UTF-8?q?=20=EC=88=98=EB=B3=B4=EB=8B=A4=20=EB=A7=8E=EC=95=84=EC=A7=80?= =?UTF-8?q?=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/mouda/backend/moim/domain/Moim.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/mouda/backend/moim/domain/Moim.java b/backend/src/main/java/mouda/backend/moim/domain/Moim.java index 23eedbbaf..e1ec28e0f 100644 --- a/backend/src/main/java/mouda/backend/moim/domain/Moim.java +++ b/backend/src/main/java/mouda/backend/moim/domain/Moim.java @@ -39,7 +39,7 @@ public class Moim { private String description; public void join() { - if (currentPeople == maxPeople) { + if (currentPeople + 1 > maxPeople) { throw new IllegalArgumentException(); } currentPeople++; From 5cd9f10fd3d085ff7e6ebe233585e417c28a9f31 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 17:48:39 +0900 Subject: [PATCH 16/18] =?UTF-8?q?fix:=20docker=20build=20platform=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml index 5bf3d4f8b..202af2f79 100644 --- a/.github/workflows/ci-dev.yml +++ b/.github/workflows/ci-dev.yml @@ -38,5 +38,5 @@ jobs: - name: 도커 이미지 빌드 및 푸시 run: | - docker buildx build --platform=linux/amd64,linux/arm64 -t 2024mouda/mouda-be:latest . --push + docker buildx build . --platform=linux/amd64,linux/arm64 -t 2024mouda/mouda-be:latest docker push 2024mouda/mouda-be:latest From f4e6fc6cffceab8cbd5118eb7ba2da76fa8ce9bc Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 18:37:55 +0900 Subject: [PATCH 17/18] =?UTF-8?q?fix:=20docker=20build=20platform=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml index 202af2f79..1a826bcd0 100644 --- a/.github/workflows/ci-dev.yml +++ b/.github/workflows/ci-dev.yml @@ -1,4 +1,4 @@ -name: cd-dev +name: ci-dev on: pull_request: @@ -38,5 +38,5 @@ jobs: - name: 도커 이미지 빌드 및 푸시 run: | - docker buildx build . --platform=linux/amd64,linux/arm64 -t 2024mouda/mouda-be:latest + docker buildx build ./backend/ --platform=linux/arm64 -t 2024mouda/mouda-be:latest docker push 2024mouda/mouda-be:latest From afecfcc82a283723c5a67289563adbfe2f78030c Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 17 Jul 2024 18:39:41 +0900 Subject: [PATCH 18/18] =?UTF-8?q?fix:=20build=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-dev.yml b/.github/workflows/ci-dev.yml index 1a826bcd0..345d7f2f4 100644 --- a/.github/workflows/ci-dev.yml +++ b/.github/workflows/ci-dev.yml @@ -38,5 +38,5 @@ jobs: - name: 도커 이미지 빌드 및 푸시 run: | - docker buildx build ./backend/ --platform=linux/arm64 -t 2024mouda/mouda-be:latest + docker buildx build ./ --platform=linux/arm64 -t 2024mouda/mouda-be:latest docker push 2024mouda/mouda-be:latest