Skip to content

Commit

Permalink
Merge pull request #90 from kakao-tech-campus-2nd-step3/Weekly
Browse files Browse the repository at this point in the history
7주차 산출물(Weekly -> Develop)
  • Loading branch information
zzoe2346 authored Oct 18, 2024
2 parents f84bbda + 5009cc8 commit 65a340f
Show file tree
Hide file tree
Showing 82 changed files with 3,136 additions and 469 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'
implementation group: 'com.twilio.sdk', name: 'twilio', version: '10.5.0'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1'
}

tasks.named('test') {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/example/sinitto/SinittoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableJpaAuditing
@EnableConfigurationProperties(KakaoProperties.class)
@EnableScheduling
public class SinittoApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import jakarta.validation.constraints.NotNull;

@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
public record KakaoTokenResponse(
String accessToken,
String refreshToken,
@NotNull
int expiresIn,
@NotNull
int refreshTokenExpiresIn

) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.sinitto.callback.controller;

import com.example.sinitto.callback.dto.CallbackResponse;
import com.example.sinitto.callback.dto.CallbackUsageHistoryResponse;
import com.example.sinitto.callback.service.CallbackService;
import com.example.sinitto.common.annotation.MemberId;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -25,18 +26,18 @@ public CallbackController(CallbackService callbackService) {

@Operation(summary = "콜백 전화 리스트 보기(페이지)", description = "시니어가 요청한 콜백전화를 페이징으로 보여줍니다.")
@GetMapping
public ResponseEntity<Page<CallbackResponse>> getCallbackList(@MemberId Long memberId,
@PageableDefault(sort = "postTime", direction = Sort.Direction.DESC) Pageable pageable) {
public ResponseEntity<Page<CallbackResponse>> getWaitingCallbackList(@MemberId Long memberId,
@PageableDefault(sort = "postTime", direction = Sort.Direction.DESC) Pageable pageable) {

return ResponseEntity.ok(callbackService.getCallbacks(memberId, pageable));
return ResponseEntity.ok(callbackService.getWaitingCallbacks(memberId, pageable));
}

@Operation(summary = "진행 상태인 콜백을 완료 대기 상태로 전환(시니또가)", description = "시니또가 수락한 콜백 수행을 완료했을때 이 api 호출하면 완료 대기 상태로 변합니다.")
@PutMapping("/pendingComplete/{callbackId}")
public ResponseEntity<Void> pendingCompleteCallback(@MemberId Long memberId,
@PathVariable Long callbackId) {

callbackService.pendingComplete(memberId, callbackId);
callbackService.changeCallbackStatusToPendingCompleteBySinitto(memberId, callbackId);
return ResponseEntity.ok().build();
}

Expand All @@ -45,7 +46,7 @@ public ResponseEntity<Void> pendingCompleteCallback(@MemberId Long memberId,
public ResponseEntity<Void> completeCallback(@MemberId Long memberId,
@PathVariable Long callbackId) {

callbackService.complete(memberId, callbackId);
callbackService.changeCallbackStatusToCompleteByGuard(memberId, callbackId);
return ResponseEntity.ok().build();
}

Expand All @@ -54,7 +55,7 @@ public ResponseEntity<Void> completeCallback(@MemberId Long memberId,
public ResponseEntity<Void> acceptCallback(@MemberId Long memberId,
@PathVariable Long callbackId) {

callbackService.accept(memberId, callbackId);
callbackService.acceptCallbackBySinitto(memberId, callbackId);
return ResponseEntity.ok().build();
}

Expand All @@ -63,14 +64,14 @@ public ResponseEntity<Void> acceptCallback(@MemberId Long memberId,
public ResponseEntity<Void> cancelCallback(@MemberId Long memberId,
@PathVariable Long callbackId) {

callbackService.cancel(memberId, callbackId);
callbackService.cancelCallbackAssignmentBySinitto(memberId, callbackId);
return ResponseEntity.ok().build();
}

@PostMapping("/twilio")
public ResponseEntity<String> addCallCheck(@RequestParam("From") String fromNumber) {

return ResponseEntity.ok(callbackService.add(fromNumber));
return ResponseEntity.ok(callbackService.createCallbackByCall(fromNumber));
}

@Operation(summary = "시니또에게 현재 할당된 콜백 조회", description = "현재 시니또 본인에게 할당된 콜백을 조회합니다.")
Expand All @@ -79,4 +80,20 @@ public ResponseEntity<CallbackResponse> getAcceptedCallback(@MemberId Long membe

return ResponseEntity.ok(callbackService.getAcceptedCallback(memberId));
}

@Operation(summary = "보호자의 콜백 이용 내역 조회", description = "보호자에게 연관된 모든 콜백 내역을 조회합니다. 기본적으로 최신 내역 부터 조회됩니다.")
@GetMapping("/guard/requested")
public ResponseEntity<Page<CallbackUsageHistoryResponse>> getAcceptedCallback(@MemberId Long memberId,
@PageableDefault(sort = "postTime", direction = Sort.Direction.DESC) Pageable pageable) {

return ResponseEntity.ok(callbackService.getCallbackHistoryOfGuard(memberId, pageable));
}

@Operation(summary = "콜백 단건 조회", description = "콜백 id 로 콜백을 단건 조회합니다.")
@GetMapping("/{callbackId}")
public ResponseEntity<CallbackResponse> getCallback(@PathVariable("callbackId") Long callbackId) {

return ResponseEntity.ok(callbackService.getCallback(callbackId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.sinitto.callback.dto;

import java.time.LocalDateTime;

public record CallbackUsageHistoryResponse(
Long callbackId,
String seniorName,
LocalDateTime postTime,
String status
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Callback {
private Long id;
@CreatedDate
private LocalDateTime postTime;
private LocalDateTime pendingCompleteTime;
@NotNull
@Enumerated(EnumType.STRING)
private Callback.Status status;
Expand Down Expand Up @@ -140,6 +141,14 @@ public Long getAssignedMemberId() {
return assignedMemberId;
}

public LocalDateTime getPendingCompleteTime() {
return pendingCompleteTime;
}

public void setPendingCompleteTime(LocalDateTime pendingCompleteTime) {
this.pendingCompleteTime = pendingCompleteTime;
}

public enum Status {
WAITING,
IN_PROGRESS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.sinitto.callback.exception;

public class MemberHasInProgressCallbackException extends ConflictException {

public MemberHasInProgressCallbackException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package com.example.sinitto.callback.repository;

import com.example.sinitto.callback.entity.Callback;
import com.example.sinitto.member.entity.Senior;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface CallbackRepository extends JpaRepository<Callback, Long> {

Page<Callback> findAll(Pageable pageable);
Page<Callback> findAllByStatus(Callback.Status status, Pageable pageable);

Optional<Callback> findByAssignedMemberIdAndStatus(Long memberId, Callback.Status status);

boolean existsByAssignedMemberIdAndStatus(Long memberId, Callback.Status status);

Page<Callback> findAllBySeniorIn(List<Senior> seniors, Pageable pageable);

List<Callback> findAllByStatusAndPendingCompleteTimeBefore(Callback.Status status, LocalDateTime dateTime);

boolean existsBySeniorAndStatusIn(Senior senior, List<Callback.Status> statuses);
}
Loading

0 comments on commit 65a340f

Please sign in to comment.