Skip to content

Commit

Permalink
test : admin test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong0329 committed Nov 15, 2024
1 parent c1130cd commit 1f5b402
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package com.wable.www.WableServer.api;

import com.wable.www.WableServer.common.config.jwt.AdminConfig;
import com.wable.www.WableServer.common.response.ApiResponse;
import com.wable.www.WableServer.common.response.ErrorStatus;
import com.wable.www.WableServer.common.util.MemberUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.List;

@RestController
@RequiredArgsConstructor
@Tag(name = "HealthCheck Controller", description = "HealthCheck API Document")
@SecurityRequirement(name = "JWT Auth")
public class HealthCheckController {

private final AdminConfig adminConfig;
@GetMapping("health")
@Operation(summary = "HealthCheck", description = "HealthCheck API입니다.")
public Long healthCheck(Principal principal) {
Expand All @@ -30,4 +35,15 @@ public Long healthCheck(Principal principal) {
public ApiResponse test() throws Exception {
throw new Exception(ErrorStatus.INTERNAL_SERVER_ERROR.getMessage());
}

@GetMapping("admin/test")
public Boolean isAdmin(Principal principal) {
Long memberId = MemberUtil.getMemberId(principal);
return isAllowedId(memberId);
}

public boolean isAllowedId(Long id) {
List<Long> allowedIds = adminConfig.getAllowedIds();
return allowedIds.contains(id);
}
}

0 comments on commit 1f5b402

Please sign in to comment.