7
7
import cmf .commitField .global .error .ErrorCode ;
8
8
import cmf .commitField .global .exception .CustomException ;
9
9
import cmf .commitField .global .globalDto .GlobalResponse ;
10
- import cmf .commitField .global .websocket .NotiWebSocketHandler ;
11
10
import lombok .RequiredArgsConstructor ;
12
11
import lombok .extern .slf4j .Slf4j ;
12
+ import org .springframework .context .ApplicationEventPublisher ;
13
13
import org .springframework .security .core .Authentication ;
14
+ import org .springframework .security .core .annotation .AuthenticationPrincipal ;
14
15
import org .springframework .security .core .context .SecurityContextHolder ;
15
16
import org .springframework .security .oauth2 .client .authentication .OAuth2AuthenticationToken ;
16
17
import org .springframework .security .oauth2 .core .user .OAuth2User ;
@@ -30,24 +31,14 @@ public class ApiV1NotiController {
30
31
private final NotiService notiService ;
31
32
private final UserRepository userRepository ;
32
33
private final NotiWebSocketHandler notiWebSocketHandler ;
34
+ private final ApplicationEventPublisher eventPublisher ;
33
35
34
36
@ GetMapping ("" )
35
- public GlobalResponse <List <NotiDto >> getNoti () {
36
- Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
37
-
38
- if (authentication instanceof OAuth2AuthenticationToken ) {
39
- OAuth2User principal = (OAuth2User ) authentication .getPrincipal ();
40
- Map <String , Object > attributes = principal .getAttributes ();
41
- String username = (String ) attributes .get ("login" ); // GitHub ID
42
- User user = userRepository .findByUsername (username ).orElseThrow (() -> new CustomException (ErrorCode .NOT_FOUND_USER ));
43
- List <NotiDto > notis = notiService .getNotReadNoti (user );
44
- // ์น์์ผ์ผ๋ก ์๋ฆผ ์ ์ก
45
- notiWebSocketHandler .sendNotification (user , notis );
46
-
47
- return GlobalResponse .success (notis );
48
- }
49
-
50
- return GlobalResponse .error (ErrorCode .LOGIN_REQUIRED );
37
+ public GlobalResponse <List <NotiDto >> getNoti (@ AuthenticationPrincipal OAuth2User oAuth2User ) {
38
+ String username = oAuth2User .getName ();
39
+ User user = userRepository .findByUsername (username ).orElseThrow (() -> new CustomException (ErrorCode .NOT_FOUND_USER ));
40
+ List <NotiDto > notis = notiService .getNotReadNoti (user );
41
+ return GlobalResponse .success (notis );
51
42
}
52
43
53
44
@ PostMapping ("" )
0 commit comments