Skip to content

Commit

Permalink
#16 Create _post_mapping route to send a new doctype description
Browse files Browse the repository at this point in the history
  • Loading branch information
Estelle Maudet committed Nov 14, 2018
1 parent b0c5a93 commit 430c861
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions web/fulltext/fulltext.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Routes(router *echo.Group) {
router.POST("/_delete_index", DeleteIndex)
router.POST("/_delete_all_indexes", DeleteAllIndexes)
router.POST("/_delete_index_query/:instance/:doctype/:lang", DeleteIndexQuery)
router.POST("/_post_mapping/:doctype", PostMapping)
}

func SearchQuery(c echo.Context) error {
Expand Down Expand Up @@ -324,6 +325,45 @@ func DeleteIndexQuery(c echo.Context) error {
return c.JSON(http.StatusOK, nil)
}

func PostMapping(c echo.Context) error {

docType := c.Param("doctype")

tmpFile, err := ioutil.TempFile(indexation.MappingDescriptionPath, "store.tmp.")
if err != nil {
fmt.Println(err)
return c.JSON(http.StatusInternalServerError, echo.Map{
"error": err.Error(),
})
}

_, err = io.Copy(tmpFile, c.Request().Body)
if err != nil {
fmt.Println(err)
return c.JSON(http.StatusInternalServerError, echo.Map{
"error": err.Error(),
})
}

err = tmpFile.Close()
if err != nil {
fmt.Println(err)
return c.JSON(http.StatusInternalServerError, echo.Map{
"error": err.Error(),
})
}

err = os.Rename(tmpFile.Name(), indexation.MappingDescriptionPath+docType+".json")
if err != nil {
fmt.Println(err)
return c.JSON(http.StatusInternalServerError, echo.Map{
"error": err.Error(),
})
}

return c.JSON(http.StatusOK, nil)
}

func MakeRequest(mapJSONRequest map[string]interface{}) search.QueryRequest {

request := search.QueryRequest{
Expand Down

0 comments on commit 430c861

Please sign in to comment.