Skip to content

Commit fcd365d

Browse files
authored
Merge pull request #88 from sgdevcamp2025/be/faet/84-direct
[BE] feat: Direct create API
2 parents bc17a25 + 935d7ee commit fcd365d

35 files changed

+520
-32
lines changed

src/backend/chat-server/src/main/kotlin/com/asyncgate/chat_server/config/WebSocketConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.asyncgate.chat_server.config
22

33
import com.asyncgate.chat_server.filter.FilterChannelInterceptor
4-
import com.asyncgate.chat_server.filter.JwtHandshakeInterceptor
4+
import com.asyncgate.chat_server.filter.WebSocketHandshakeInterceptor
55
import org.springframework.context.annotation.Configuration
66
import org.springframework.messaging.simp.config.ChannelRegistration
77
import org.springframework.messaging.simp.config.MessageBrokerRegistry
@@ -13,13 +13,13 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerCo
1313
@EnableWebSocketMessageBroker
1414
class WebSocketConfig(
1515
private val filterChannelInterceptor: FilterChannelInterceptor,
16-
private val jwtHandshakeInterceptor: JwtHandshakeInterceptor,
16+
private val webSocketHandshakeInterceptor: WebSocketHandshakeInterceptor,
1717
) : WebSocketMessageBrokerConfigurer {
1818

1919
override fun registerStompEndpoints(registry: StompEndpointRegistry) {
2020
registry.addEndpoint("/asyncgate-chat")
2121
.setAllowedOriginPatterns("*")
22-
.addInterceptors(jwtHandshakeInterceptor)
22+
.addInterceptors(webSocketHandshakeInterceptor)
2323
}
2424

2525
override fun configureMessageBroker(registry: MessageBrokerRegistry) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.asyncgate.chat_server.controller
2+
3+
import org.springframework.web.bind.annotation.GetMapping
4+
import org.springframework.web.bind.annotation.RequestMapping
5+
import org.springframework.web.bind.annotation.RestController
6+
7+
@RestController
8+
@RequestMapping("/health")
9+
class HealthCheckController {
10+
11+
@GetMapping
12+
fun healthCheck(): Map<String, String> {
13+
return mapOf("status" to "UP")
14+
}
15+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.asyncgate.chat_server.exception
2+
3+
import com.asyncgate.chat_server.support.response.FailResponse
4+
import org.slf4j.Logger
5+
import org.slf4j.LoggerFactory
6+
import org.springframework.http.ResponseEntity
7+
import org.springframework.web.bind.annotation.ControllerAdvice
8+
import org.springframework.web.bind.annotation.ExceptionHandler
9+
import org.springframework.web.servlet.resource.NoResourceFoundException
10+
11+
@ControllerAdvice
12+
class ChatServerErrorHandler {
13+
private val log: Logger = LoggerFactory.getLogger(ChatServerErrorHandler::class.java)
14+
15+
@ExceptionHandler(ChatServerException::class)
16+
fun handleApiException(e: ChatServerException): ResponseEntity<FailResponse> {
17+
val errorType: FailType = e.failType
18+
val response: FailResponse = FailResponse.of(
19+
errorType.errorCode,
20+
errorType.message,
21+
errorType.status.value()
22+
)
23+
return ResponseEntity.status(errorType.status).body(response)
24+
}
25+
26+
@ExceptionHandler(Exception::class)
27+
fun handleException(exception: Exception) {
28+
log.error("🚨 [Global Error] ${exception.message}", exception)
29+
}
30+
31+
@ExceptionHandler(NoResourceFoundException::class)
32+
fun handleResourceException(exception: NoResourceFoundException) {
33+
}
34+
}

src/backend/chat-server/src/main/kotlin/com/asyncgate/chat_server/exception/WebSocketErrorHandler.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/backend/chat-server/src/main/kotlin/com/asyncgate/chat_server/filter/FilterChannelInterceptor.kt renamed to src/backend/chat-server/src/main/kotlin/com/asyncgate/chat_server/filter/StompInterceptor.kt

File renamed without changes.

src/backend/chat-server/src/main/kotlin/com/asyncgate/chat_server/filter/JwtHandshakeInterceptor.kt renamed to src/backend/chat-server/src/main/kotlin/com/asyncgate/chat_server/filter/WebSocketHandshakeInterceptor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import org.springframework.web.socket.WebSocketHandler
1010
import org.springframework.web.socket.server.HandshakeInterceptor
1111

1212
@Component
13-
class JwtHandshakeInterceptor(
13+
class WebSocketHandshakeInterceptor(
1414
private val jwtTokenProvider: JwtTokenProvider,
1515
) : HandshakeInterceptor {
1616

1717
companion object {
18-
private val log: Logger = LoggerFactory.getLogger(JwtHandshakeInterceptor::class.java)
18+
private val log: Logger = LoggerFactory.getLogger(WebSocketHandshakeInterceptor::class.java)
1919
}
2020

2121
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.asyncgate.guild_server.client;
2+
3+
import com.asyncgate.guild_server.support.response.SuccessResponse;
4+
import org.springframework.cloud.openfeign.FeignClient;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
8+
import java.util.List;
9+
10+
@FeignClient(name = "user-server")
11+
public interface UserClient {
12+
13+
@GetMapping("/users")
14+
SuccessResponse<UserClientInfoResponses> getUsersInfo(@RequestParam(required = false) List<String> memberIds);
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.asyncgate.guild_server.client;
2+
3+
import java.util.List;
4+
5+
public record UserClientInfoResponses(List<UserClientInfoResponse> responses) {
6+
public record UserClientInfoResponse(String userId, String name, String nickname, String profileImageUrl) {
7+
}
8+
}

src/backend/guild-server/src/main/java/com/asyncgate/guild_server/config/FeignClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.context.annotation.Configuration;
77

88
@Configuration
9-
@EnableFeignClients
9+
@EnableFeignClients(basePackages = "com.asyncgate.guild_server.client")
1010
public class FeignClientConfig {
1111

1212
@Bean
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.asyncgate.guild_server.controller;
2+
3+
import com.asyncgate.guild_server.dto.request.DirectChannelCreateRequest;
4+
import com.asyncgate.guild_server.dto.response.DirectResponse;
5+
import com.asyncgate.guild_server.service.DirectService;
6+
import com.asyncgate.guild_server.support.response.SuccessResponse;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
9+
import org.springframework.web.bind.annotation.PostMapping;
10+
import org.springframework.web.bind.annotation.RequestBody;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
@RestController
15+
@RequiredArgsConstructor
16+
@RequestMapping("/direct")
17+
public class DirectController {
18+
19+
private final DirectService directService;
20+
21+
@PostMapping
22+
public SuccessResponse<DirectResponse> create(
23+
final @AuthenticationPrincipal String currentUserId,
24+
final @RequestBody DirectChannelCreateRequest request
25+
) {
26+
return SuccessResponse.created(
27+
directService.create(currentUserId, request)
28+
);
29+
}
30+
}

0 commit comments

Comments
 (0)