Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

모임 참여 기능 구현 #61

Merged
merged 4 commits into from
Jul 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,16 @@ public ResponseEntity<RestResponse<MoimDetailsFindResponse>> findMoimDetails(@Pa
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 = "모임 삭제 성공!"),
Expand Down
7 changes: 7 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 @@ -37,4 +37,11 @@ public class Moim {
private String authorNickname;

private String description;

public void join() {
if (currentPeople + 1 > maxPeople) {
throw new IllegalArgumentException();
}
currentPeople++;
Comment on lines +41 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
}
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
Expand Up @@ -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.MoimDetailsFindResponse;
import mouda.backend.moim.dto.response.MoimFindAllResponse;
import mouda.backend.moim.dto.response.MoimFindAllResponses;
Expand Down Expand Up @@ -42,6 +43,12 @@ public MoimDetailsFindResponse findMoimDetails(long id) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Loading