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
Todo REST API 만들기 #71
Conversation
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.
안녕하세요. 반갑습니다!
String method = exchange.getRequestMethod(); | ||
URI uri = exchange.getRequestURI(); | ||
String path = uri.getPath(); |
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.
변경하지 않을 값을 선언하게 될 경우엔 final
을 붙여 보면 어떨까요?
String method = exchange.getRequestMethod(); | |
URI uri = exchange.getRequestURI(); | |
String path = uri.getPath(); | |
final String method = exchange.getRequestMethod(); | |
final URI uri = exchange.getRequestURI(); | |
final String path = uri.getPath(); |
import com.sun.net.httpserver.HttpExchange; | ||
import com.sun.net.httpserver.HttpHandler; | ||
|
||
import java.io.*; |
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.
import *
을 하지 않는 것이 좋은 습관일 수 있어요. 어떤 것을 import
하는지 분명히 명시해 주는 연습을 해 봅시다. IDE의 기능을 사용하면 *
을 각 import
문으로 확장해줄 수 있을 거에요.
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.
IDE기능을 꺼두고 각각 어떤 기능것을 명시해주는지 알도록 앞으로는 *쓰는것을 자제하겠습니다
import * 해제하 각항목에 대해 명시(import문 확장)
변경하지 않는 값은 상수로 바꾸고 |
import java.util.stream.Collectors; | ||
|
||
public class DemoHttpHandler implements HttpHandler { | ||
private ObjectMapper objectMapper = new ObjectMapper(); |
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.
이번 과제에서는 ObjectMapper
를 사용하지 않고 작업을 해 보면 어떨까요? 추후 아샬님의 강의 단계에서 등장할 거에요.
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.
ObjectMapper를 사용하지 않는 방법은 프레임워크를 통해서가 아닌 따로 자바의 기능내에서 말씀하는건가요??
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.
네 ObjectMapper
를 쓰지 않고 직접 String을 갖고 작업하는 방법을 권해드리는 거에요. 물론 계속 쓰는 것이 더 낫다고 생각하시면 그대로 사용하셔도 괜찮아요.
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.
넵 감사합니다. 다음 과제부터와 이번과제에서부터 적용해보도록 노력하겠습니다.
import * 해제하 각항목에 대해 명시(import문 확장)
# Conflicts: # app/src/main/java/com/codesoom/assignment/DemoHttpHandler.java
import * 해제하 각항목에 대해 명시(import문 확장)
오늘 올라온 강의를 보고 과제를 마무리하면서 자바가 너무나도 약하다는걸 다시한번 깨달았습니다. |
if (method.equals("GET") ) { | ||
handleDetail(exchange, task); | ||
} | ||
|
||
if (method.equals("PUT") || method.equals("PATH")) {//PUT : 전체 PATH : 일부분 | ||
handleUpdate(exchange, task); | ||
} | ||
|
||
if (method.equals("DELETE") ) { |
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.
GET
, PUT
, DELETE
같은 HTTP method는 enum으로 선언해보면 어떨까요? 문자열을 그대로 사용하는 것은 아쉬운 일입니다.
} | ||
|
||
private void handleList(HttpExchange exchange) throws IOException { | ||
send(exchange, 200, toJSON(tasks)); |
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.
200
같은 HTTP status 코드도 enum으로 선언해 보세요.
//get을 사용시 그대로 나오며 값이 없다면 excption을 준다 | ||
private Task findTask(Long id) { | ||
return tasks.stream() | ||
.filter(task -> task.getId().equals(id)) | ||
.findFirst() | ||
.orElse(null); | ||
// .findFirst().get(); | ||
} |
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.
주석에서는 값이 없다면 exception을 준다
라고 작성하셨는데요, 코드에서는 값이 없는 경우에 null
을 리턴하도록 하고 있습니다. 주석이나 코드 둘 중 하나를 고칠 필요가 있겠어요.
private Long generateId() { | ||
newId += 1; | ||
return newId; | ||
} |
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.
synchronized
에 대해 조사해 보시고 적용을 고려해 보세요.
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.
한 주간 고생 많으셨습니다. 다음주부터는 일요일 저녁에 주간 회고를 작성해 공유해 주세요.
이번주 과제는 끝났지만 받은 리뷰는 틈틈히 고쳐 보도록 하겠습니다! |
아직 자바에 익숙하지 않아서 책을 보면서 좀더 생각을 해보고 있습니다.
구현 능력이 떨어지다보니 좀더 노력해야할 거같아요