Skip to content
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

[#3] controller, dto 생성, Test 코드 작성 #4

Merged
merged 7 commits into from
Dec 18, 2024
Merged

Conversation

austinhong22
Copy link
Collaborator

구현사항

  • controller, dto 생성
  • test 코드 작성

@austinhong22 austinhong22 self-assigned this Dec 11, 2024
api/build.gradle Outdated
@@ -10,4 +11,5 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.apache.ant:ant:1.10.13'

Choose a reason for hiding this comment

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

이 라이브러리는 왜 필요했을까요?


@PutMapping("/settings")
public String updateAlertSetings(@RequestBody AlertSettingsDto settings){
return "updated setting";

Choose a reason for hiding this comment

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

업데이트된 AlertSettings를 보여주는게 좋지 않을까요?


@PostMapping
public String createPost(@RequestBody PostDto post) {
return "게시글 생성 : " + post.getTitle();

Choose a reason for hiding this comment

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

아웃풋은 되도록이면, 구조체로 보내는 것이 좋은 것 같습니다. title만 보낼 것이어도, json형태로 보내는 것이 클라이언트에서 사용하기 편하지 않을까 싶네요.

public class AlertController {

@GetMapping("/settings")
public AlertSettingsDto getAlertSettings() {

Choose a reason for hiding this comment

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

AlertSettings가 여러개 인 경우가 더 일반적이지 않을까요?

}

@PutMapping("/settings")
public String updateAlertSetings(@RequestBody AlertSettingsDto settings){

Choose a reason for hiding this comment

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

하나의 alertSettings를 지정하기 위한 key나 unique값이 필요하지 않을까요? 어떤 alertSettings를 바꾸고 싶은지에 대해서 ...


@RestController
@RequestMapping("/api/posts")
public class CommunityController {

Choose a reason for hiding this comment

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

URL과 컨트롤러의 규칙을 통일하면 더 좋을 것 같습니다.

public class TransactionController {

@GetMapping("/list")
public List<TransactionDto> getTransactions(){

Choose a reason for hiding this comment

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

나중에 페이징이 들어갈 예정


@RestController
@RequestMapping("/api/alerts")
public class AlertController {

Choose a reason for hiding this comment

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

alerts는 로그인한 사용자를 기반으로 보여주는 API

return userDto;
}

@GetMapping("/me")

Choose a reason for hiding this comment

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

Suggested change
@GetMapping("/me")
@GetMapping

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@WebMvcTest(controllers = AlertController.class)

Choose a reason for hiding this comment

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

@SpringBootTest(.......)

public class AlertControllerTest {

@Autowired
MockMvc mockMvc;

Choose a reason for hiding this comment

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

TestRestTemplate

.content(userJson))
.andExpect(status().isOk())
.andExpect(jsonPath("$.email").value("[email protected]"))
.andExpect(jsonPath("$.username").value("Test"));

Choose a reason for hiding this comment

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

포함되어야하는 필드 이외에 다른 필드가 없는지는 어떻게 테스트할 수 있을까요?


@Test
void createPost() throws Exception {
PostDto post = new PostDto(3, "Post1", "post1");

Choose a reason for hiding this comment

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

createPost인데 PostDto에 id가 있는 것이 좀 이상한 것 같아요. :-)

}

@PostMapping("/login")
public UserDto loginUser(@RequestBody UserDto userDto) {

Choose a reason for hiding this comment

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

로그인 결과로는 JWT Token을 줄 예정

@RestController
@RequestMapping("/api/posts")
public class PostController {
private List<PostDto> posts = new ArrayList<>();

Choose a reason for hiding this comment

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

중요한건 아니지만, ArrayList는 Thread-safe한가요?

Copy link

@f-lab-lyan f-lab-lyan left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@austinhong22 austinhong22 merged commit 99e8409 into develop Dec 18, 2024
2 checks passed
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