Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.fisa.pg.dto.response.ApiKeyResponseDto;
import com.fisa.pg.dto.response.BaseResponse;
import com.fisa.pg.dto.response.WebhookResponseDto;
import com.fisa.pg.service.ApiKeyService;
import com.fisa.pg.service.WebhookService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -12,32 +14,42 @@
import org.springframework.web.bind.annotation.RestController;

/**
* 관리자용 API 키 관리 컨트롤러
* 관리자 전용 컨트롤러
* <p>
* 이 컨트롤러는 관리자에게 모든 가맹점의 API 키를 조회할 수 있는 엔드포인트를 제공합니다.
* 관리자 인증이 필요한 API이며, 가맹점 별 API 키 발급 및 관리 현황을 모니터링하는 용도로 사용됩니다.
* 이 컨트롤러는 관리자 전용 API를 제공합니다.
* </p>
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/admin/api-keys")
public class AdminApiKeyController {
@RequestMapping("/api/admin")
public class AdminController {

private final ApiKeyService apiKeyService;

private final WebhookService webhookService;

/**
* 전체 API 키 목록 페이징 조회 API
*
* @param pageable 페이지 번호, 페이지 크기, 정렬 조건 등의 페이징 정보
* @return 페이징된 API 키 목록과 함께 200 OK 응답
* @throws IllegalArgumentException 페이징 파라미터가 유효하지 않은 경우 발생
*/
@GetMapping
public ResponseEntity<BaseResponse<Page<ApiKeyResponseDto>>> getApiKeyList(
Pageable pageable
) {
@GetMapping("/api-keys")
public ResponseEntity<BaseResponse<Page<ApiKeyResponseDto>>> getApiKeyList(Pageable pageable) {
Page<ApiKeyResponseDto> data = apiKeyService.getApiKeyList(pageable);

return ResponseEntity.ok(BaseResponse.onSuccess("API 키 목록 조회 성공", data));
}

/**
* 관리자용 웹훅 목록 조회 API
*
* @param pageable 페이징 정보
* @return 웹훅 응답 DTO 페이지
*/
@GetMapping("/webhooks")
public ResponseEntity<BaseResponse<Page<WebhookResponseDto>>> getAllWebhooks(Pageable pageable) {
Page<WebhookResponseDto> data = webhookService.getWebhookList(pageable);
return ResponseEntity.ok(BaseResponse.onSuccess("모든 웹훅 조회 성공", data));
}
}
42 changes: 0 additions & 42 deletions src/main/java/com/fisa/pg/controller/AdminWebhookController.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.fisa.pg.controller;

import com.fisa.pg.dto.request.CreateApiKeyRequestDto;
import com.fisa.pg.dto.request.CreateWebhookRequestDto;
import com.fisa.pg.dto.response.ApiKeyResponseDto;
import com.fisa.pg.dto.response.BaseResponse;
import com.fisa.pg.dto.response.CreateApiKeyResponseDto;
import com.fisa.pg.dto.response.CreateWebhookResponseDto;
import com.fisa.pg.entity.user.Merchant;
import com.fisa.pg.service.ApiKeyService;
import com.fisa.pg.service.WebhookService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,21 +23,21 @@
import java.time.LocalDateTime;

/**
* 가맹점용 API 키 관리 컨트롤러
* 가맹점용 컨트롤러
* <p>
* 이 컨트롤러는 가맹점에게 자신의 API 키를 생성, 조회 및 비활성화할 수 있는 엔드포인트를 제공합니다.
* 가맹점은 인증된 상태에서만 이 API를 사용할 수 있으며, 자신의 API 키만 관리할 수 있습니다.
* API 키는 가맹점이 PG 시스템과 연동하기 위해 필요한 인증 수단입니다.
* 가맹점은 인증된 상태에서만 이 API를 사용할 수 있습니다.
* </p>
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/merchants/api-keys")
public class MerchantApiKeyController {
@RequestMapping("/api/merchants")
public class MerchantController {

private final ApiKeyService apiKeyService;

private final WebhookService webhookService;

/**
* 가맹점용 API 키 발급 엔드포인트
* <p>
Expand All @@ -47,7 +51,7 @@ public class MerchantApiKeyController {
* @return 생성된 API 키 정보와 함께 201 Created 응답
* @throws jakarta.validation.ConstraintViolationException 요청 데이터 유효성 검증 실패 시
*/
@PostMapping
@PostMapping("/api-keys")
public ResponseEntity<CreateApiKeyResponseDto> createApiKey(
@Valid @RequestBody CreateApiKeyRequestDto requestDto,
@AuthenticationPrincipal @NotNull Merchant merchant
Expand Down Expand Up @@ -80,7 +84,7 @@ public ResponseEntity<CreateApiKeyResponseDto> createApiKey(
* @param pageable 페이징 정보
* @return 가맹점의 API 키 목록 페이지와 함께 200 OK 응답
*/
@GetMapping
@GetMapping("/api-keys")
public ResponseEntity<Page<ApiKeyResponseDto>> getApiKeys(
@AuthenticationPrincipal @NotNull Merchant merchant,
Pageable pageable
Expand Down Expand Up @@ -110,7 +114,7 @@ public ResponseEntity<Page<ApiKeyResponseDto>> getApiKeys(
* @throws IllegalArgumentException API 키가 존재하지 않거나 가맹점이 소유하지 않은 경우
* @throws IllegalStateException API 키가 이미 비활성화된 경우
*/
@PatchMapping("/{keyId}/deactivate")
@PatchMapping("/api-keys/{keyId}/deactivate")
public ResponseEntity<Void> deactivateApiKey(
@PathVariable Long keyId,
@AuthenticationPrincipal @NotNull Merchant merchant
Expand All @@ -123,4 +127,38 @@ public ResponseEntity<Void> deactivateApiKey(
log.info("API 키 비활성화 완료: 가맹점 ID={}, 키 ID={}", merchant.getId(), keyId);
return ResponseEntity.noContent().build();
}

/**
* 가맹점 웹훅 생성 API
* <br/>
* 가맹점의 웹훅을 생성합니다.
*
* @param merchant 웹훅을 생성할 가맹점
* @param requestDto 웹훅 요청 DTO
* @return 웹훅 응답 DTO
*/
@PostMapping("/webhook")
public ResponseEntity<BaseResponse<CreateWebhookResponseDto>> createWebhook(
@AuthenticationPrincipal Merchant merchant,
@RequestBody CreateWebhookRequestDto requestDto
) {
CreateWebhookResponseDto response = webhookService.createWebhook(merchant.getId(), requestDto);
return ResponseEntity.ok(BaseResponse.onSuccess("가맹점 웹훅 생성 성공", response));
}

/**
* 가맹점 웹훅 조회 API
* <br/>
* 가맹점의 웹훅 설정 정보를 조회합니다.
*
* @param merchant 로그인한 가맹점
* @return 웹훅 응답 DTO
*/
@GetMapping("/webhook")
public ResponseEntity<BaseResponse<CreateWebhookResponseDto>> getWebhook(
@AuthenticationPrincipal Merchant merchant
) {
CreateWebhookResponseDto response = CreateWebhookResponseDto.from(merchant);
return ResponseEntity.ok(BaseResponse.onSuccess("가맹점 웹훅 조회 성공", response));
}
}

This file was deleted.