diff --git a/src/main/java/com/ecolink/core/auth/token/UserPrincipal.java b/src/main/java/com/ecolink/core/auth/token/UserPrincipal.java index a7e2913b..3200a547 100644 --- a/src/main/java/com/ecolink/core/auth/token/UserPrincipal.java +++ b/src/main/java/com/ecolink/core/auth/token/UserPrincipal.java @@ -41,6 +41,7 @@ public class UserPrincipal implements Serializable { private final Set authorities; // Manager + private final Long managerId; private final List managingStores; public static UserPrincipal of(User user, Avatar avatar, Set authoritySet, @@ -60,6 +61,7 @@ public static UserPrincipal of(User user, Avatar avatar, Set applyManger( return ApiResponse.ok(); } + @Tag(name = "${swagger.tag.my-page}") + @Operation(summary = "관리 매장 조회 API - 인증 필요", + description = "관리 매장 조회 API - 인증 필요", + security = {@SecurityRequirement(name = "session-token")}) + @PreAuthorize("hasRole('MANAGER')") + @GetMapping("/stores") + public ApiResponse> getManagingStores( + @AuthenticationPrincipal UserPrincipal principal) { + return ApiResponse.ok(managerService.getManagingStores(principal.getManagerId())); + } + } diff --git a/src/main/java/com/ecolink/core/manager/repository/ManagerRepository.java b/src/main/java/com/ecolink/core/manager/repository/ManagerRepository.java index 97540f7a..c4afd5d8 100644 --- a/src/main/java/com/ecolink/core/manager/repository/ManagerRepository.java +++ b/src/main/java/com/ecolink/core/manager/repository/ManagerRepository.java @@ -1,5 +1,6 @@ package com.ecolink.core.manager.repository; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,19 +9,27 @@ import com.ecolink.core.manager.constant.ManagerStatus; import com.ecolink.core.manager.domain.Manager; +import com.ecolink.core.store.domain.Store; import com.ecolink.core.user.domain.User; public interface ManagerRepository extends JpaRepository { @Query("select m from Manager m " - + "join fetch m.storeRegistrations sr " - + "join fetch sr.store " - + "where m.user = :user") + + "left join fetch m.storeRegistrations sr " + + "left join fetch sr.store " + + "where m.user = :user") Optional findByUser(@Param("user") User user); @Query("select (count(m) > 0) from Manager m " - + "where m.user.id = :id " - + "and m.status = :status ") - boolean existsByUserAndStatus(@Param("id") Long id,@Param("status") ManagerStatus status); + + "where m.user.id = :id " + + "and m.status = :status ") + boolean existsByUserAndStatus(@Param("id") Long id, @Param("status") ManagerStatus status); + + @Query("select s from Manager m " + + "left join m.storeRegistrations sr " + + "on sr.status = com.ecolink.core.manager.constant.RegistrationStatus.ACTIVE " + + "left join sr.store s " + + "where m.id = :managerId") + List findStoresByManager(@Param("managerId") Long id); } diff --git a/src/main/java/com/ecolink/core/manager/service/ManagerService.java b/src/main/java/com/ecolink/core/manager/service/ManagerService.java index c09b8316..fa761ef9 100644 --- a/src/main/java/com/ecolink/core/manager/service/ManagerService.java +++ b/src/main/java/com/ecolink/core/manager/service/ManagerService.java @@ -1,9 +1,12 @@ package com.ecolink.core.manager.service; +import java.util.List; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.ecolink.core.auth.token.UserPrincipal; +import com.ecolink.core.bookmark.dto.response.StoreInfoDto; import com.ecolink.core.common.error.ErrorCode; import com.ecolink.core.common.error.exception.EntityNotFoundException; import com.ecolink.core.common.error.exception.ManagerApplicationException; @@ -36,7 +39,7 @@ public Long applyManager(ManagerApplicationRequest request, UserPrincipal princi } /** - * 대표 등록 신청 진행중인 지 여부 확인하는 메서드 + * 대표 등록 신청 진행중인지 여부 확인하는 메서드 */ public boolean checkIfPending(Long userId) { return managerRepository.existsByUserAndStatus(userId, ManagerStatus.PENDING); @@ -47,4 +50,9 @@ public Manager getByUser(User user) { .orElseThrow(() -> new EntityNotFoundException(ErrorCode.MANAGER_NOT_FOUND)); } + @Transactional + public List getManagingStores(Long managerId) { + return managerRepository.findStoresByManager(managerId).stream().map(StoreInfoDto::of).toList(); + } + }