11.21 save Problem List Post..
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.io.realworld.config;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TagListDeserializer extends JsonDeserializer<List<String>> {
|
||||
@Override
|
||||
public List<String> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||
JsonToken jt = p.getCurrentToken();
|
||||
if(jt == JsonToken.START_ARRAY){
|
||||
return p.readValueAs(List.class);
|
||||
}else if(jt == JsonToken.VALUE_STRING){
|
||||
return Arrays.asList(p.getValueAsString());
|
||||
}
|
||||
throw new UnsupportedOperationException("Cannot update object");
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,19 @@
|
||||
package com.io.realworld.domain.aggregate.article.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.io.realworld.config.TagListDeserializer;
|
||||
import lombok.*;
|
||||
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@JsonTypeName("article")
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
|
||||
@@ -19,6 +21,9 @@ public class Articledto {
|
||||
private String title;
|
||||
private String description;
|
||||
private String body;
|
||||
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
|
||||
//@JsonDeserialize(using = TagListDeserializer.class)
|
||||
private List<String> tagList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
placeholder="Write your article (in markdown)" v-model="article.body"></textarea>
|
||||
</fieldset>
|
||||
<fieldset class="form-group">
|
||||
<input type="text" class="form-control" placeholder="Enter tags" v-model="tag">
|
||||
<input type="text" class="form-control" placeholder="Enter tags" v-model="article.tagList">
|
||||
<div class="tag-list"></div>
|
||||
</fieldset>
|
||||
<button @click="addArticle" class="btn btn-lg pull-xs-right btn-primary" type="button">
|
||||
@@ -46,16 +46,18 @@ export default {
|
||||
const url = import.meta.env.VITE_BASE_URL;
|
||||
const store = useStore();
|
||||
const token = store.state.token
|
||||
const tag = ref("")
|
||||
const article = reactive({
|
||||
title: "",
|
||||
description: "",
|
||||
body: "",
|
||||
tagList: new Array(tag),
|
||||
tagList: [],
|
||||
})
|
||||
|
||||
const addArticle = () => {
|
||||
console.log(article)
|
||||
console.log(JSON.stringify(article));
|
||||
console.log(JSON.stringify({article}));
|
||||
console.log({article});
|
||||
axios.post(url+"/api/articles",JSON.stringify({article}) ,{headers:{
|
||||
Authorization : "TOKEN " + token,
|
||||
"Content-Type": `application/json`,
|
||||
@@ -63,7 +65,7 @@ export default {
|
||||
.then(response => {console.log(response)})
|
||||
}
|
||||
|
||||
return { article,tag, addArticle }
|
||||
return { article, addArticle }
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -84,8 +84,7 @@ export default {
|
||||
user
|
||||
})
|
||||
.then(response => {
|
||||
store.dispatch("LOGIN",response.data.user)
|
||||
allHideError();
|
||||
store.dispatch("LOGIN",response.data.user).then(allHideError);
|
||||
router.push({name: "Home"});
|
||||
})
|
||||
.catch(error =>{
|
||||
|
||||
Reference in New Issue
Block a user