Skip to content

Commit

Permalink
feat: 질문 수정 API 개발(#7)
Browse files Browse the repository at this point in the history
* Put Controller 개발
* modifyContent Service 개발
* Question에 Constructor 추가
  • Loading branch information
isieun0908 committed Apr 24, 2023
1 parent d466fc5 commit 47b6dbb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -23,4 +24,12 @@ public Boolean create(@PathVariable Long channel_id, @RequestBody QuestionReques

return true;
}

@PutMapping("/question/{question_id}")
public Boolean modify(@PathVariable Long question_id, @RequestBody QuestionRequest questionRequest) {

questionService.modifyContent(question_id, questionRequest);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import devteamOne.classmate.user.domain.User;
import jakarta.persistence.*;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Question {

@Id
Expand All @@ -27,4 +32,8 @@ public class Question {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "channel_id")
private Channel channel;

public void modifyContent(String content) {
this.content = content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,17 @@ public void save(Long channel_id, QuestionRequest questionRequest) {
//.user(user)
.build());
}

public void modifyContent(Long question_id, QuestionRequest questionRequest) {

// question 조회
Question question = questionRepository.findById(question_id)
.orElseThrow();

// user 조회 및 권한 확인

// question 내용 수정
question.modifyContent(questionRequest.getContent());
questionRepository.save(question);
}
}

0 comments on commit 47b6dbb

Please sign in to comment.