-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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' |
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.
이 라이브러리는 왜 필요했을까요?
|
||
@PutMapping("/settings") | ||
public String updateAlertSetings(@RequestBody AlertSettingsDto settings){ | ||
return "updated setting"; |
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.
업데이트된 AlertSettings를 보여주는게 좋지 않을까요?
|
||
@PostMapping | ||
public String createPost(@RequestBody PostDto post) { | ||
return "게시글 생성 : " + post.getTitle(); |
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.
아웃풋은 되도록이면, 구조체로 보내는 것이 좋은 것 같습니다. title만 보낼 것이어도, json형태로 보내는 것이 클라이언트에서 사용하기 편하지 않을까 싶네요.
public class AlertController { | ||
|
||
@GetMapping("/settings") | ||
public AlertSettingsDto getAlertSettings() { |
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.
AlertSettings가 여러개 인 경우가 더 일반적이지 않을까요?
} | ||
|
||
@PutMapping("/settings") | ||
public String updateAlertSetings(@RequestBody AlertSettingsDto settings){ |
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.
하나의 alertSettings를 지정하기 위한 key나 unique값이 필요하지 않을까요? 어떤 alertSettings를 바꾸고 싶은지에 대해서 ...
|
||
@RestController | ||
@RequestMapping("/api/posts") | ||
public class CommunityController { |
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.
URL과 컨트롤러의 규칙을 통일하면 더 좋을 것 같습니다.
public class TransactionController { | ||
|
||
@GetMapping("/list") | ||
public List<TransactionDto> getTransactions(){ |
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.
나중에 페이징이 들어갈 예정
|
||
@RestController | ||
@RequestMapping("/api/alerts") | ||
public class AlertController { |
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.
alerts는 로그인한 사용자를 기반으로 보여주는 API
return userDto; | ||
} | ||
|
||
@GetMapping("/me") |
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.
@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) |
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.
@SpringBootTest(.......)
public class AlertControllerTest { | ||
|
||
@Autowired | ||
MockMvc mockMvc; |
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.
TestRestTemplate
.content(userJson)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.email").value("[email protected]")) | ||
.andExpect(jsonPath("$.username").value("Test")); |
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.
포함되어야하는 필드 이외에 다른 필드가 없는지는 어떻게 테스트할 수 있을까요?
|
||
@Test | ||
void createPost() throws Exception { | ||
PostDto post = new PostDto(3, "Post1", "post1"); |
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.
createPost인데 PostDto에 id가 있는 것이 좀 이상한 것 같아요. :-)
} | ||
|
||
@PostMapping("/login") | ||
public UserDto loginUser(@RequestBody UserDto userDto) { |
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.
로그인 결과로는 JWT Token을 줄 예정
Quality Gate passedIssues Measures |
@RestController | ||
@RequestMapping("/api/posts") | ||
public class PostController { | ||
private List<PostDto> posts = new ArrayList<>(); |
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.
중요한건 아니지만, ArrayList는 Thread-safe한가요?
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.
LGTM 👍
구현사항