Skip to content

Commit

Permalink
Merge pull request #22 from hyundai-fruitfruit/HEENDY-46-socket
Browse files Browse the repository at this point in the history
[HEENDY-‪46-socket] 이벤트 참여 API 및 소켓 연결 설정
  • Loading branch information
sangeun99 authored Feb 28, 2024
2 parents 9941cd0 + 17d006a commit 5d84939
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@
<artifactId>javase</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>${org.springframework-version}</version>
</dependency>
</dependencies>

<build>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/hyundai/app/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void configure(WebSecurity web) {
web.ignoring().antMatchers(
"/", "/resources/**",
"/v2/api-docs", "/swagger-resources/**", "/swagger-ui/index.html", "/swagger-ui.html","/webjars/**", "/swagger/**", // swagger
"/api/v1/auth/**", "/api/v1/fcm-push/**", "/api/v1/heendy-guide/**");
"/api/v1/auth/**", "/api/v1/admin/**", "/api/v1/fcm-push/**", "/api/v1/heendy-guide/**", "/websocket/**");
}

@Override
Expand All @@ -61,6 +61,7 @@ public void configure(HttpSecurity httpSecurity) throws Exception {
.and()
.authorizeRequests()
.antMatchers("/api/v1/auth/**").permitAll()
.antMatchers("/api/v1/admin/**").permitAll()
.antMatchers("/api/v1/fcm/**").permitAll()
.antMatchers("/api/v1/stores/**").authenticated()
.antMatchers("/api/v1/members/**").authenticated()
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/hyundai/app/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ protected Class<?>[] getServletConfigClasses() {
ServletContextConfig.class,
CorsConfig.class,
SecurityConfig.class,
SwaggerConfig.class
SwaggerConfig.class,
WebSocketConfig.class
};
}

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/hyundai/app/config/WebSocketConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.hyundai.app.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
* @author 엄상은
* @since 2024/02/27
* 웹소켓 설정
*/
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/websocket")
.setAllowedOrigins("*")
.withSockJS();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.hyundai.app.common.AdventureOfHeendyResponse;
import com.hyundai.app.event.dto.EventDetailResDto;
import com.hyundai.app.event.dto.EventListResDto;
import com.hyundai.app.event.dto.EventParticipateResDto;
import com.hyundai.app.event.dto.EventSaveReqDto;
import com.hyundai.app.event.dto.MemberEventDetailsResDto;
import com.hyundai.app.event.service.EventService;
Expand Down Expand Up @@ -66,12 +67,23 @@ public AdventureOfHeendyResponse<Void> delete(@PathVariable final int eventId) {
return AdventureOfHeendyResponse.success("이벤트를 삭제했습니다.", eventService.delete(storeId, eventId));
}

/**
* @author 엄상은
* @since 2024/02/27
* 어드민용 이벤트 참여 컨트롤러
*/
@PostMapping("{eventId}/participate")
@ApiOperation("어드민용 이벤트 참여 API")
public AdventureOfHeendyResponse<EventParticipateResDto> participateEvent(@PathVariable int eventId,
@RequestParam String memberId){
return AdventureOfHeendyResponse.success("이벤트 참여에 성공했습니다.", eventService.participateEvent(memberId, eventId));
}

/**
* @author 최성혁
* @since 2024/02/27
* 이벤트 참여자 회원 목록 조회
*/

@GetMapping("/{eventId}/participants")
@ApiOperation("어드민용 이벤트 참여자 상세정보 조회 API")
public AdventureOfHeendyResponse<List<MemberEventDetailsResDto>> findEventParticipants(@PathVariable final int eventId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.hyundai.app.event.controller;

import lombok.extern.log4j.Log4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
* @author 엄상은
* @since 2024/02/27
* 소켓 테스트용 컨트롤러
*/
@Log4j
@Controller
public class SocketController {
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public String getMessageAndSend(String message) {
log.debug("소켓으로부터 메세지 받음: " + message);
return "서버에서 소켓으로 메세지 날림" + message;
}
}

0 comments on commit 5d84939

Please sign in to comment.