-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: 도메인 관련 문제 수정 - Group 엔티티 명을 Role 로 변경 - ManyToOne Fetch Type 을 Lazy로 설정 - Member 엔티티 오타 수정 * feat: 기본 Repository 정의 * feat: Controller 및 Service 기본 로직 구현 * feat: Response dto 정의 --------- Co-authored-by: Kyunghun Kim <[email protected]>
- Loading branch information
1 parent
cc718db
commit a702524
Showing
14 changed files
with
270 additions
and
25 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
api/api-member/src/main/java/com/pgms/apimember/controller/AdminController.java
This file contains 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,42 @@ | ||
package com.pgms.apimember.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.pgms.apimember.dto.response.AdminGetResponse; | ||
import com.pgms.apimember.service.AdminService; | ||
import com.pgms.coredomain.response.ApiResponse; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/admin") | ||
@RequiredArgsConstructor | ||
public class AdminController { | ||
|
||
private static final Long TEMP_CURRENT_ID = 1L; | ||
|
||
private final AdminService adminService; | ||
|
||
@GetMapping("/members") | ||
public ResponseEntity<ApiResponse<?>> getMembers(@RequestParam(required = false) List<Long> memberIds) { | ||
return ResponseEntity.ok(ApiResponse.ok(adminService.getMembers(memberIds))); | ||
} | ||
|
||
@GetMapping("/me") | ||
public ResponseEntity<ApiResponse<AdminGetResponse>> getMyInfo() { | ||
return ResponseEntity.ok(ApiResponse.ok(adminService.getAdmin(TEMP_CURRENT_ID))); | ||
} | ||
|
||
@DeleteMapping("/me") | ||
public ResponseEntity<ApiResponse<Void>> deleteMyAccount() { | ||
adminService.deleteAdmin(TEMP_CURRENT_ID); | ||
return ResponseEntity.ok(ApiResponse.ok(null)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
api/api-member/src/main/java/com/pgms/apimember/dto/response/AdminGetResponse.java
This file contains 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.pgms.apimember.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.pgms.coredomain.domain.member.Admin; | ||
import com.pgms.coredomain.domain.member.Role; | ||
import com.pgms.coredomain.domain.member.enums.AccountStatus; | ||
|
||
public record AdminGetResponse( | ||
Long id, | ||
String name, | ||
String phoneNumber, | ||
String email, | ||
AccountStatus status, | ||
LocalDateTime lastLoginAt, | ||
LocalDateTime lastPasswordUpdatedAt, | ||
LocalDateTime createdAt, | ||
LocalDateTime updatedAt, | ||
Role role | ||
) { | ||
public static AdminGetResponse toDto(Admin admin) { | ||
return new AdminGetResponse( | ||
admin.getId(), | ||
admin.getName(), | ||
admin.getPhoneNumber(), | ||
admin.getEmail(), | ||
admin.getStatus(), | ||
admin.getLastLoginAt(), | ||
admin.getLastPasswordUpdatedAt(), | ||
admin.getCreatedAt(), | ||
admin.getUpdatedAt(), | ||
admin.getRole() | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
api/api-member/src/main/java/com/pgms/apimember/dto/response/MemberDetailGetResponse.java
This file contains 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,49 @@ | ||
package com.pgms.apimember.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.pgms.coredomain.domain.member.Member; | ||
import com.pgms.coredomain.domain.member.Role; | ||
import com.pgms.coredomain.domain.member.enums.AccountStatus; | ||
import com.pgms.coredomain.domain.member.enums.Gender; | ||
import com.pgms.coredomain.domain.member.enums.Provider; | ||
|
||
public record MemberDetailGetResponse( | ||
Long id, | ||
String name, | ||
String phoneNumber, | ||
String email, | ||
String birthDate, | ||
Gender gender, | ||
String streetAddress, | ||
String detailAddress, | ||
String zipCode, | ||
AccountStatus status, | ||
Provider provider, | ||
LocalDateTime lastLoginAt, | ||
LocalDateTime lastPasswordUpdatedAt, | ||
LocalDateTime createdAt, | ||
LocalDateTime updatedAt, | ||
Role role | ||
) { | ||
public static MemberDetailGetResponse toDto(Member member) { | ||
return new MemberDetailGetResponse( | ||
member.getId(), | ||
member.getName(), | ||
member.getPhoneNumber(), | ||
member.getEmail(), | ||
member.getBirthDate(), | ||
member.getGender(), | ||
member.getStreetAddress(), | ||
member.getDetailAddress(), | ||
member.getZipCode(), | ||
member.getStatus(), | ||
member.getProvider(), | ||
member.getLastLoginAt(), | ||
member.getLastPasswordUpdatedAt(), | ||
member.getCreatedAt(), | ||
member.getUpdatedAt(), | ||
member.getRole() | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
api/api-member/src/main/java/com/pgms/apimember/dto/response/MemberSummaryGetResponse.java
This file contains 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,19 @@ | ||
package com.pgms.apimember.dto.response; | ||
|
||
import com.pgms.coredomain.domain.member.Member; | ||
|
||
public record MemberSummaryGetResponse( | ||
Long id, | ||
String name, | ||
String phoneNumber, | ||
String email | ||
) { | ||
public static MemberSummaryGetResponse toDto(Member member) { | ||
return new MemberSummaryGetResponse( | ||
member.getId(), | ||
member.getName(), | ||
member.getPhoneNumber(), | ||
member.getEmail() | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
api/api-member/src/main/java/com/pgms/apimember/service/AdminService.java
This file contains 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,53 @@ | ||
package com.pgms.apimember.service; | ||
|
||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.pgms.apimember.dto.response.AdminGetResponse; | ||
import com.pgms.apimember.dto.response.MemberDetailGetResponse; | ||
import com.pgms.apimember.dto.response.MemberSummaryGetResponse; | ||
import com.pgms.coredomain.domain.member.Admin; | ||
import com.pgms.coredomain.domain.member.repository.AdminRepository; | ||
import com.pgms.coredomain.domain.member.repository.MemberRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class AdminService { | ||
|
||
private final AdminRepository adminRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public Object getMembers(List<Long> memberIds) { | ||
if (memberIds == null || memberIds.isEmpty()) { | ||
return memberRepository.findAll().stream().map(MemberSummaryGetResponse::toDto).toList(); | ||
} else { | ||
return memberRepository.findAllById(memberIds).stream().map(MemberDetailGetResponse::toDto).toList(); | ||
} | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public AdminGetResponse getAdmin(Long adminId) { | ||
return AdminGetResponse.toDto(getAvailableAdmin(adminId)); | ||
} | ||
|
||
public void deleteAdmin(Long adminId) { | ||
final Admin admin = getAvailableAdmin(adminId); | ||
admin.updateToDeleted(); | ||
} | ||
|
||
private Admin getAvailableAdmin(Long adminId) { | ||
final Admin admin = adminRepository.findById(adminId) | ||
.orElseThrow(() -> new NoSuchElementException("Admin not found")); | ||
if (admin.isDeleted()) { | ||
throw new IllegalArgumentException("Admin is already deleted"); | ||
} | ||
return admin; | ||
} | ||
} |
This file contains 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 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 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 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
8 changes: 8 additions & 0 deletions
8
...re-domain/src/main/java/com/pgms/coredomain/domain/member/repository/AdminRepository.java
This file contains 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,8 @@ | ||
package com.pgms.coredomain.domain.member.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.pgms.coredomain.domain.member.Admin; | ||
|
||
public interface AdminRepository extends JpaRepository<Admin, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
...e-domain/src/main/java/com/pgms/coredomain/domain/member/repository/MemberRepository.java
This file contains 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,8 @@ | ||
package com.pgms.coredomain.domain.member.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.pgms.coredomain.domain.member.Member; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
...main/src/main/java/com/pgms/coredomain/domain/member/repository/PermissionRepository.java
This file contains 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,8 @@ | ||
package com.pgms.coredomain.domain.member.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.pgms.coredomain.domain.member.Permission; | ||
|
||
public interface PermissionRepository extends JpaRepository<Permission, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
.../src/main/java/com/pgms/coredomain/domain/member/repository/RolePermissionRepository.java
This file contains 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,8 @@ | ||
package com.pgms.coredomain.domain.member.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.pgms.coredomain.domain.member.RolePermission; | ||
|
||
public interface RolePermissionRepository extends JpaRepository<RolePermission, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
...ore-domain/src/main/java/com/pgms/coredomain/domain/member/repository/RoleRepository.java
This file contains 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,8 @@ | ||
package com.pgms.coredomain.domain.member.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.pgms.coredomain.domain.member.Role; | ||
|
||
public interface RoleRepository extends JpaRepository<Role, Long> { | ||
} |