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..50037509b 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,12 +46,21 @@ public ResponseEntity> findAllMoim() { return ResponseEntity.ok().body(new RestResponse<>(moimService.findAllMoim())); } + @Operation(summary = "모임 상세 조회", description = "모임 상세 조회한다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "모임 상세 조회 성공!"), + }) + @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); } } 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/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/dto/response/MoimFindAllResponse.java b/backend/src/main/java/mouda/backend/moim/dto/response/MoimFindAllResponse.java index d2de6f936..04978b651 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 @@ -13,6 +13,7 @@ public record MoimFindAllResponse( LocalDate date, LocalTime time, String place, + int currentPeople, int maxPeople, String authorNickname, String description @@ -24,6 +25,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()) 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); + } }