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

[SAMBAD-204] 초대 코드 기반 모임명 조회 API 추가 #72

Merged
merged 2 commits into from
Aug 2, 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 @@ -3,9 +3,12 @@
import java.util.List;

import org.depromeet.sambad.moring.meeting.meeting.domain.Meeting;
import org.depromeet.sambad.moring.meeting.meeting.domain.MeetingCode;
import org.depromeet.sambad.moring.meeting.meeting.domain.TypesPerMeeting;
import org.depromeet.sambad.moring.meeting.meeting.presentation.exception.MeetingNotFoundException;
import org.depromeet.sambad.moring.meeting.meeting.presentation.request.MeetingPersistRequest;
import org.depromeet.sambad.moring.meeting.meeting.presentation.response.MeetingResponse;
import org.depromeet.sambad.moring.meeting.meeting.presentation.response.MeetingNameResponse;
import org.depromeet.sambad.moring.meeting.member.application.MeetingMemberRepository;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember;
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMemberValidator;
Expand Down Expand Up @@ -47,6 +50,13 @@ public MeetingResponse getMeetingResponse(Long userId) {
return MeetingResponse.from(meetings);
}

public MeetingNameResponse getMeetingNameByCode(String code) {
Meeting meeting = meetingRepository.findByCode(MeetingCode.from(code))
.orElseThrow(MeetingNotFoundException::new);

return MeetingNameResponse.from(meeting);
}

private void addTypesToMeeting(MeetingPersistRequest request, Meeting meeting) {
List<TypesPerMeeting> types = meetingTypeRepository.findByIdIn(request.meetingTypeIds())
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import org.depromeet.sambad.moring.meeting.meeting.presentation.request.MeetingPersistRequest;
import org.depromeet.sambad.moring.meeting.meeting.presentation.response.MeetingPersistResponse;
import org.depromeet.sambad.moring.meeting.meeting.presentation.response.MeetingResponse;
import org.depromeet.sambad.moring.meeting.meeting.presentation.response.MeetingNameResponse;
import org.depromeet.sambad.moring.meeting.meeting.presentation.response.MeetingTypeResponse;
import org.depromeet.sambad.moring.user.presentation.resolver.UserId;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -47,6 +49,18 @@ public ResponseEntity<MeetingResponse> getMeetings(@UserId Long userId) {
return ResponseEntity.ok(response);
}

@Operation(summary = "초대 코드 기반 모임명 조회", description = "초대 코드를 기반으로 모임명을 조회하며, 모임 존재 여부를 검증합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임명 조회 성공"),
@ApiResponse(responseCode = "404", description = "MEETING_NOT_FOUND"),
})
@GetMapping("/name")
public ResponseEntity<MeetingNameResponse> getMeetingName(@RequestParam String code) {
MeetingNameResponse response = meetingService.getMeetingNameByCode(code);

return ResponseEntity.ok(response);
}

@Operation(summary = "모임 생성", description = "모임을 생성합니다.")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "모임 생성 성공"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.depromeet.sambad.moring.meeting.meeting.presentation.response;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*;

import org.depromeet.sambad.moring.meeting.meeting.domain.Meeting;

import io.swagger.v3.oas.annotations.media.Schema;

public record MeetingNameResponse(
@Schema(description = "모임명", example = "삼밧드의 모험", requiredMode = REQUIRED)
String name
) {
public static MeetingNameResponse from(Meeting meeting) {
return new MeetingNameResponse(meeting.getName());
}
}
Loading