Skip to content

Commit

Permalink
[SAMBAD-204] 초대 코드 기반 모임명 조회 API 추가 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkjsw17 authored Aug 2, 2024
1 parent a4d6ff6 commit fa1a10c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
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());
}
}

0 comments on commit fa1a10c

Please sign in to comment.