Skip to content

Commit

Permalink
Merge pull request #70 from woowacourse-teams/develop-backend
Browse files Browse the repository at this point in the history
develop-backend 브랜치를 develop으로 머지
  • Loading branch information
hoyeonyy authored Jul 18, 2024
2 parents 484203e + 8b122ab commit 8b78d9f
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 65 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 ./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
42 changes: 42 additions & 0 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: ci-dev

on:
pull_request:
branches:
- develop-backend

jobs:
build:
runs-on: ubuntu-24.04

defaults:
run:
shell: bash
working-directory: ./backend

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 buildx build ./ --platform=linux/arm64 -t 2024mouda/mouda-be:latest
docker push 2024mouda/mouda-be:latest
9 changes: 9 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 11 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.7" # 파일 규격 버전
services:
mouda-be:
build: .
container_name: mouda-be # 컨테이너 이름 설정
ports:
- "8080:8080"
command:
- run
- --cors
- "*"
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
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;

Expand Down Expand Up @@ -45,12 +47,31 @@ public ResponseEntity<RestResponse<MoimFindAllResponses>> findAllMoim() {
return ResponseEntity.ok().body(new RestResponse<>(moimService.findAllMoim()));
}

@Operation(summary = "모임 상세 조회", description = "모임 상세 조회한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 상세 조회 성공!"),
})
@GetMapping("/{moimId}")
public ResponseEntity<RestResponse<MoimDetailsFindResponse>> findMoimDetails(@PathVariable long moimId) {
return ResponseEntity.ok().body(new RestResponse<>(moimService.findMoimDetails(moimId)));
}

@Operation(summary = "모임 참여", description = "모임에 참여한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 참여 성공!")
})
@PostMapping("/join")
public ResponseEntity<RestResponse<Void>> joinMoim(@RequestBody MoimJoinRequest moimJoinRequest) {
moimService.joinMoim(moimJoinRequest);
return ResponseEntity.ok().build();
}

@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);
}
}
9 changes: 9 additions & 0 deletions backend/src/main/java/mouda/backend/moim/domain/Moim.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ public class Moim {

private String place;

private int currentPeople;

private int maxPeople;

private String authorNickname;

private String description;

public void join() {
if (currentPeople + 1 > maxPeople) {
throw new IllegalArgumentException();
}
currentPeople++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mouda.backend.moim.dto.request;

public record MoimJoinRequest(
Long moimId
) {
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@

@Builder
public record MoimFindAllResponse(
long moimId,
String title,
LocalDate date,
LocalTime time,
String place,
int currentPeople,
int maxPeople,
String authorNickname,
String description
) {
public static MoimFindAllResponse toResponse(Moim moim) {
return MoimFindAllResponse.builder()
.moimId(moim.getId())
.title(moim.getTitle())
.date(moim.getDate())
.time(moim.getTime())
.place(moim.getPlace())
.currentPeople(moim.getCurrentPeople())
.maxPeople(moim.getMaxPeople())
.authorNickname(moim.getAuthorNickname())
.description(moim.getDescription())
Expand Down
20 changes: 18 additions & 2 deletions backend/src/main/java/mouda/backend/moim/service/MoimService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
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.MoimDetailsFindResponse;
import mouda.backend.moim.dto.response.MoimFindAllResponse;
import mouda.backend.moim.dto.response.MoimFindAllResponses;
import mouda.backend.moim.repository.MoimRepository;
Expand All @@ -33,10 +35,24 @@ 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 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);
}
}
}
Loading

0 comments on commit 8b78d9f

Please sign in to comment.