-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
130 additions
and
6 deletions.
There are no files selected for viewing
Empty file.
27 changes: 27 additions & 0 deletions
27
...main/java/org/sopt/seonyakServer/domain/appointment/controller/AppointmentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.sopt.seonyakServer.domain.appointment.controller; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
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.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") | ||
public class AppointmentController { | ||
|
||
private final AppointmentService appointmentService; | ||
|
||
@PostMapping("") | ||
public ResponseEntity<Void> postAppointment( | ||
@RequestBody final AppointmentRequest appointmentRequest | ||
) { | ||
appointmentService.postAppointment(appointmentRequest); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
Empty file.
12 changes: 12 additions & 0 deletions
12
src/main/java/org/sopt/seonyakServer/domain/appointment/dto/AppointmentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.sopt.seonyakServer.domain.appointment.dto; | ||
|
||
import java.util.List; | ||
import org.sopt.seonyakServer.domain.appointment.model.DataTimeRange; | ||
|
||
public record AppointmentRequest( | ||
Long seniorId, | ||
List<String> topic, | ||
String personalTopic, | ||
List<DataTimeRange> timeList | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/org/sopt/seonyakServer/domain/appointment/model/DataTimeRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.seonyakServer.domain.appointment.model; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class DataTimeRange { | ||
private String date; | ||
private String startTime; | ||
private String endTime; | ||
} |
Empty file.
7 changes: 7 additions & 0 deletions
7
...main/java/org/sopt/seonyakServer/domain/appointment/repository/AppointmentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.sopt.seonyakServer.domain.appointment.repository; | ||
|
||
import org.sopt.seonyakServer.domain.appointment.model.Appointment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AppointmentRepository extends JpaRepository<Appointment, Long> { | ||
} |
Empty file.
44 changes: 44 additions & 0 deletions
44
src/main/java/org/sopt/seonyakServer/domain/appointment/service/AppointmentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.sopt.seonyakServer.domain.appointment.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.seonyakServer.domain.appointment.dto.AppointmentRequest; | ||
import org.sopt.seonyakServer.domain.appointment.model.Appointment; | ||
import org.sopt.seonyakServer.domain.appointment.model.AppointmentStatus; | ||
import org.sopt.seonyakServer.domain.appointment.repository.AppointmentRepository; | ||
import org.sopt.seonyakServer.domain.member.model.Member; | ||
import org.sopt.seonyakServer.domain.member.repository.MemberRepository; | ||
import org.sopt.seonyakServer.domain.senior.model.Senior; | ||
import org.sopt.seonyakServer.domain.senior.repository.SeniorRepository; | ||
import org.sopt.seonyakServer.global.auth.PrincipalHandler; | ||
import org.sopt.seonyakServer.global.exception.enums.ErrorType; | ||
import org.sopt.seonyakServer.global.exception.model.CustomException; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AppointmentService { | ||
|
||
private final AppointmentRepository appointmentRepository; | ||
private final SeniorRepository seniorRepository; | ||
private final MemberRepository memberRepository; | ||
private final PrincipalHandler principalHandler; | ||
|
||
@Transactional | ||
public void postAppointment(AppointmentRequest appointmentRequest) { | ||
Member member = memberRepository.findMemberByIdOrThrow(principalHandler.getUserIdFromPrincipal()); | ||
Senior senior = seniorRepository.findSeniorByIdOrThrow(appointmentRequest.seniorId()); | ||
if (member.getId().equals(senior.getId())) { | ||
throw new CustomException(ErrorType.SAME_MEMBER_APPOINTMENT_ERROR); | ||
} | ||
Appointment appointment = Appointment.createAppointment( | ||
member, | ||
senior, | ||
AppointmentStatus.PENDING, | ||
appointmentRequest.timeList(), | ||
appointmentRequest.topic(), | ||
appointmentRequest.personalTopic() | ||
); | ||
appointmentRepository.save(appointment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters