Skip to content

Commit

Permalink
[SAMBAD-275] 모임 코드 조회 API 추가 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkjsw17 authored and nahyeon99 committed Aug 24, 2024
1 parent 3dbd020 commit 931d115
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public MeetingNameResponse getMeetingNameByCode(String code) {
return MeetingNameResponse.from(meeting);
}

public Meeting getMeeting(Long meetingId) {
return meetingRepository.findById(meetingId)
.orElseThrow(MeetingNotFoundException::new);
}

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 @@ -9,20 +9,23 @@
import org.depromeet.sambad.moring.meeting.meeting.domain.Meeting;
import org.depromeet.sambad.moring.meeting.meeting.domain.MeetingType;
import org.depromeet.sambad.moring.meeting.meeting.presentation.request.MeetingPersistRequest;
import org.depromeet.sambad.moring.meeting.meeting.presentation.response.MeetingCodeResponse;
import org.depromeet.sambad.moring.meeting.meeting.presentation.response.MeetingNameResponse;
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.PathVariable;
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;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -41,6 +44,7 @@ public class MeetingController {
@Operation(summary = "모임 조회", description = "가입되어 있는 모임 목록을 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 조회 성공"),
@ApiResponse(responseCode = "404", description = "NOT_JOINED_ANY_MEETING"),
})
@GetMapping
public ResponseEntity<MeetingResponse> getMeetings(@UserId Long userId) {
Expand All @@ -61,6 +65,21 @@ public ResponseEntity<MeetingNameResponse> getMeetingName(@RequestParam String c
return ResponseEntity.ok(response);
}

@Operation(summary = "모임의 초대 코드 조회", description = "특정 모임의 초대 코드를 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "초대 코드 조회 성공"),
@ApiResponse(responseCode = "404", description = "MEETING_NOT_FOUND"),
})
@GetMapping("/{meetingId}/code")
public ResponseEntity<MeetingCodeResponse> getMeetingCode(
@Parameter(description = "모임 ID", example = "1", required = true) @PathVariable Long meetingId
) {
Meeting meeting = meetingService.getMeeting(meetingId);
MeetingCodeResponse response = MeetingCodeResponse.from(meeting);

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 MeetingCodeResponse(
@Schema(description = "초대 코드", example = "ABCDEF", requiredMode = REQUIRED)
String code
) {
public static MeetingCodeResponse from(Meeting meeting) {
return new MeetingCodeResponse(meeting.getCode());
}
}

0 comments on commit 931d115

Please sign in to comment.