Skip to content

Commit

Permalink
Merge pull request #208 from tukcom2023CD/feat/#207
Browse files Browse the repository at this point in the history
[Feat/#207] 멘토링 완료 및 당시 코드 저장, 게시글 수정
  • Loading branch information
kjeongh authored Jun 10, 2023
2 parents 3b4ae6a + 98d6c32 commit 80af651
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 9 deletions.
2 changes: 0 additions & 2 deletions backend/gradle/properties.java

This file was deleted.

Binary file removed backend/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 0 additions & 5 deletions backend/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rising.backend.domain.post.domain.PostType;
import com.rising.backend.domain.post.dto.PostDto;
import com.rising.backend.domain.post.dto.PostDto.PostUpdateRequest;
import com.rising.backend.domain.post.service.PostService;
import com.rising.backend.domain.user.domain.User;
import com.rising.backend.global.annotation.LoginRequired;
Expand Down Expand Up @@ -84,5 +85,25 @@ 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 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
@@ -1,8 +1,10 @@
package com.rising.backend.domain.post.domain;

import com.rising.backend.domain.post.dto.PostDto.PostUpdateRequest;
import com.rising.backend.domain.user.domain.User;
import com.rising.backend.global.domain.BaseEntity;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

Expand Down Expand Up @@ -31,18 +33,28 @@ public class Post extends BaseEntity {

@NotBlank
@Column(length = 100)
@Setter
private String title;

@NotBlank
@Column(columnDefinition = "TEXT")
@Setter
private String content;


@Column(length = 255)
private String videoUrl;

@Column(length = 255)
private String sessionUrl;

@ColumnDefault("false")
private boolean isSolved;

@Column(length = 1000)
@Setter
private String solvedCode;

@NotNull
@Enumerated(EnumType.STRING)
private PostType postType;
Expand All @@ -52,10 +64,17 @@ public class Post extends BaseEntity {
joinColumns = @JoinColumn(name = "POST_ID"),
inverseJoinColumns = @JoinColumn(name = "TAG_ID")
)

@Setter
private List<Tag> tag = new ArrayList<>();


public void setTags(List<Tag> tags) {
this.tag = tags;
}

public void setSolved() {
this.isSolved = true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public static class PostCreateRequest {
private List<String> tags = new ArrayList<>();
}

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public static class PostUpdateRequest {
private String title;
private String content;
private List<String> tags = new ArrayList<>();
}

@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
Expand Down Expand Up @@ -76,6 +85,10 @@ public static class PostDetailResponse {

private LocalDate created_at;

private boolean isSolved;

private String solvedCode;

private List<String> tags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public PostDto.PostDetailResponse toPostDto(Post post, List<String> tags) {
.title(post.getTitle())
.content(post.getContent())
.videoUrl(post.getVideoUrl())
.type(post.getPostType())
.type(post.getType())
.isSolved(post.isSolved())
.solvedCode(post.getSolvedCode())
.tags(tags)
.created_at(post.getCreatedAt().toLocalDate())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,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 @@ -16,11 +16,12 @@ public enum ResultCode {

//POST
POST_CREATE_SUCCESS(201, "게시글 등록 성공"),

POST_UPDATE_SUCCESS(200, "게시글 수정 성공"),
POST_DELETE_SUCCESS(200, "게시글 삭제 성공"),
POST_PAGINATION_SUCCESS(200, "게시글 리스트 조회 성공"),
POST_FIND_SUCCESS(200, "게시글 id로 단일 게시글 조회 성공"),
POSTLIST_FIND_BY_USERID_SUCCESS(200, "유저 id로 게시글 리스트 조회 성공"),
POST_SOLVED(200, "질문 해결"),

//SESSION
SESSION_GET_SUCCESS(201, "세션 반환 성공"),
Expand Down

0 comments on commit 80af651

Please sign in to comment.