Skip to content

Commit

Permalink
[MERGE/#79] 약속 수락/거절 구현
Browse files Browse the repository at this point in the history
[FEAT] #79 - 약속 수락/거절 구현
  • Loading branch information
seokbeom00 authored Jul 15, 2024
2 parents 5951db2 + 905a932 commit a2d0c94
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@


import lombok.RequiredArgsConstructor;
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.service.AppointmentService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -24,4 +27,20 @@ public ResponseEntity<Void> postAppointment(
appointmentService.postAppointment(appointmentRequest);
return ResponseEntity.ok().build();
}

@PatchMapping("/accept")
public ResponseEntity<Void> acceptAppointment(
@RequestBody final AppointmentAcceptRequest appointmentAcceptRequest
) {
appointmentService.acceptAppointment(appointmentAcceptRequest);
return ResponseEntity.ok().build();
}

@PatchMapping("/reject")
public ResponseEntity<Void> rejectAppointment(
@RequestBody final AppointmentRejectRequest appointmentRejectRequest
) {
appointmentService.rejectAppointment(appointmentRejectRequest);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.seonyakServer.domain.appointment.dto;

import java.util.List;
import org.sopt.seonyakServer.domain.appointment.model.DataTimeRange;

public record AppointmentAcceptRequest(
Long appointmentId,
String googleMeetLink,
List<DataTimeRange> timeList
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sopt.seonyakServer.domain.appointment.dto;

public record AppointmentRejectRequest(
Long appointmentId,
String rejectReason,
String rejectDetail
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,24 @@ public static Appointment createAppointment(
.personalTopic(personalTopic)
.build();
}

public void acceptAppointment(
List<DataTimeRange> timeList,
String googleMeetLink,
AppointmentStatus appointmentStatus
) {
this.timeList = timeList;
this.googleMeetLink = googleMeetLink;
this.appointmentStatus = appointmentStatus;
}

public void rejectAppointment(
String rejectReason,
String rejectDetail,
AppointmentStatus appointmentStatus
) {
this.rejectReason = rejectReason;
this.rejectDetail = rejectDetail;
this.appointmentStatus = appointmentStatus;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package org.sopt.seonyakServer.domain.appointment.repository;

import java.util.Optional;
import org.sopt.seonyakServer.domain.appointment.model.Appointment;
import org.sopt.seonyakServer.global.exception.enums.ErrorType;
import org.sopt.seonyakServer.global.exception.model.CustomException;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AppointmentRepository extends JpaRepository<Appointment, Long> {

Optional<Appointment> findAppointmentById(Long id);

default Appointment findAppointmentByIdOrThrow(Long id) {
return findAppointmentById(id)
.orElseThrow(() -> new CustomException(ErrorType.NOT_FOUND_APPOINTMENT_ERROR));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.sopt.seonyakServer.domain.appointment.service;

import java.util.Objects;
import lombok.RequiredArgsConstructor;
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.model.Appointment;
import org.sopt.seonyakServer.domain.appointment.model.AppointmentStatus;
Expand Down Expand Up @@ -41,4 +44,42 @@ public void postAppointment(AppointmentRequest appointmentRequest) {
);
appointmentRepository.save(appointment);
}

@Transactional
public void acceptAppointment(AppointmentAcceptRequest appointmentAcceptRequest) {
Appointment appointment = appointmentRepository.findAppointmentByIdOrThrow(
appointmentAcceptRequest.appointmentId());
Member member = memberRepository.findMemberByIdOrThrow(principalHandler.getUserIdFromPrincipal());

// 약속의 선배ID와 토크ID가 일치하지 않는 경우
if (!Objects.equals(member.getId(), appointment.getSenior().getId())) {
throw new CustomException(ErrorType.NOT_AUTHORIZATION_ACCEPT);
}

appointment.acceptAppointment(
appointmentAcceptRequest.timeList(),
appointmentAcceptRequest.googleMeetLink(),
AppointmentStatus.SCHEDULED
);
appointmentRepository.save(appointment);
}

@Transactional
public void rejectAppointment(AppointmentRejectRequest appointmentRejectRequest) {
Appointment appointment = appointmentRepository.findAppointmentByIdOrThrow(
appointmentRejectRequest.appointmentId());
Member member = memberRepository.findMemberByIdOrThrow(principalHandler.getUserIdFromPrincipal());

// 약속의 선배ID와 토크ID가 일치하지 않는 경우
if (!Objects.equals(member.getId(), appointment.getSenior().getId())) {
throw new CustomException(ErrorType.NOT_AUTHORIZATION_REJECT);
}

appointment.rejectAppointment(
appointmentRejectRequest.rejectReason(),
appointmentRejectRequest.rejectDetail(),
AppointmentStatus.REJECTED
);
appointmentRepository.save(appointment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public enum ErrorType {
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", "약속을 수락할 권한이 없습니다."),
NOT_AUTHORIZATION_REJECT(HttpStatus.UNAUTHORIZED, "40111", "약속을 거절할 권한이 없습니다."),

/**
* 404 NOT FOUND
Expand All @@ -62,6 +64,7 @@ public enum ErrorType {
NOT_FOUND_CREDENTIALS_JSON_ERROR(HttpStatus.NOT_FOUND, "40403", "구글미트 Credentials Json 파일을 찾을 수 없습니다."),
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", "존재하지 않는 약속입니다."),

/**
* 409 CONFLICT
Expand Down

0 comments on commit a2d0c94

Please sign in to comment.