Skip to content

Commit

Permalink
refactor: 핸들러 메서드 함수형 인터페이스 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
yoondgu committed Sep 4, 2023
1 parent cb5bdfe commit 5b9f66b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import nextstep.jwp.controller.UserController;
import org.apache.coyote.http11.common.HandlerMapping;
import org.apache.coyote.http11.common.HandlerMethod;
import org.apache.coyote.http11.request.Request;
import org.apache.coyote.http11.response.Response;

public class HandlerAdaptor {

private static final Map<HandlerMapping, Function<Request, Response>> handlerMethods = new HashMap<>(
private static final Map<HandlerMapping, HandlerMethod> handlerMethods = new HashMap<>(
Map.of(
new HandlerMapping(POST, "/login"), UserController::login,
new HandlerMapping(POST, "/register"), UserController::register
Expand All @@ -23,12 +23,12 @@ public class HandlerAdaptor {
public Response getMapping(Request request) {
/// TODO: 2023/09/04 매핑되는 메서드가 없을 때 예외처리
return handlerMethods.get(new HandlerMapping(GET, request.getPath()))
.apply(request);
.handle(request);
}

public Response postMapping(Request request) {
/// TODO: 2023/09/04 매핑되는 메서드가 없을 때 예외처리
return handlerMethods.get(new HandlerMapping(POST, request.getPath()))
.apply(request);
.handle(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.apache.coyote.http11.common;

import org.apache.coyote.http11.request.Request;
import org.apache.coyote.http11.response.Response;

public interface HandlerMethod {

Response handle(Request request);

}

0 comments on commit 5b9f66b

Please sign in to comment.