Skip to content

Commit

Permalink
Merge pull request #217 from tukcom2023CD/BE/hotfix/#216
Browse files Browse the repository at this point in the history
[BE/hotfix/#216] 게시글 수정 및 질문 완료 복원, 로그인시 id까지 반환
  • Loading branch information
kjeongh authored Jun 16, 2023
2 parents 1e3a81f + d0c893c commit 8c29373
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import java.util.List;

import static com.rising.backend.domain.post.dto.PostDto.PostCreateRequest;
Expand Down Expand Up @@ -84,5 +85,23 @@ public ResponseEntity<ResultResponse> getPostListByUserId(@PathVariable Long use
return ResponseEntity.ok(ResultResponse.of(ResultCode.POSTLIST_FIND_BY_USERID_SUCCESS, postList));
}

@PutMapping("/{postId}")
public ResponseEntity<ResultResponse> update(
@PathVariable Long postId,
@RequestBody PostDto.PostUpdateRequest updateRequest) {
postService.updatePost(postId, updateRequest);
return ResponseEntity.ok(ResultResponse.of(ResultCode.POST_UPDATE_SUCCESS));

}

//멘토링 종료
@PutMapping("/{postId}/solve")
public ResponseEntity<ResultResponse> solve(
@PathVariable Long postId,
@RequestBody String solvedCode) {
postService.solve(postId, solvedCode);
return ResponseEntity.ok(ResultResponse.of(ResultCode.POST_SOLVED));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,21 @@ public Tag getTagByContent(String content) {
public void deletePostById(Long postId) {
postRepository.deleteById(postId);
}

public void updatePost(Long postId, PostDto.PostUpdateRequest updateRequest) {
Post post = findPostById(postId);

List<Tag> tags = updateRequest.getTags().stream().map(t -> getTagByContent(t))
.collect(Collectors.toList());

post.setTitle(updateRequest.getTitle());
post.setContent(updateRequest.getContent());
post.setTags(tags);
}

public void solve(Long postId, String solvedCode) {
Post post = findPostById(postId);
post.setSolved(); //멘토링 완료
post.setSolvedCode(solvedCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public ResponseEntity<ResultResponse> login(@RequestBody @Valid UserDto.UserLogi
loginService.login(member.getId(), request.getSession()); //세션에 로그인 정보 저장

return ResponseEntity.ok(ResultResponse.of(ResultCode.USER_LOGIN_SUCCESS,
UserDto.UserLoginResponse.builder().name(member.getName()).build()));
UserDto.UserLoginResponse.builder()
.name(member.getName())
.id(member.getId())
.build()));
}

@GetMapping("/logout")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public static class UserLoginResponse {

@NotNull
private String name;

private Long id;
}

@Builder
Expand Down

0 comments on commit 8c29373

Please sign in to comment.