-
Notifications
You must be signed in to change notification settings - Fork 0
관리자 페이지 추가 #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
관리자 페이지 추가 #49
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dbbdbdb
feat(admin): 관리자 권한 분리
Jaehyeon-Han 4800339
fix: Swagger 서버 도메인 오류 수정
Jaehyeon-Han 2f1f6bb
refactor(ai): 로깅 및 프롬프트 활성화 예외 케이스 보완
Jaehyeon-Han 5a7b779
feat(admin): 프롬프트 관리 페이지 리액트 빌드 결과 추가
Jaehyeon-Han c6a99e9
feat(admin): admin 테이블 flyway 추가
Jaehyeon-Han 3b09b19
refactor(ai, admin): Copilot 리뷰 의견 반영
Jaehyeon-Han File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/example/konnect_backend/domain/admin/controller/AdminAuthController.java
This file contains hidden or 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,39 @@ | ||
| package com.example.konnect_backend.domain.admin.controller; | ||
|
|
||
| import com.example.konnect_backend.domain.admin.dto.request.AdminLoginRequest; | ||
| import com.example.konnect_backend.domain.admin.service.AdminAuthService; | ||
| import com.example.konnect_backend.domain.auth.dto.response.AuthResponse; | ||
| import com.example.konnect_backend.global.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.Hidden; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| 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 | ||
| @RequestMapping("/api/admin/auth") | ||
| @RequiredArgsConstructor | ||
| @Hidden | ||
| @Tag(name = "Admin Authentication", description = "관리자 인증 (스펙 비노출)") | ||
| public class AdminAuthController { | ||
|
|
||
| private final AdminAuthService adminAuthService; | ||
|
|
||
| @PostMapping("/login") | ||
| @Operation(summary = "관리자 로그인", description = "요청 JSON의 id(로그인 ID)·password 검증 후 ADMIN 역할 JWT 액세스 토큰을 발급합니다.") | ||
| @ApiResponses(value = { | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "성공"), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))), | ||
| @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "계정 없음 또는 비밀번호 불일치", content = @Content(schema = @Schema(implementation = ApiResponse.class))) | ||
| }) | ||
| public ApiResponse<AuthResponse> login(@Valid @RequestBody AdminLoginRequest request) { | ||
| return ApiResponse.onSuccess(adminAuthService.login(request)); | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
...ontroller/PromptManagementController.java → ...ontroller/PromptManagementController.java
This file contains hidden or 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/example/konnect_backend/domain/admin/dto/request/AdminLoginRequest.java
This file contains hidden or 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,24 @@ | ||
| package com.example.konnect_backend.domain.admin.dto.request; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @Schema(description = "관리자 로그인 요청") | ||
| public class AdminLoginRequest { | ||
|
|
||
| @NotBlank | ||
| @JsonProperty("id") | ||
| @Schema(description = "로그인 ID", example = "root") | ||
| private String loginId; | ||
|
|
||
| @NotBlank | ||
| @Schema(description = "비밀번호") | ||
| private String password; | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/example/konnect_backend/domain/admin/entity/Admin.java
This file contains hidden or 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,31 @@ | ||
| package com.example.konnect_backend.domain.admin.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| @Table(name = "admin") | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class Admin { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "login_id", nullable = false, unique = true, length = 64) | ||
| private String loginId; | ||
|
|
||
| @Column(nullable = false) | ||
| private String password; | ||
|
|
||
| @Column(length = 100) | ||
| private String name; | ||
|
|
||
| @Column(name = "created_at", nullable = false, updatable = false, insertable = false) | ||
| private LocalDateTime createdAt; | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/konnect_backend/domain/admin/repository/AdminRepository.java
This file contains hidden or 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,11 @@ | ||
| package com.example.konnect_backend.domain.admin.repository; | ||
|
|
||
| import com.example.konnect_backend.domain.admin.entity.Admin; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface AdminRepository extends JpaRepository<Admin, Long> { | ||
|
|
||
| Optional<Admin> findByLoginId(String loginId); | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/konnect_backend/domain/admin/service/AdminAuthService.java
This file contains hidden or 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,35 @@ | ||
| package com.example.konnect_backend.domain.admin.service; | ||
|
|
||
| import com.example.konnect_backend.domain.admin.dto.request.AdminLoginRequest; | ||
| import com.example.konnect_backend.domain.admin.entity.Admin; | ||
| import com.example.konnect_backend.domain.admin.repository.AdminRepository; | ||
| import com.example.konnect_backend.domain.auth.dto.response.AuthResponse; | ||
| import com.example.konnect_backend.global.code.status.ErrorStatus; | ||
| import com.example.konnect_backend.global.exception.GeneralException; | ||
| import com.example.konnect_backend.global.security.JwtTokenProvider; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class AdminAuthService { | ||
|
|
||
| private final AdminRepository adminRepository; | ||
| private final PasswordEncoder passwordEncoder; | ||
| private final JwtTokenProvider jwtTokenProvider; | ||
|
|
||
| public AuthResponse login(AdminLoginRequest request) { | ||
| Admin admin = adminRepository.findByLoginId(request.getLoginId()) | ||
| .orElseThrow(() -> new GeneralException(ErrorStatus.PASSWORD_FAILED)); | ||
|
|
||
| if (!passwordEncoder.matches(request.getPassword(), admin.getPassword())) { | ||
| throw new GeneralException(ErrorStatus.PASSWORD_FAILED); | ||
| } | ||
|
|
||
| String accessToken = jwtTokenProvider.createToken(admin.getId(), "ADMIN"); | ||
| return AuthResponse.of(accessToken, admin.getId(), "ADMIN"); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| CREATE TABLE `admin` | ||
| ( | ||
| id BIGINT NOT NULL AUTO_INCREMENT, | ||
| login_id VARCHAR(64) NOT NULL, | ||
| password VARCHAR(255) NOT NULL, | ||
| name VARCHAR(100) NULL, | ||
| created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), | ||
| PRIMARY KEY (id), | ||
| UNIQUE KEY uk_admin_login_id (login_id) | ||
| ) ENGINE = InnoDB | ||
| DEFAULT CHARSET = utf8mb4 | ||
| COLLATE = utf8mb4_unicode_ci; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.