Ylab-001: init commit for chat#1
Open
AphexSign wants to merge 2 commits into
Open
Conversation
Eugenekulik
reviewed
Apr 8, 2026
Comment on lines
+76
to
+83
| docker run -d -p 6379:6379 --name chat-redis redis:7-alpine | ||
| ``` | ||
| Запуск приложения | ||
| ``` | ||
| mvn clean spring-boot:run | ||
| ``` | ||
| Приложение будет доступно по адресу: http://localhost:8080 | ||
| H2 Console (для разработки): |
There was a problem hiding this comment.
лучше было написать dockerfile и добавить в docker compose чтобы запускалось без проблем вне зависимости от окружения.
Eugenekulik
reviewed
Apr 10, 2026
Comment on lines
+13
to
+25
| public class RedisConstants { | ||
|
|
||
| /** | ||
| * Redis stream key for the dead-letter queue. | ||
| */ | ||
| public static final String DEAD_LETTER_STREAM_KEY = "chat:dead-letter:stream"; | ||
|
|
||
| /** | ||
| * Consumer group name for the dead-letter queue stream. | ||
| */ | ||
| public static final String DEAD_LETTER_CONSUMER_GROUP = "chat-dlq-group"; | ||
|
|
||
| } No newline at end of file |
Eugenekulik
reviewed
Apr 10, 2026
Comment on lines
+38
to
+55
|
|
||
| if (authHeader != null && authHeader.startsWith("Bearer ")) { | ||
| String token = authHeader.substring(7); | ||
| try { | ||
| String username = jwtUtil.extractUsername(token); | ||
| if (username != null | ||
| && SecurityContextHolder.getContext().getAuthentication() == null) { | ||
| if (jwtUtil.validateToken(token, username)) { | ||
| UsernamePasswordAuthenticationToken authToken = | ||
| new UsernamePasswordAuthenticationToken(username, null, | ||
| new ArrayList<>()); | ||
| SecurityContextHolder.getContext().setAuthentication(authToken); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| } | ||
| } | ||
| filterChain.doFilter(request, response); |
There was a problem hiding this comment.
можно вынести в приватный метод и сделать инверсию условий, будет более читаемо
Eugenekulik
reviewed
Apr 10, 2026
There was a problem hiding this comment.
большая вложенность условий, попробую отрефакторить
Eugenekulik
reviewed
Apr 10, 2026
Comment on lines
+57
to
+74
| @Around("@annotation(io.ylab.chat.aop.annotation.WithUserContext)") | ||
| public Object withUserContext(ProceedingJoinPoint jp) throws Throwable { | ||
| Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
| if (auth == null || !auth.isAuthenticated() || "anonymousUser".equals( | ||
| auth.getPrincipal())) { | ||
| throw new UnauthorizedException("User not authenticated"); | ||
| } | ||
|
|
||
| String username = auth.getName(); | ||
| UserContext.setUserInfo(UserInfo.builder().username(username).build()); | ||
|
|
||
| try { | ||
| return jp.proceed(); | ||
| } finally { | ||
| UserContext.clear(); | ||
| log.debug("User context cleared for {}", username); | ||
| } | ||
| } |
There was a problem hiding this comment.
можно было сделать на основе scope websocket и заполнять в фильтре или интерсепторе
Eugenekulik
reviewed
Apr 10, 2026
| refill-duration-seconds: 60 | ||
|
|
||
| jwt: | ||
| secret: FITSy9dGK9BlOOrOqOi3xRaWjMPgR9KQtT0GaPiBaKQ7LcYniHsdsSA78iEy8BmOGAXpkVi7Imp9dZeHfJPptA== |
There was a problem hiding this comment.
в .env лучше выносить, даже если это учебный проект (взять за практику)
Eugenekulik
reviewed
Apr 10, 2026
| jpa: | ||
| database-platform: org.hibernate.dialect.H2Dialect | ||
| hibernate: | ||
| ddl-auto: create-drop |
Eugenekulik
reviewed
Apr 10, 2026
Comment on lines
+75
to
+87
| void withUserContext_authenticated_setsContextAndProceeds() throws Throwable { | ||
| Authentication auth = mock(Authentication.class); | ||
| when(auth.isAuthenticated()).thenReturn(true); | ||
| when(auth.getPrincipal()).thenReturn(TEST_USER); | ||
| when(auth.getName()).thenReturn(TEST_USER); | ||
| SecurityContextHolder.getContext().setAuthentication(auth); | ||
|
|
||
| when(joinPoint.proceed()).thenReturn(EXPECTED_METHOD_RESULT); | ||
|
|
||
| Object result = aspect.withUserContext(joinPoint); | ||
|
|
||
| verify(joinPoint).proceed(); | ||
| softly.assertThat(result).isEqualTo(EXPECTED_METHOD_RESULT); |
There was a problem hiding this comment.
тесты разделяй на блоки, самому потом проще будет читать их (например //GIVEN//WHEN//THEN)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.