Skip to content

Commit

Permalink
[FIX/#84] Conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
ckkim817 committed Jul 15, 2024
2 parents 93dd0dd + ade9605 commit e18d9df
Show file tree
Hide file tree
Showing 34 changed files with 431 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@


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.dto.GoogleMeetLinkRequest;
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;
Expand All @@ -20,18 +23,34 @@ public class AppointmentController {

private final AppointmentService appointmentService;

@PostMapping("/appoinment")
@PostMapping("/appointment")
public ResponseEntity<Void> postAppointment(
@RequestBody final AppointmentRequest appointmentRequest
) {
appointmentService.postAppointment(appointmentRequest);
return ResponseEntity.ok().build();
}

@GetMapping("/google-meet")
@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();
}

@GetMapping("/google-meet/{appointmentId}")
public ResponseEntity<GoogleMeetLinkResponse> getGoogleMeetLink(
@RequestBody final GoogleMeetLinkRequest googleMeetLinkRequest
@PathVariable final Long appointmentId
) {
return ResponseEntity.ok(appointmentService.getGoogleMeetLink(googleMeetLinkRequest));
return ResponseEntity.ok(appointmentService.getGoogleMeetLink(appointmentId));
}
}
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
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private Appointment(
this.personalTopic = personalTopic;
}

public static Appointment createAppointment(
public static Appointment create(
Member member,
Senior senior,
AppointmentStatus appointmentStatus,
Expand All @@ -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,24 +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;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface AppointmentRepository extends JpaRepository<Appointment, Long> {

@Query("SELECT a.googleMeetLink "
+ "FROM Appointment a "
+ "WHERE a.id = :appointmentId")
String findGoogleMeetLinkById(@Param("appointmentId") Long appointmentId);
Optional<Appointment> findAppointmentById(Long id);

@Query("SELECT a.member.id "
+ "FROM Appointment a "
+ "WHERE a.id = :appointmentId")
Long findMemberIdById(@Param("appointmentId") Long appointmentId);

@Query("SELECT a.senior.id "
+ "FROM Appointment a "
+ "WHERE a.id = :appointmentId")
Long findSeniorIdById(@Param("appointmentId") Long appointmentId);
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,8 +1,10 @@
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.dto.GoogleMeetLinkRequest;
import org.sopt.seonyakServer.domain.appointment.dto.GoogleMeetLinkResponse;
import org.sopt.seonyakServer.domain.appointment.model.Appointment;
import org.sopt.seonyakServer.domain.appointment.model.AppointmentStatus;
Expand Down Expand Up @@ -33,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 @@ -44,17 +46,59 @@ 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);
}

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

Long userId = memberRepository.findMemberByIdOrThrow(principalHandler.getUserIdFromPrincipal()).getId();
Long memberId = appointmentRepository.findMemberIdById(googleMeetLinkRequest.appointmentId());
Long seniorId = appointmentRepository.findSeniorIdById(googleMeetLinkRequest.appointmentId());
Long memberId = appointment.getMember().getId();
Long seniorMemberId = appointment.getSenior().getMember().getId();

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

String googleMeetLink = appointmentRepository.findGoogleMeetLinkById(googleMeetLinkRequest.appointmentId());
String googleMeetLink = appointment.getGoogleMeetLink();

if (googleMeetLink == null || googleMeetLink.isEmpty()) {
throw new CustomException(ErrorType.NOT_FOUND_GOOGLE_MEET_LINK_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.sopt.seonyakServer.domain.member.dto.LoginSuccessResponse;
import org.sopt.seonyakServer.domain.member.dto.MemberJoinRequest;
import org.sopt.seonyakServer.domain.member.dto.MemberJoinResponse;
import org.sopt.seonyakServer.domain.member.dto.NicknameRequest;
import org.sopt.seonyakServer.domain.member.dto.SendCodeRequest;
import org.sopt.seonyakServer.domain.member.dto.VerifyCodeRequest;
import org.sopt.seonyakServer.domain.member.service.MemberService;
import org.sopt.seonyakServer.domain.member.service.MessageService;
import org.sopt.seonyakServer.global.common.external.client.dto.MemberLoginRequest;
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 @@ -27,11 +30,18 @@ public class MemberController {
@PostMapping("/auth/login")
public ResponseEntity<LoginSuccessResponse> login(
@RequestParam final String authorizationCode,
@RequestBody @Valid final MemberLoginRequest loginRequest
@Valid @RequestBody final MemberLoginRequest loginRequest
) {
return ResponseEntity.ok(memberService.create(authorizationCode, loginRequest));
}

@PatchMapping("/auth/join")
public ResponseEntity<MemberJoinResponse> join(
@RequestBody final MemberJoinRequest memberJoinRequest
) {
return ResponseEntity.ok(memberService.patchMemberJoin(memberJoinRequest));
}

@PostMapping("/nickname")
public ResponseEntity<Void> validNickname(
@Valid @RequestBody final NicknameRequest nicknameRequest
Expand All @@ -43,7 +53,7 @@ public ResponseEntity<Void> validNickname(

@PostMapping("/phone/verify")
public ResponseEntity<Void> sendCode(
@RequestBody final SendCodeRequest sendCodeRequest
@Valid @RequestBody final SendCodeRequest sendCodeRequest
) {
messageService.sendMessage(sendCodeRequest);

Expand All @@ -52,7 +62,7 @@ public ResponseEntity<Void> sendCode(

@PostMapping("/phone/verifycode")
public ResponseEntity<Void> verifyCode(
@RequestBody final VerifyCodeRequest verifyCodeRequest
@Valid @RequestBody final VerifyCodeRequest verifyCodeRequest
) {
messageService.verifyCode(verifyCodeRequest);
messageService.validPhoneNumberDuplication(verifyCodeRequest);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.sopt.seonyakServer.domain.member.dto;

import java.util.List;

public record MemberJoinRequest(
String role,
Boolean isSubscribed,
String nickname,
String image,
String phoneNumber,
String univName,
String field,
List<String> departmentList,
String businessCard,
String company,
String position,
String detailPosition,
String level
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.seonyakServer.domain.member.dto;

public record MemberJoinResponse(
String role
) {
public static MemberJoinResponse of(final String role) {
return new MemberJoinResponse(role);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.sopt.seonyakServer.domain.member.dto;

import jakarta.validation.constraints.NotBlank;

public record SendCodeRequest(
@NotBlank(message = "전화번호는 공백일 수 없습니다.")
String phoneNumber
) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.sopt.seonyakServer.domain.member.dto;

import jakarta.validation.constraints.NotBlank;

public record VerifyCodeRequest(
@NotBlank(message = "전화번호는 공백일 수 없습니다.")
String phoneNumber,

@NotBlank(message = "인증번호는 공백일 수 없습니다.")
String verificationCode
) {
}
Loading

0 comments on commit e18d9df

Please sign in to comment.