Answer Create
입력한 데이터로 Answer object를 생성합니다.
URL
/post/answer/
Method
POST
Data Params
Key | Description | Type | Require |
---|---|---|---|
question | 답변이 달리는 Question의 pk | Int | True |
content | quillJS 텍스트 에디터에서 .getContent()를 통해 뽑아낸 json데이터 - https://quilljs.com/docs/delta/ | JSON | False |
content_html | quillJS 텍스트 에디터에서 InnerHTML 을 통해 뽑아낸 html String | Str | False |
published | "임시저장" 버튼의 경우 False, "답변 포스트"버튼의 경우 True를 전달 | Bool | False |
Content: Require = False, 하지만 ""값은 받지 못함
유저가 질문에 답변을 하려고 클릭을 했다가 아무런 답변을 달지 않아도 임시저장을 할 수 있도록 하기 위해 필수항목이 아니도록 설정되었습니다.
하지만 JSONField의 Implementation때문에 content:"" 혹은 content:Null 형식의 자료를 받지 못합니다. - 이 경우 400 Error가 발생합니다. 그렇기 때문에, 만약 유저가 아무런 글을 적지 않았다면 content data parameter 자체를 보내지 말아야 합니다.
Published: Require = False
Published 에 대한 아무런 값을 전달하지 않을 경우 default가 False로 설정되도록 정해져 있습니다.
Success Response
HTTP Status Code
201
Content
Key | Description | Type |
---|---|---|
pk | Answer의 pk | Int |
url | 생성된 Answer Detail 링크 | Str |
user | Topic을 만든 유저의 Profile Detail 링크 | Str |
question | Answer가 달린 Question Detail 링크 | int |
content_html | quillJS 텍스트 에디터에서 InnerHTML 을 통해 뽑아낸 html String | str |
content | quillJS 텍스트 에디터에서 .getContent()를 통해 뽑아낸 json데이터 | JSON |
published | True or False | Bool |
created_at | 생성된 날짜 | Date |
modified_at | 마지막으로 수정된 날짜 - 처음 생성되었을 때는 created_at과 같음 | Date |
{
"pk": 179,
"url": "http://localhost:8000/post/answer/179/",
"user": "http://localhost:8000/user/4/profile/main-detail/",
"question": "http://localhost:8000/post/question/12/",
"content_html": "<div class=\"ql-editor\" contenteditable=\"true\" data-gramm=\"false\" data-placeholder=\"Compose an epic...\"><p>A robot who has developed sentience, and is the only robot of his kind shown to be still functioning on Earth.</p><p><img src=\"/media/answer/179/ZD0KQY.jpeg\"/></p><p>This is a Test to see if image saving is actually working. </p><p>한번 테스트를 해보겠습니다. </p><p><br/></p><p>정말 이미지 삽입이 잘 될까요?</p><p><img src=\"/media/answer/179/9Z4J9F.jpeg\"/></p></div><div class=\"ql-clipboard\" contenteditable=\"true\" tabindex=\"-1\"></div><div class=\"ql-tooltip ql-hidden\" style=\"margin-top: -119px;\"><a class=\"ql-preview\" href=\"about:blank\" target=\"_blank\"></a><input data-formula=\"e=mc^2\" data-link=\"https://quilljs.com\" data-video=\"Embed URL\" type=\"text\"/><a class=\"ql-action\"></a><a class=\"ql-remove\"></a></div>",
"content": {
"ops": [
{
"insert": "A robot who has developed sentience, and is the only robot of his kind shown to be still functioning on Earth.\n"
},
{
"insert": {
"image": "/media/answer/179/ZD0KQY.jpeg"
}
},
{
"insert": "\nThis is a Test to see if image saving is actually working. \n한번 테스트를 해보겠습니다. \n\n정말 이미지 삽입이 잘 될까요?\n"
},
{
"insert": {
"image": "/media/answer/179/9Z4J9F.jpeg"
}
},
{
"insert": "\n"
}
]
},
"upvote_count": 0,
"comment_count": 0,
"user_upvote_relation": null,
"user_bookmark_relation": null,
"published": true,
"created_at": "2017-12-12",
"modified_at": "2017-12-12T16:37:31.414314+09:00"
}
Error Response
Bad Request Error
HTTP Status Code
400
Content
# 필수 항목 누락
{
"question": [
"이 필드는 필수 항목입니다."
],
}
HTTP Status Code
400
Content
# Content 가 None 인 상태에서 Publish가 True로 전달되었을 시
{
"non_field_errors": [
"Content가 없는 답변은 Publish가 불가능합니다."
]
}
HTTP Status Code
400
Content
# Data Parameter에 Content가 Key값으로 왔으나 Value 가 비어있을 때
{
"content": [
"Value 는 유효한 JSON형식이어야 합니다."
]
}
HTTP Status Code
400
Content
# Content 가 있으나 Content_html이 없을
{
"error": "Content 가 왔으나 Content_html 이 없습니다."
}
HTTP Status Code
400
Content
# Content_html 이 있으나 Content 가 없을
{
"error": "Content_html 이 왔으나 Content 없습니다."
}