-
Notifications
You must be signed in to change notification settings - Fork 2
문의, 문의 답변, 관리자 기능 구현 #166
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
Merged
문의, 문의 답변, 관리자 기능 구현 #166
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a256175
Enhance README with authors and API details
Seol-JY 75489e5
fix: 오류 있는 부분 수정
wafla f7094c7
feat: 관리자 기능 구현
wafla 1e750f3
feat: 문의, 문의 답변 기능 구현
wafla 8514f9f
feat: 문의, 문의 답변 기능 구현
wafla ca6c7c6
fix: 테스트 코드 수정
wafla 0fd5c61
fix: 테스트 코드 수정
wafla 78a9ffc
fix: 오류 사항 수정
wafla 4f65927
fix: 오류 사항 수정
wafla 9539a1b
fix: 오류 사항 수정
wafla fc15b24
fix: 오류 사항 수정
wafla 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
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 |
|---|---|---|
| @@ -1,12 +1,36 @@ | ||
| <p align="center"> | ||
| <img src="https://github.com/user-attachments/assets/1060eb65-877a-4fb4-bbdc-9ee68a66afa8" alt="토덕 To.duck Logo" width="150"/> | ||
| </p> | ||
| <h1 align="center">토덕 To.duck</h1> | ||
| <p align="center"> | ||
| <strong>성인 ADHD인을 위한 토닥임</strong> | ||
| </p> | ||
| <p align="center"> | ||
| <a href="https://apps.apple.com/us/app/%ED%86%A0%EB%8D%95-to-duck-%EC%84%B1%EC%9D%B8-adhd%EC%9D%B8%EC%9D%84-%EC%9C%84%ED%95%9C-%ED%86%A0%EB%8B%A5%EC%9E%84/id6502951629"> | ||
| <img src="https://tools.applemediaservices.com/api/badges/download-on-the-app-store/black/en-us?size=250x83" alt="Download on the App Store" height="120"/> | ||
| </a> | ||
| </p> | ||
| <p align="center"> | ||
| Copyright © 2025 To.duck Team | ||
| </p> | ||
| <br/> | ||
|
|
||
| ### 🔗 API | ||
| - [https://api-toduck.seol.pro](https://api-toduck.seol.pro/) | ||
| - [Swagger UI](https://api-toduck.seol.pro/swagger-ui/index.html) | ||
| - [에러 코드](https://api-toduck.seol.pro/exception-codes) | ||
|
|
||
| <br/> | ||
|
|
||
| ### 🧑💻 Authors | ||
| | 강민기 | 박준하 | 설진영 | 최연우 | | ||
| |:----------------------------------------------------------------------------:|:----------------------------------------------------------------------------:|:----------------------------------------------------------------------------:|:----------------------------------------------------------------------------:| | ||
| | <img src="https://avatars.githubusercontent.com/u/75325326?v=4" width="80"/> | <img src="https://avatars.githubusercontent.com/u/67590577?v=4" width="80"/> | <img src="https://avatars.githubusercontent.com/u/70826982?v=4" width="80"/> | <img src="https://avatars.githubusercontent.com/u/50083524?v=4" width="80"/> | | ||
| | [@kang20](https://github.com/kang20) | [@Junad-Park](https://github.com/Junad-Park) | [@Seol-JY](https://github.com/Seol-JY) | [@wafla](https://github.com/wafla) | | ||
|
|
||
| | 강민기 | 박준하 | 설진영 | | ||
| |:----------------------------------------------------------------------------:|:----------------------------------------------------------------------------:|:----------------------------------------------------------------------------:| | ||
| | <img src="https://avatars.githubusercontent.com/u/75325326?v=4" width="80"/> | <img src="https://avatars.githubusercontent.com/u/67590577?v=4" width="80"/> | <img src="https://avatars.githubusercontent.com/u/70826982?v=4" width="80"/> | | ||
| | [@kang20](https://github.com/kang20) | [@Junad-Park](https://github.com/Junad-Park) | [@Seol-JY](https://github.com/Seol-JY) | | ||
| <br/> | ||
|
|
||
| ### 📜 Docs | ||
|
|
||
| - [초기 개발환경 설정](https://kyxxn.notion.site/fdf5a3a523f040328a9c68d4377ff997?pvs=74) | ||
| - [개발 가이드](https://kyxxn.notion.site/9a2670768f784ea5bb3ca8f044ede895) | ||
| - [API 개요](https://kyxxn.notion.site/API-e775e161efa6459583a0ee0d586c4d19) |
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/im/toduck/domain/admin/common/mapper/AdminMapper.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 im.toduck.domain.admin.common.mapper; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import im.toduck.domain.admin.persistence.entity.Admin; | ||
| import im.toduck.domain.admin.presentation.dto.response.AdminListResponse; | ||
| import im.toduck.domain.admin.presentation.dto.response.AdminResponse; | ||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class AdminMapper { | ||
| public static AdminResponse toAdminResponse(final Admin admin) { | ||
| return new AdminResponse( | ||
| admin.getId(), | ||
| admin.getUser().getId(), | ||
| admin.getDisplayName() | ||
| ); | ||
| } | ||
|
|
||
| public static AdminListResponse toAdminListResponse(final List<AdminResponse> admins) { | ||
| return AdminListResponse.toListAdminResponse(admins); | ||
| } | ||
| } |
93 changes: 93 additions & 0 deletions
93
src/main/java/im/toduck/domain/admin/domain/service/AdminService.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,93 @@ | ||
| package im.toduck.domain.admin.domain.service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import im.toduck.domain.admin.common.mapper.AdminMapper; | ||
| import im.toduck.domain.admin.persistence.entity.Admin; | ||
| import im.toduck.domain.admin.persistence.repository.AdminRepository; | ||
| import im.toduck.domain.admin.presentation.dto.request.AdminCreateRequest; | ||
| import im.toduck.domain.admin.presentation.dto.request.AdminUpdateRequest; | ||
| import im.toduck.domain.admin.presentation.dto.response.AdminResponse; | ||
| import im.toduck.domain.user.persistence.entity.User; | ||
| import im.toduck.domain.user.persistence.entity.UserRole; | ||
| import im.toduck.domain.user.persistence.repository.UserRepository; | ||
| import im.toduck.global.exception.CommonException; | ||
| import im.toduck.global.exception.ExceptionCode; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class AdminService { | ||
| private final UserRepository userRepository; | ||
| private final AdminRepository adminRepository; | ||
|
|
||
| @Transactional | ||
| public Admin getAdmin(final Long userId) { | ||
| return adminRepository.findActiveAdminByUserId(userId) | ||
| .orElseThrow(() -> CommonException.from(ExceptionCode.NOT_FOUND_ADMIN)); | ||
| } | ||
|
|
||
| // Role은 Admin이지만 admin 테이블에 등록되어있지 않은 경우 사용합니다. | ||
| @Transactional | ||
| public Admin getAdminBySameUser(final Long userId) { | ||
| return adminRepository.findActiveAdminByUserId(userId) | ||
| .orElseGet(() -> createDefaultAdmin(userId)); | ||
| } | ||
|
|
||
| private Admin createDefaultAdmin(final Long userId) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> CommonException.from(ExceptionCode.NOT_FOUND_USER)); | ||
|
|
||
| if (user.getRole() != UserRole.ADMIN) { | ||
| throw CommonException.from(ExceptionCode.NOT_FOUND_ADMIN); | ||
| } | ||
|
|
||
| Admin admin = Admin.builder() | ||
| .user(user) | ||
| .displayName("토덕 관리자") | ||
| .build(); | ||
|
|
||
| return adminRepository.save(admin); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<AdminResponse> getAdmins() { | ||
| List<Admin> admins = adminRepository.findAllActiveAdmins(); | ||
| return admins.stream() | ||
| .map(AdminMapper::toAdminResponse) | ||
| .toList(); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public Optional<Admin> getExistingAdmin(final Long userId) { | ||
| return adminRepository.findByUserIdIncludeDeleted(userId); | ||
| } | ||
|
|
||
| @Transactional | ||
| public Admin createAdmin(final AdminCreateRequest request, final User user) { | ||
| Admin admin = Admin.builder() | ||
| .user(user) | ||
| .displayName(request.displayName()) | ||
| .build(); | ||
|
|
||
| return adminRepository.save(admin); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void updateAdmin(final Long userId, final AdminUpdateRequest request) { | ||
| Admin admin = adminRepository.findActiveAdminByUserId(userId) | ||
| .orElseThrow(() -> CommonException.from(ExceptionCode.NOT_FOUND_ADMIN)); | ||
| if (request.displayName() != null) { | ||
| admin.updateDisplayName(request.displayName()); | ||
| } | ||
| } | ||
|
wafla marked this conversation as resolved.
|
||
|
|
||
| @Transactional | ||
| public void deleteAdmin(final Admin admin) { | ||
| adminRepository.delete(admin); | ||
| } | ||
| } | ||
93 changes: 93 additions & 0 deletions
93
src/main/java/im/toduck/domain/admin/domain/usecase/AdminUseCase.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,93 @@ | ||
| package im.toduck.domain.admin.domain.usecase; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import im.toduck.domain.admin.common.mapper.AdminMapper; | ||
| import im.toduck.domain.admin.domain.service.AdminService; | ||
| import im.toduck.domain.admin.persistence.entity.Admin; | ||
| import im.toduck.domain.admin.presentation.dto.request.AdminCreateRequest; | ||
| import im.toduck.domain.admin.presentation.dto.request.AdminUpdateRequest; | ||
| import im.toduck.domain.admin.presentation.dto.response.AdminListResponse; | ||
| import im.toduck.domain.admin.presentation.dto.response.AdminResponse; | ||
| import im.toduck.domain.user.domain.service.UserService; | ||
| import im.toduck.domain.user.persistence.entity.User; | ||
| import im.toduck.domain.user.persistence.entity.UserRole; | ||
| import im.toduck.global.annotation.UseCase; | ||
| import im.toduck.global.exception.CommonException; | ||
| import im.toduck.global.exception.ExceptionCode; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @UseCase | ||
| @RequiredArgsConstructor | ||
| public class AdminUseCase { | ||
| private final AdminService adminService; | ||
| private final UserService userService; | ||
|
|
||
| @Transactional | ||
| public AdminResponse getAdmin(final Long userId) { | ||
| Admin admin = adminService.getAdmin(userId); | ||
|
|
||
| return AdminMapper.toAdminResponse(admin); | ||
| } | ||
|
|
||
| @Transactional | ||
| public AdminListResponse getAdmins() { | ||
| List<AdminResponse> admins = adminService.getAdmins(); | ||
|
|
||
| return AdminMapper.toAdminListResponse(admins); | ||
| } | ||
|
|
||
| @Transactional | ||
| public Admin createAdmin(final AdminCreateRequest request) { | ||
| User user = userService.getUserById(request.userId()) | ||
| .orElseThrow(() -> CommonException.from(ExceptionCode.NOT_FOUND_USER)); | ||
|
|
||
| Admin existingAdmin = adminService.getExistingAdmin(user.getId()).orElse(null); | ||
|
|
||
| // 이미 활성화된 관리자인 경우 | ||
| if (existingAdmin != null && existingAdmin.getDeletedAt() == null) { | ||
| throw CommonException.from(ExceptionCode.DUPLICATE_ADMIN); | ||
| } | ||
|
|
||
| // 삭제된 관리자 복구 | ||
| if (existingAdmin != null) { | ||
| existingAdmin.revive(); | ||
| existingAdmin.updateDisplayName(request.displayName()); | ||
|
|
||
| if (user.getRole() == UserRole.USER) { | ||
| user.promoteToAdmin(); | ||
| } | ||
|
|
||
| return existingAdmin; | ||
| } | ||
|
|
||
| // 신규 관리자 | ||
| Admin admin = adminService.createAdmin(request, user); | ||
|
|
||
| if (user.getRole() == UserRole.USER) { | ||
| user.promoteToAdmin(); | ||
| } | ||
|
|
||
| return admin; | ||
| } | ||
|
|
||
| @Transactional | ||
| public void updateAdmin(final Long userId, final AdminUpdateRequest request) { | ||
| User user = userService.getUserById(userId) | ||
| .orElseThrow(() -> CommonException.from(ExceptionCode.NOT_FOUND_USER)); | ||
|
|
||
| adminService.updateAdmin(userId, request); | ||
| } | ||
|
wafla marked this conversation as resolved.
|
||
|
|
||
| @Transactional | ||
| public void deleteAdmin(final Long userId) { | ||
| Admin admin = adminService.getAdmin(userId); | ||
|
|
||
| User user = admin.getUser(); | ||
| user.demoteToUser(); | ||
|
|
||
| adminService.deleteAdmin(admin); | ||
| } | ||
|
wafla marked this conversation as resolved.
|
||
| } | ||
51 changes: 51 additions & 0 deletions
51
src/main/java/im/toduck/domain/admin/persistence/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,51 @@ | ||
| package im.toduck.domain.admin.persistence.entity; | ||
|
|
||
| import org.hibernate.annotations.SQLDelete; | ||
|
|
||
| import im.toduck.domain.user.persistence.entity.User; | ||
| import im.toduck.global.base.entity.BaseEntity; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.OneToOne; | ||
| import jakarta.persistence.Table; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "admin") | ||
| @Getter | ||
| @NoArgsConstructor | ||
| @SQLDelete(sql = "UPDATE admin SET deleted_at = NOW() where id=?") | ||
| public class Admin extends BaseEntity { | ||
|
wafla marked this conversation as resolved.
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @OneToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "user_id", nullable = false, unique = true) | ||
| private User user; | ||
|
|
||
| @Column(length = 255, nullable = false) | ||
| private String displayName; | ||
|
|
||
| @Builder | ||
| private Admin(User user, | ||
| String displayName) { | ||
| this.user = user; | ||
| this.displayName = displayName; | ||
| } | ||
|
|
||
| public void updateDisplayName(final String displayName) { | ||
| this.displayName = displayName; | ||
| } | ||
|
|
||
| public void revive() { | ||
| this.deletedAt = null; | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/main/java/im/toduck/domain/admin/persistence/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 im.toduck.domain.admin.persistence.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import im.toduck.domain.admin.persistence.entity.Admin; | ||
| import im.toduck.domain.admin.persistence.repository.querydsl.AdminRepositoryCustom; | ||
|
|
||
| @Repository | ||
| public interface AdminRepository extends JpaRepository<Admin, Long>, AdminRepositoryCustom { | ||
| } |
14 changes: 14 additions & 0 deletions
14
...in/java/im/toduck/domain/admin/persistence/repository/querydsl/AdminRepositoryCustom.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,14 @@ | ||
| package im.toduck.domain.admin.persistence.repository.querydsl; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import im.toduck.domain.admin.persistence.entity.Admin; | ||
|
|
||
| public interface AdminRepositoryCustom { | ||
| Optional<Admin> findActiveAdminByUserId(Long userId); | ||
|
|
||
| List<Admin> findAllActiveAdmins(); | ||
|
|
||
| Optional<Admin> findByUserIdIncludeDeleted(Long userId); | ||
| } |
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.