Skip to content

Commit

Permalink
Merge pull request #239 from ASAP-as-soon-as-possible/feat/#238
Browse files Browse the repository at this point in the history
#238 [refactor] 회의 ID 디코딩 로직 리팩토링
  • Loading branch information
KWY0218 authored Nov 19, 2023
2 parents d0cd049 + e523176 commit da46b0f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 51 deletions.
7 changes: 3 additions & 4 deletions src/main/java/com/asap/server/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.asap.server.config;

import com.asap.server.config.resolver.meeting.MeetingPathResolver;
import com.asap.server.config.resolver.meeting.MeetingPathVariableResolver;
import com.asap.server.config.resolver.user.UserIdResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
Expand All @@ -17,7 +17,7 @@
@Configuration
public class WebConfig implements WebMvcConfigurer {
private final UserIdResolver userIdResolver;
private final MeetingPathResolver meetingPathResolver;
private final MeetingPathVariableResolver meetingPathVariableResolver;

@Bean
public PasswordEncoder getPasswordEncoder() {
Expand All @@ -35,7 +35,6 @@ public void addCorsMappings(CorsRegistry registry) {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(userIdResolver);
resolvers.add(meetingPathResolver);

resolvers.add(meetingPathVariableResolver);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.asap.server.config.resolver.meeting;

import org.springframework.core.annotation.AliasFor;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -10,12 +8,4 @@
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface MeetingPathVariable {

@AliasFor("name")
String value() default "";

@AliasFor("value")
String name() default "";

boolean required() default true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.asap.server.config.resolver.meeting;

import com.asap.server.common.utils.SecureUrlUtil;
import com.asap.server.exception.model.BadRequestException;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
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 org.springframework.web.servlet.HandlerMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

import static com.asap.server.exception.Error.INVALID_MEETING_URL_EXCEPTION;

@Component
@RequiredArgsConstructor
public class MeetingPathVariableResolver implements HandlerMethodArgumentResolver {
private static final String MEETING_PATH_VARIABLE = "meetingId";
private final SecureUrlUtil secureUrlUtil;

@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.hasParameterAnnotation(MeetingPathVariable.class);
}

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
final HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
final Map<String, String> pathVariables = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

final String meetingId = pathVariables.get(MEETING_PATH_VARIABLE);
try {
return secureUrlUtil.decodeUrl(meetingId);
} catch (NumberFormatException e) {
throw new BadRequestException(INVALID_MEETING_URL_EXCEPTION);
}
}
}

0 comments on commit da46b0f

Please sign in to comment.