Skip to content

Backend-study-assignment1#1

Open
HyunsuYEE wants to merge 1 commit into
HeXA-UNIST:masterfrom
HyunsuYEE:develop
Open

Backend-study-assignment1#1
HyunsuYEE wants to merge 1 commit into
HeXA-UNIST:masterfrom
HyunsuYEE:develop

Conversation

@HyunsuYEE

Copy link
Copy Markdown

Todo class



int count_completed = 0;
for(int i= 0; i < todoList.size(); i++){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todoList.size()를 변수로 빼놓으면 함수 call 여러번 안해도 되니까 좀 더 최적화 되고 좋을듯?


int count_completed = 0;
for(int i= 0; i < todoList.size(); i++){
if(todoList.get(i).isCompleteYn()){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요런거 세고 싶을 때는 stream을 사용하면 filter랑 count 써서 더 쉬울 수 있음. for랑 if 사용하는거보다 보기도 좋을것.

int count_completed = todoList.stream()
    .filter(Todo::isCompleteYn)
    .count();

요런 느낌으로 가능해짐. 한번 찾아보고 바꿔보면 좋을 거야...


}
public List<TodoInquiryDto> changeIntoTodoInquiryDto(List<ParentTodo> entities){
return entities.stream().map(parentTodo -> new TodoInquiryDto(parentTodo.getIdList(),parentTodo.getTitle(),parentTodo.getContent(),parentTodo.getSubTitles(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream 사용할 때는 보기 좋게 하기 위해서 .stream() 아래로 .map이나 .filter, .collect 등 함수들 마다 줄 바꿈을 해주는 편. 그렇게 해서 어떤 것을 하고 싶은것인지 해당 줄 맨 앞에 보여주고 그 외에 내용은 들여쓰기로 안에 들여써두면 이 stream에서 뭘 하고 싶은 것인지 더 잘 보이기 때문.

잘 formatting 다시 해보기 바람.

return this.completeYn;
}
public Short getTakeToTimeInMinutes(){
return (short)(this.endAt.getMinute()- this.startAt.getMinute());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit 이전에 자동 줄 정렬을 모든 파일에서 못하니까 intelliJ commit 할 때 옵션 중에 reformatting 옵션이 있는데 그걸 켜두면 알아서 commit 할 때 이런 띄워쓰기 같은거 reformatting을 해줌. 설정 해놓고 commit 하기!

public TodoResponse getTodoResponse() {
// todo
return null;
List<ParentTodo> listOfParentTodo= this.todoEntities.stream().map(todo -> (ParentTodo)todo).collect(Collectors.toList());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 reformatting 필요.

// todo
return null;
List<ParentTodo> listOfParentTodo= this.todoEntities.stream().map(todo -> (ParentTodo)todo).collect(Collectors.toList());
TodoResponse TR = new TodoResponse(listOfParentTodo);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명 아무리 길어져도 이렇게 줄임말을 잘 사용하지 않는 편.
대문자로 이루어진 변수는 관행적으로 전역 변수를 의미하기 때문에, 이렇게 사용하면 어떤 것이 전역인지 아닌지 구분하기 힘들어짐. 지역 변수는 반드시 맨 앞에는 소문자, 그 외 단어 시작마다 대문자를 사용하는 camelCase로 사용해야함.

List<TodoUpdateDto> updatedDtos = request.getTodoUpdateList();
for(int i = 0; i < updatedDtos.size(); i++){
boolean found = false;
for(int j = 0; j < todoEntities.size(); j++){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for를 이용해서 구현했는데, 사실 list에서는 get을 이용하는 것이 더 일반적이지 않고, 객체를 바로 가져오도록 하는 것이 많음. 차라리 forEach를 쓰는 것이 더 낫지 않았을까 싶음....

// todo: 입력 받은 childTodo의 완료 처리와 동시에 parentTodo의 모든 details 내에 있는 todo가 완료 되었으면 parentTodo도 완료 처리.
}
public List<Long> getIdList(){
List<Long> IdList = Collections.emptyList();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 이용하지 말고 stream으로 한번에 내주면 더 좋을 것 같은데 그럼 변수 선언 없이 바로 return도 가능할듯.

return this.details.stream()
    .map(Todo::getId)
    .collect(Collectors.List());

아래 함수들도 같은 식으로 다시 구현 가능하니 다시 구현해보기 바람.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants