Skip to content

Conversation

yungu0010
Copy link
Member

✅ 과제

  1. Post 데이터 형식 정의 & 각 필요한 Dto 정의
  2. 게시물 생성 실습
  3. 게시물 조회 (Path Variable) 1번 아이디의 게시물 조회 → ArrayList의 get 메서드 참조
  4. 게시물 검색 (Query Parameter) 해당 제목의 게시물 검색

Comment on lines +9 to +10
import java.util.ArrayList;
@SpringBootApplication

Choose a reason for hiding this comment

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

9번째 줄과 10번째 줄 띄어쓰기 해주시면 좋을 것 같아요

Comment on lines +13 to +14
public static ArrayList<User> userList;
public static ArrayList<Article> articleList;

Choose a reason for hiding this comment

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

static과 non-static의 차이는 무엇일까요?
이걸 static으로 두면 어떤 일이 발생할까요?

Comment on lines +9 to +35
@PostMapping("/article")
public String register(@RequestBody final RegisterArticleRequestDto request) {
System.out.println(request.getTitle());
System.out.println(request.getDetail());

// 서비스 계층에 유저를 등록하는 메서드를 호출

return "게시물 등록이 완료됐습니다.";
}

@GetMapping("/article/{articleId}")
public String getOne(@PathVariable final Long articleId) {
System.out.println("요청 게시물 아이디: " + articleId);

// 서비스 계층에서 유저 아이디로 유저를 찾는 메서드 호출

return "게시물 조회 성공";
}

@GetMapping("/article/search")
public String search(@RequestParam final String title) {
System.out.println("게시물 제목 검색 인자: " + title);

// 서비스 계층에서 유저 닉네임으로 유저를 찾는 메서드 호출

return "게시물 검색 성공";
}

Choose a reason for hiding this comment

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

컨트롤러의 어노테이션으로 @RequestMapping("/article")을 붙여주면 조금 더 편할 거에요! 검색해보세요.

Comment on lines +9 to +14
public class RegisterArticleRequestDto {

private String title;

private String detail;
}

Choose a reason for hiding this comment

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

필드를 불변으로 해주면 더 좋을 것 같아요! 바뀌면 안되는 값들이잖아용:)

Comment on lines +18 to +19
@RequiredArgsConstructor
public class UserController {

Choose a reason for hiding this comment

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

요긴 RequiredArgsConstructor를 쓰셧네요
AllArgsConstructor와 RequiredArgsConstructor의 차이는 무엇일까요?

@RestController
@RequiredArgsConstructor
public class UserController {
private final UserService userService;

Choose a reason for hiding this comment

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

@Autowired를 하지 않아도 자동으로 스프링 빈으로 주입이 되는데 왜그럴까요?

public class UserController {
private final UserService userService;

@PostMapping("/user")

Choose a reason for hiding this comment

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

마찬가지로 컨트롤러 어노테이션으로 @RequiredMapping으로 해주시면 좋을 것 같아요!

"contact: " + this.contact + "\n" +
"age: " + this.age;
}
} No newline at end of file

Choose a reason for hiding this comment

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

마지막줄 한줄 띄워줘여 ㅋㅋ

Comment on lines +18 to +20
public void setId(Long id) {
this.id = id;
}

Choose a reason for hiding this comment

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

도메인은 굉장히 중요한 객체인데요. 변하는 것을 최대한 방어해야한다고 생각해요.
세터를 쓰는 것보다 생성자를 두 개 만들어서 설정해보면 어떨까요?

Comment on lines +8 to +20
public class User {

private Long id;

private String gender;

private String name;

private String address;

private String contact;

private int age;

Choose a reason for hiding this comment

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

마찬가지로 도메인 관련 이야기인데요. final 키워드를 붙여보시면 조금 더 객체지향적으로 변할 겁니다.

Copy link

@hyesuuou hyesuuou left a comment

Choose a reason for hiding this comment

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

자바윤서 ㄷ ㄷ
스위프트 없이 행복해?


// 데이터베이스에 저장
articleList.add(newArticle);
newArticle.setId((long) articleList.size());

Choose a reason for hiding this comment

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

타입케스팅의 다른 방법도 존재합니다! toLong()처럼..?

Choose a reason for hiding this comment

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

이렇게 강제 케스팅을 하지 않는 이유는, toLong() 코드를 뜯어보면 아시겠지만 예외처리를 해줍니다:)

Copy link

@shb03323 shb03323 left a comment

Choose a reason for hiding this comment

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

고생하셨슴돠
처음인거 맞나요? 구조 미쳤네요

// 서비스 계층에서 유저 닉네임으로 유저를 찾는 메서드 호출

return "게시물 검색 성공";
}

Choose a reason for hiding this comment

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

검색하려는 게시물이 없을 때에 대한 예외처리도 해주시면 더 보기 좋을 것 같습니다-!!👍

@dong2ast
Copy link

dong2ast commented May 1, 2023

제가 발견한 부분은 다른 분들께서 다 작성해주셔서😂
고생하셨습니다 👍

Copy link

@dong2ast dong2ast left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

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.

5 participants