Skip to content

Commit

Permalink
Merge branch 'Weekly' into Feat/issue-#193,#194,#195
Browse files Browse the repository at this point in the history
  • Loading branch information
zzoe2346 authored Nov 9, 2024
2 parents 7ca4c7f + d2e8c7d commit a3e9011
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.domain.Page;
Expand All @@ -27,15 +26,15 @@ public CallbackController(CallbackService callbackService) {

@Operation(summary = "콜백 μ „ν™” 리슀트 보기(νŽ˜μ΄μ§€)", description = "μ‹œλ‹ˆμ–΄κ°€ μš”μ²­ν•œ μ½œλ°±μ „ν™”λ₯Ό νŽ˜μ΄μ§•μœΌλ‘œ λ³΄μ—¬μ€λ‹ˆλ‹€.")
@GetMapping
public ResponseEntity<Page<CallbackResponse>> getWaitingCallbackList(@MemberId Long memberId,
public ResponseEntity<Page<CallbackResponse>> getWaitingCallbackList(@RequestAttribute("memberId") Long memberId,
@PageableDefault(sort = "postTime", direction = Sort.Direction.DESC) Pageable pageable) {

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

@Operation(summary = "진행 μƒνƒœμΈ μ½œλ°±μ„ μ™„λ£Œ λŒ€κΈ° μƒνƒœλ‘œ μ „ν™˜(μ‹œλ‹ˆλ˜κ°€)", description = "μ‹œλ‹ˆλ˜κ°€ μˆ˜λ½ν•œ 콜백 μˆ˜ν–‰μ„ μ™„λ£Œν–ˆμ„λ•Œ 이 api ν˜ΈμΆœν•˜λ©΄ μ™„λ£Œ λŒ€κΈ° μƒνƒœλ‘œ λ³€ν•©λ‹ˆλ‹€.")
@PutMapping("/pendingComplete/{callbackId}")
public ResponseEntity<Void> pendingCompleteCallback(@MemberId Long memberId,
public ResponseEntity<Void> pendingCompleteCallback(@RequestAttribute("memberId") Long memberId,
@PathVariable Long callbackId) {

callbackService.changeCallbackStatusToPendingCompleteBySinitto(memberId, callbackId);
Expand All @@ -44,7 +43,7 @@ public ResponseEntity<Void> pendingCompleteCallback(@MemberId Long memberId,

@Operation(summary = "μ™„λ£Œ λŒ€κΈ° μƒνƒœμΈ μ½œλ°±μ„ μ™„λ£Œ μƒνƒœλ‘œ μ „ν™˜(λ³΄ν˜Έμžκ°€)", description = "λ³΄ν˜Έμžκ°€ μ™„λ£Œ λŒ€κΈ° μƒνƒœμΈ μ½œλ°±μ„ μ™„λ£Œ ν™•μ • μ‹œν‚΅λ‹ˆλ‹€.")
@PutMapping("/complete/{callbackId}")
public ResponseEntity<Void> completeCallback(@MemberId Long memberId,
public ResponseEntity<Void> completeCallback(@RequestAttribute("memberId") Long memberId,
@PathVariable Long callbackId) {

callbackService.changeCallbackStatusToCompleteByGuard(memberId, callbackId);
Expand All @@ -53,7 +52,7 @@ public ResponseEntity<Void> completeCallback(@MemberId Long memberId,

@Operation(summary = "콜백 μ„œλΉ„μŠ€ 수락 μ‹ μ²­", description = "μ‹œλ‹ˆλ˜κ°€ 콜백 μ„œλΉ„μŠ€ μˆ˜λ½μ„ μ‹ μ²­ν•©λ‹ˆλ‹€.")
@PutMapping("/accept/{callbackId}")
public ResponseEntity<Void> acceptCallback(@MemberId Long memberId,
public ResponseEntity<Void> acceptCallback(@RequestAttribute("memberId") Long memberId,
@PathVariable Long callbackId) {

callbackService.acceptCallbackBySinitto(memberId, callbackId);
Expand All @@ -62,7 +61,7 @@ public ResponseEntity<Void> acceptCallback(@MemberId Long memberId,

@Operation(summary = "진행쀑인 콜백 μ„œλΉ„μŠ€ μ·¨μ†Œ", description = "μ‹œλ‹ˆλ˜κ°€ 진행쀑인 콜백 μ„œλΉ„μŠ€λ₯Ό μ·¨μ†Œν•©λ‹ˆλ‹€. μ½œλ°±μ€ λ‹€μ‹œ λŒ€κΈ° μƒνƒœλ‘œ λŒμ•„κ°‘λ‹ˆλ‹€.")
@PutMapping("/cancel/{callbackId}")
public ResponseEntity<Void> cancelCallback(@MemberId Long memberId,
public ResponseEntity<Void> cancelCallback(@RequestAttribute("memberId") Long memberId,
@PathVariable Long callbackId) {

callbackService.cancelCallbackAssignmentBySinitto(memberId, callbackId);
Expand All @@ -77,22 +76,22 @@ public ResponseEntity<String> addCallCheck(@RequestParam("From") String fromNumb

@Operation(summary = "μ‹œλ‹ˆλ˜μ—κ²Œ ν˜„μž¬ ν• λ‹Ήλœ 콜백 쑰회", description = "ν˜„μž¬ μ‹œλ‹ˆλ˜ λ³ΈμΈμ—κ²Œ ν• λ‹Ήλœ μ½œλ°±μ„ μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping("/sinitto/accepted")
public ResponseEntity<CallbackResponse> getAcceptedCallback(@MemberId Long memberId) {
public ResponseEntity<CallbackResponse> getAcceptedCallback(@RequestAttribute("memberId") Long memberId) {

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

@Operation(summary = "보호자의 콜백 이용 λ‚΄μ—­ 쑰회", description = "λ³΄ν˜Έμžμ—κ²Œ μ—°κ΄€λœ λͺ¨λ“  콜백 내역을 μ‘°νšŒν•©λ‹ˆλ‹€. 기본적으둜 μ΅œμ‹  λ‚΄μ—­ λΆ€ν„° μ‘°νšŒλ©λ‹ˆλ‹€.")
@GetMapping("/guard/requested")
public ResponseEntity<Page<CallbackUsageHistoryResponse>> getAcceptedCallback(@MemberId Long memberId,
public ResponseEntity<Page<CallbackUsageHistoryResponse>> getAcceptedCallback(@RequestAttribute("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<CallbackForSinittoResponse> getCallback(@MemberId Long memberId,
public ResponseEntity<CallbackForSinittoResponse> getCallback(@RequestAttribute("memberId") Long memberId,
@PathVariable("callbackId") Long callbackId) {

return ResponseEntity.ok(callbackService.getCallbackForSinitto(memberId, callbackId));
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/example/sinitto/common/annotation/MemberId.java

This file was deleted.

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/java/com/example/sinitto/common/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.sinitto.common.config;

import com.example.sinitto.common.interceptor.JwtInterceptor;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
Expand All @@ -13,6 +14,7 @@
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.time.Duration;
Expand All @@ -23,6 +25,11 @@ public class WebConfig implements WebMvcConfigurer {
private static final int TIME_OUT_DURATION = 5;
private static final int MAX_OPEN_CONNECTIONS = 100;
private static final int CONNECTIONS_PER_IP_PORT_PAIR = 5;
private final JwtInterceptor jwtInterceptor;

public WebConfig(JwtInterceptor jwtInterceptor){
this.jwtInterceptor = jwtInterceptor;
}

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder, RestTemplateResponseErrorHandler errorHandler) {
Expand Down Expand Up @@ -62,4 +69,9 @@ public CorsFilter corsFilter() {
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor).addPathPatterns("/api/**");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.sinitto.common.interceptor;

import com.example.sinitto.common.exception.UnauthorizedException;
import com.example.sinitto.member.service.MemberTokenService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import java.lang.reflect.Method;

@Component
public class JwtInterceptor implements HandlerInterceptor {
private final MemberTokenService memberTokenService;

public JwtInterceptor(MemberTokenService memberTokenService){
this.memberTokenService = memberTokenService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();

Class<?>[] parameterTypes = method.getParameterTypes();

for (Class<?> paramType : parameterTypes) {
if (paramType.equals(Long.class)) {
String authorizationHeader = request.getHeader("Authorization");
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) {
throw new UnauthorizedException("토큰이 μ—†κ±°λ‚˜, 헀더 ν˜•μ‹μ— λ§žμ§€ μ•ŠμŠ΅λ‹ˆλ‹€.");
}

String token = authorizationHeader.substring(7);

request.setAttribute("memberId", memberTokenService.getMemberIdByToken(token));
return true;
}
}
}

return true;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.sinitto.guard.controller;

import com.example.sinitto.common.annotation.MemberId;
import com.example.sinitto.guard.dto.GuardRequest;
import com.example.sinitto.guard.dto.GuardResponse;
import com.example.sinitto.guard.dto.SeniorRequest;
Expand All @@ -25,61 +24,61 @@ public GuardController(GuardService guardService) {

@Operation(summary = "μ—°κ²°λœ λͺ¨λ“  μ‹œλ‹ˆμ–΄ 정보 쑰회", description = "λ³΄ν˜Έμžκ°€ λ“±λ‘ν•œ λͺ¨λ“  μ‹œλ‹ˆμ–΄μ˜ 정보λ₯Ό μš”μ²­ν•©λ‹ˆλ‹€.")
@GetMapping("/senior")
public ResponseEntity<List<SeniorResponse>> getAllSeniors(@MemberId Long memberId) {
public ResponseEntity<List<SeniorResponse>> getAllSeniors(@RequestAttribute("memberId") Long memberId) {
return ResponseEntity.ok(guardService.readSeniors(memberId));
}

@Operation(summary = "μ—°κ²°λœ νŠΉμ • μ‹œλ‹ˆμ–΄ 정보 쑰회", description = "λ³΄ν˜Έμžκ°€ λ“±λ‘ν•œ νŠΉμ • μ‹œλ‹ˆμ–΄μ˜ 정보λ₯Ό μš”μ²­ν•©λ‹ˆλ‹€.")
@GetMapping("/senior/{seniorId}")
public ResponseEntity<SeniorResponse> getSenior(@MemberId Long memberId, @PathVariable Long seniorId) {
public ResponseEntity<SeniorResponse> getSenior(@RequestAttribute("memberId") Long memberId, @PathVariable Long seniorId) {
return ResponseEntity.ok(guardService.readOneSenior(memberId, seniorId));
}

@Operation(summary = "μ‹œλ‹ˆμ–΄ 정보 μˆ˜μ •", description = "μ‹œλ‹ˆμ–΄μ˜ 정보λ₯Ό μˆ˜μ •ν•©λ‹ˆλ‹€.")
@PutMapping("/senior/{seniorId}")
public ResponseEntity<String> updateSenior(@MemberId Long memberId, @PathVariable Long seniorId, @RequestBody SeniorRequest seniorRequest) {
public ResponseEntity<String> updateSenior(@RequestAttribute("memberId") Long memberId, @PathVariable Long seniorId, @RequestBody SeniorRequest seniorRequest) {
guardService.updateSenior(memberId, seniorId, seniorRequest);
return ResponseEntity.ok("μ‹œλ‹ˆμ–΄ 정보가 μˆ˜μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
}

@Operation(summary = "μ‹œλ‹ˆμ–΄ μΆ”κ°€", description = "λ³΄ν˜Έμžκ°€ μƒˆλ‘œμš΄ μ‹œλ‹ˆμ–΄λ₯Ό λ“±λ‘ν•©λ‹ˆλ‹€.")
@PostMapping("/senior")
public ResponseEntity<String> createSenior(@MemberId Long memberId, @RequestBody SeniorRequest seniorRequest) {
public ResponseEntity<String> createSenior(@RequestAttribute("memberId") Long memberId, @RequestBody SeniorRequest seniorRequest) {
guardService.createSenior(memberId, seniorRequest);
return ResponseEntity.ok("μƒˆλ‘œμš΄ μ‹œλ‹ˆμ–΄κ°€ λ“±λ‘λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
}

@Operation(summary = "μ‹œλ‹ˆμ–΄ μ‚­μ œ", description = "λ³΄ν˜Έμžκ°€ μ‹œλ‹ˆμ–΄λ₯Ό 등둝 ν•΄μ œν•©λ‹ˆλ‹€.")
@DeleteMapping("/senior/{seniorId}")
public ResponseEntity<String> deleteSenior(@MemberId Long memberId, @PathVariable Long seniorId) {
public ResponseEntity<String> deleteSenior(@RequestAttribute("memberId") Long memberId, @PathVariable Long seniorId) {
guardService.deleteSenior(memberId, seniorId);
return ResponseEntity.ok("μ‹œλ‹ˆμ–΄κ°€ μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
}

@Operation(summary = "보호자 본인 정보 쑰회", description = "보호자의 본인 정보λ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping
public ResponseEntity<GuardResponse> getGuardInfo(@MemberId Long memberId) {
public ResponseEntity<GuardResponse> getGuardInfo(@RequestAttribute("memberId") Long memberId) {
return ResponseEntity.ok(guardService.readGuard(memberId));
}

@Operation(summary = "보호자 본인 정보 μˆ˜μ •", description = "보호자의 본인 정보λ₯Ό μˆ˜μ •ν•©λ‹ˆλ‹€.")
@PutMapping
public ResponseEntity<String> updateGuardInfo(@MemberId Long memberId, @RequestBody GuardRequest guardRequest) {
public ResponseEntity<String> updateGuardInfo(@RequestAttribute("memberId") Long memberId, @RequestBody GuardRequest guardRequest) {
guardService.updateGuard(memberId, guardRequest);
return ResponseEntity.ok("보호자 정보가 μˆ˜μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
}

// ν˜„μž¬λŠ” jwt μ•ˆμ˜ idλ₯Ό μ‚­μ œν•˜κ²Œ κ΅¬ν˜„ν–ˆλŠ”λ°, λ‚˜μ€‘μ— κ΄€λ¦¬μž 계정 λ§Œλ“€λ©΄ νŠΉμ • id μ§€μ •ν•΄μ„œ μ‚­μ œν•˜κ²Œ μˆ˜μ •ν•΄μ•Όν•  λ“―ν•©λ‹ˆλ‹€.
@Operation(summary = "보호자 μ‚­μ œ", description = "κ΄€λ¦¬μžμš© APIμž…λ‹ˆλ‹€.")
@DeleteMapping
public ResponseEntity<String> deleteGuard(@MemberId Long memberId) {
public ResponseEntity<String> deleteGuard(@RequestAttribute("memberId") Long memberId) {
guardService.deleteGuard(memberId);
return ResponseEntity.ok("λ³΄ν˜Έμžκ°€ μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
}

@Operation(summary = "λͺ¨λ“  보호자 쑰회", description = "κ΄€λ¦¬μžμš© APIμž…λ‹ˆλ‹€.")
@GetMapping("/all")
public ResponseEntity<List<GuardResponse>> getAllGuards(@MemberId Long memberId) {
public ResponseEntity<List<GuardResponse>> getAllGuards() {
return ResponseEntity.ok(guardService.readAllGuards());
}

Expand Down
Loading

0 comments on commit a3e9011

Please sign in to comment.