-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
톰캣 구현 1단계 주드 미션 제출합니다 #326
Changes from 9 commits
e5ccf98
4772fa8
350b66b
d597dc8
937b2a2
296eb41
77d5eff
2339099
ee9370d
09921ea
96340a1
a0f8f41
d913b0f
6567d96
5f5c43d
7e17d6d
42c100f
a7f459c
4f3e737
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
package nextstep.jwp.db; | ||
|
||
import nextstep.jwp.model.User; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import nextstep.jwp.model.User; | ||
|
||
public class InMemoryUserRepository { | ||
|
||
private static final Map<String, User> database = new ConcurrentHashMap<>(); | ||
private static final AtomicLong sequence = new AtomicLong(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 동시성까지 꼼꼼하게 챙겨주셨네요 👍 |
||
|
||
static { | ||
final User user = new User(1L, "gugu", "password", "[email protected]"); | ||
database.put(user.getAccount(), user); | ||
} | ||
|
||
public static void save(User user) { | ||
database.put(user.getAccount(), user); | ||
database.put( | ||
user.getAccount(), | ||
new User(sequence.incrementAndGet(), user.getAccount(), user.getPassword(), user.getEmail()) | ||
); | ||
} | ||
|
||
public static Optional<User> findByAccount(String account) { | ||
return Optional.ofNullable(database.get(account)); | ||
} | ||
|
||
private InMemoryUserRepository() {} | ||
private InMemoryUserRepository() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package nextstep.jwp.presentation; | ||
|
||
import java.io.IOException; | ||
import org.apache.coyote.http11.request.RequestReader; | ||
import org.apache.coyote.http11.response.Response; | ||
|
||
public interface Controller { | ||
|
||
Response service(RequestReader requestReader) throws IOException; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||
package nextstep.jwp.presentation; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import java.util.HashMap; | ||||||||||||||||||||||||||||||
import java.util.Map; | ||||||||||||||||||||||||||||||
import org.apache.coyote.http11.request.RequestReader; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
public class FrontController { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
private static final Map<String, Controller> controllers = new HashMap<>(); | ||||||||||||||||||||||||||||||
private static final FrontController frontController = new FrontController(); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
static { | ||||||||||||||||||||||||||||||
controllers.put("/", frontController.mainPageController); | ||||||||||||||||||||||||||||||
controllers.put("/login", frontController.loginController); | ||||||||||||||||||||||||||||||
controllers.put("/register", frontController.loginController); | ||||||||||||||||||||||||||||||
controllers.put("/index", frontController.indexController); | ||||||||||||||||||||||||||||||
controllers.put("/index.html", frontController.indexController); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
프론트 컨트롤러와 같이 해당 컨트롤러에서 인스턴스를 가져오는 방법으로 싱글톤을 유지하는 방법은 어떤가요? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 것 같습니다👍 |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
private final LoginController loginController = new LoginController(); | ||||||||||||||||||||||||||||||
private final MainPageController mainPageController = new MainPageController(); | ||||||||||||||||||||||||||||||
private final IndexController indexController = new IndexController(); | ||||||||||||||||||||||||||||||
private final OtherController otherController = new OtherController(); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
private FrontController() { | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
public static FrontController getInstance() { | ||||||||||||||||||||||||||||||
return frontController; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
public Controller findController(RequestReader requestReader) { | ||||||||||||||||||||||||||||||
return controllers.getOrDefault(requestReader.getRequestUrl(), otherController); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
디버깅을 위해 사용한 출력문은 삭제해도 좋을 것 같아요 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
부끄럽네요..