Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public AlertListResponse getMyAlerts(Long userId){
.orElseThrow(()-> LinkuException.of(ResponseCode.USER_NOT_FOUND));

// 1) 구독 정보 조회
List<Subscribe> subscribes = subscribeRepository.findByUser_UserId(userId);
List<Subscribe> subscribes = subscribeRepository.findByUser_UserIdOrderByDepartmentConfig_IdAsc(userId);

// 2) 구독한 departmentConfigId 리스트 뽑기
List<Long> departmentConfigIds = subscribes.stream()
Expand All @@ -69,7 +69,7 @@ public AlertListResponse getMyAlertsWithDepartments(Long userId, List<String> de
.orElseThrow(() -> LinkuException.of(ResponseCode.USER_NOT_FOUND));

// 1) 내 구독 DepartmentConfig ID들
List<Long> subscribedIds = subscribeRepository.findByUser_UserId(userId).stream()
List<Long> subscribedIds = subscribeRepository.findByUser_UserIdOrderByDepartmentConfig_IdAsc(userId).stream()
.map(s -> s.getDepartmentConfig().getId())
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.linku.backend.global.response.ResponseCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -28,7 +29,7 @@ public class DepartmentConfigService {

@Transactional(readOnly = true)
public DepartmentConfigListResponse getAllDepartmentConfigs() {
List<DepartmentConfig> departmentConfigList = departmentConfigRepository.findAll();
List<DepartmentConfig> departmentConfigList = departmentConfigRepository.findAll(Sort.by(Sort.Direction.ASC, "id"));

List<DepartmentConfigResponse> list = departmentConfigList.stream()
.map(department -> DepartmentConfigResponse.of(department.getId(), department.getName()))
Expand All @@ -41,7 +42,7 @@ public DepartmentConfigListResponse getAllMyDepartmentConfigs(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(()-> LinkuException.of(ResponseCode.USER_NOT_FOUND));

List<Subscribe> subscribeList = subscribeRepository.findByUser_UserId(userId);
List<Subscribe> subscribeList = subscribeRepository.findByUser_UserIdOrderByDepartmentConfig_IdAsc(userId);

List<DepartmentConfigResponse> list = subscribeList.stream()
.map(subscribe -> DepartmentConfigResponse.of(subscribe.getDepartmentConfig().getId(), subscribe.getDepartmentConfig().getName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public interface SubscribeRepository extends JpaRepository<Subscribe, Long> {
List<Subscribe> findByUser_UserId(Long userId);
List<Subscribe> findByUser_UserIdOrderByDepartmentConfig_IdAsc(Long userId);
void deleteByUser_UserIdAndDepartmentConfig_Id(Long userId, Long departmentConfigId);
boolean existsByUser_UserIdAndDepartmentConfig_Id(Long userId, Long configId);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.linku.backend.global.resolver;

import com.linku.backend.global.auth.AuthUser;
import com.linku.backend.global.exception.LinkuException;
import org.springframework.core.MethodParameter;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import com.linku.backend.global.response.ResponseCode;

import java.nio.file.attribute.UserPrincipal;

@Component
public class CurrentUserIdArgumentResolver implements HandlerMethodArgumentResolver {
Expand All @@ -23,7 +28,13 @@ public Object resolveArgument(MethodParameter parameter,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {

AuthUser principal = (AuthUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

if (authentication == null || !authentication.isAuthenticated()) {
throw LinkuException.of(ResponseCode.GOOGLE_INVALID_USER_INFO_RESPONSE);
}

AuthUser principal = (AuthUser) authentication.getPrincipal();
return principal.getId();
}
}
Loading
Loading