Skip to content

Commit

Permalink
[MERGE/#84] 구글 미트 회의실 링크 조회 API 구현
Browse files Browse the repository at this point in the history
[FEAT] #84 - 구글 미트 회의실 링크 조회 API 구현
  • Loading branch information
ckkim817 authored Jul 15, 2024
2 parents ade9605 + e18d9df commit 155e828
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
import org.sopt.seonyakServer.domain.appointment.dto.AppointmentAcceptRequest;
import org.sopt.seonyakServer.domain.appointment.dto.AppointmentRejectRequest;
import org.sopt.seonyakServer.domain.appointment.dto.AppointmentRequest;
import org.sopt.seonyakServer.domain.appointment.dto.GoogleMeetLinkResponse;
import org.sopt.seonyakServer.domain.appointment.service.AppointmentService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/appoinment")
@RequestMapping("/api/v1")
public class AppointmentController {

private final AppointmentService appointmentService;

@PostMapping("")
@PostMapping("/appointment")
public ResponseEntity<Void> postAppointment(
@RequestBody final AppointmentRequest appointmentRequest
) {
Expand All @@ -43,4 +46,11 @@ public ResponseEntity<Void> rejectAppointment(
appointmentService.rejectAppointment(appointmentRejectRequest);
return ResponseEntity.ok().build();
}

@GetMapping("/google-meet/{appointmentId}")
public ResponseEntity<GoogleMeetLinkResponse> getGoogleMeetLink(
@PathVariable final Long appointmentId
) {
return ResponseEntity.ok(appointmentService.getGoogleMeetLink(appointmentId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.seonyakServer.domain.appointment.dto;

public record GoogleMeetLinkResponse(
String googleMeetLink
) {
public static GoogleMeetLinkResponse of(final String googleMeetLink) {
return new GoogleMeetLinkResponse(googleMeetLink);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.sopt.seonyakServer.domain.appointment.dto.AppointmentAcceptRequest;
import org.sopt.seonyakServer.domain.appointment.dto.AppointmentRejectRequest;
import org.sopt.seonyakServer.domain.appointment.dto.AppointmentRequest;
import org.sopt.seonyakServer.domain.appointment.dto.GoogleMeetLinkResponse;
import org.sopt.seonyakServer.domain.appointment.model.Appointment;
import org.sopt.seonyakServer.domain.appointment.model.AppointmentStatus;
import org.sopt.seonyakServer.domain.appointment.repository.AppointmentRepository;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void postAppointment(AppointmentRequest appointmentRequest) {
if (member.getId().equals(senior.getId())) {
throw new CustomException(ErrorType.SAME_MEMBER_APPOINTMENT_ERROR);
}
Appointment appointment = Appointment.createAppointment(
Appointment appointment = Appointment.create(
member,
senior,
AppointmentStatus.PENDING,
Expand All @@ -48,10 +49,11 @@ public void postAppointment(AppointmentRequest appointmentRequest) {
@Transactional
public void acceptAppointment(AppointmentAcceptRequest appointmentAcceptRequest) {
Appointment appointment = appointmentRepository.findAppointmentByIdOrThrow(
appointmentAcceptRequest.appointmentId());
appointmentAcceptRequest.appointmentId()
);
Member member = memberRepository.findMemberByIdOrThrow(principalHandler.getUserIdFromPrincipal());

// 약속의 선배ID와 토크ID가 일치하지 않는 경우
// 약속의 선배 Id와 토큰 Id가 일치하지 않는 경우
if (!Objects.equals(member.getId(), appointment.getSenior().getId())) {
throw new CustomException(ErrorType.NOT_AUTHORIZATION_ACCEPT);
}
Expand All @@ -67,10 +69,11 @@ public void acceptAppointment(AppointmentAcceptRequest appointmentAcceptRequest)
@Transactional
public void rejectAppointment(AppointmentRejectRequest appointmentRejectRequest) {
Appointment appointment = appointmentRepository.findAppointmentByIdOrThrow(
appointmentRejectRequest.appointmentId());
appointmentRejectRequest.appointmentId()
);
Member member = memberRepository.findMemberByIdOrThrow(principalHandler.getUserIdFromPrincipal());

// 약속의 선배ID와 토크ID가 일치하지 않는 경우
// 약속의 선배 Id와 토큰 Id가 일치하지 않는 경우
if (!Objects.equals(member.getId(), appointment.getSenior().getId())) {
throw new CustomException(ErrorType.NOT_AUTHORIZATION_REJECT);
}
Expand All @@ -82,4 +85,25 @@ public void rejectAppointment(AppointmentRejectRequest appointmentRejectRequest)
);
appointmentRepository.save(appointment);
}
}

@Transactional(readOnly = true)
public GoogleMeetLinkResponse getGoogleMeetLink(Long appointmentId) {
Appointment appointment = appointmentRepository.findAppointmentByIdOrThrow(appointmentId);

Long userId = memberRepository.findMemberByIdOrThrow(principalHandler.getUserIdFromPrincipal()).getId();
Long memberId = appointment.getMember().getId();
Long seniorMemberId = appointment.getSenior().getMember().getId();

if (!userId.equals(memberId) && !userId.equals(seniorMemberId)) {
throw new CustomException(ErrorType.NOT_MEMBERS_APPOINTMENT_ERROR);
}

String googleMeetLink = appointment.getGoogleMeetLink();

if (googleMeetLink == null || googleMeetLink.isEmpty()) {
throw new CustomException(ErrorType.NOT_FOUND_GOOGLE_MEET_LINK_ERROR);
}

return GoogleMeetLinkResponse.of(googleMeetLink);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SeniorService {
@Transactional
public String createSenior(final MemberJoinRequest memberJoinRequest, Member member) {

Senior senior = Senior.createSenior(
Senior senior = Senior.create(
member,
memberJoinRequest.businessCard(),
memberJoinRequest.detailPosition(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void isPrincipalNull(
final Object principal
) {
if (principal.toString().equals(ANONYMOUS_USER)) {
throw new CustomException(ErrorType.EMPTY_PRINCIPLE_ERROR);
throw new CustomException(ErrorType.EMPTY_PRINCIPAL_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public enum ErrorType {
JSON_TO_MAP_ERROR(HttpStatus.BAD_REQUEST, "40017", "JSON 문자열을 Map으로 변환하는 중 오류가 발생했습니다."),
UNIV_CERT_REQUEST_ERROR(HttpStatus.BAD_REQUEST, "40018", "이미 인증이 완료된 이메일입니다."),
SAME_MEMBER_APPOINTMENT_ERROR(HttpStatus.BAD_REQUEST, "40019", "자기 자신에게는 약속을 신청할 수 없습니다."),
NOT_MEMBERS_APPOINTMENT_ERROR(HttpStatus.BAD_REQUEST, "40020", "해당 회원의 약속이 아닙니다"),


// S3 관련 오류
IMAGE_EXTENSION_ERROR(HttpStatus.BAD_REQUEST, "40051", "이미지 확장자는 jpg, png, webp만 가능합니다."),
IMAGE_SIZE_ERROR(HttpStatus.BAD_REQUEST, "40052", "이미지 사이즈는 5MB를 넘을 수 없습니다."),

// 인증 관련 오류
EMPTY_PRINCIPLE_ERROR(HttpStatus.BAD_REQUEST, "40076", "Principle 객체가 없습니다. (null)"),
EMPTY_PRINCIPAL_ERROR(HttpStatus.BAD_REQUEST, "40076", "Principal 객체가 없습니다. (null)"),

/**
* 401 UNAUTHORIZED
Expand All @@ -50,7 +52,7 @@ public enum ErrorType {
INVALID_JWT_SIGNATURE(HttpStatus.UNAUTHORIZED, "40105", "잘못된 JWT 서명입니다."),
UNKNOWN_JWT_ERROR(HttpStatus.UNAUTHORIZED, "40106", "알 수 없는 JWT 토큰 오류가 발생했습니다."),

INVALID_SOCIAL_ACCESS_TOKEN(HttpStatus.UNAUTHORIZED, "40107", "유효하지 않은 소셜 엑세스 토큰입니다."),
INVALID_SOCIAL_ACCESS_TOKEN(HttpStatus.UNAUTHORIZED, "40107", "유효하지 않은 소셜 액세스 토큰입니다."),
EXPIRED_AUTHENTICATION_CODE(HttpStatus.UNAUTHORIZED, "40108", "인가 코드가 만료되었습니다."),
UN_LOGIN_ERROR(HttpStatus.UNAUTHORIZED, "40109", "로그인 후 진행해주세요."),
NOT_AUTHORIZATION_ACCEPT(HttpStatus.UNAUTHORIZED, "40110", "약속을 수락할 권한이 없습니다."),
Expand All @@ -65,6 +67,7 @@ public enum ErrorType {
NOT_FOUND_SENIOR_BY_MEMBER(HttpStatus.NOT_FOUND, "40404", "해당 ID를 가진 멤버와 매핑된 선배를 찾을 수 없습니다."),
NOT_FOUND_SENIOR_ERROR(HttpStatus.NOT_FOUND, "40405", "존재하지 않는 선배입니다."),
NOT_FOUND_APPOINTMENT_ERROR(HttpStatus.NOT_FOUND, "40406", "존재하지 않는 약속입니다."),
NOT_FOUND_GOOGLE_MEET_LINK_ERROR(HttpStatus.NOT_FOUND, "40407", "구글 미트 링크가 존재하지 않는 약속입니다."),

/**
* 409 CONFLICT
Expand Down

0 comments on commit 155e828

Please sign in to comment.