Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Support for search api in web server.
Browse files Browse the repository at this point in the history
  • Loading branch information
agile6v committed Apr 14, 2019
1 parent 23aa2ec commit 3130bbf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
19 changes: 19 additions & 0 deletions pkg/server/web/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func (api *AppAPI) create(w http.ResponseWriter, r *http.Request) {
return
}

if task.Protocol == "" {
util.RespondWithError(w, http.StatusBadRequest, "Protocol field cannot be empty.")
return
}

err = task.Handle(body)
if err != nil {
util.RespondWithError(w, http.StatusInternalServerError, err.Error())
Expand Down Expand Up @@ -79,7 +84,21 @@ func (api *AppAPI) delete(w http.ResponseWriter, r *http.Request) {
}

func (api *AppAPI) search(w http.ResponseWriter, r *http.Request) {
// Read body
task := &controllers.GenericTask{}
_, err := util.ReadBody(r, task)
if err != nil {
util.RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}

ret, err := task.Search()
if err != nil {
util.RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}

util.RespondWithJSON(w, http.StatusOK, ret)
}

func (api *AppAPI) list(w http.ResponseWriter, r *http.Request) {
Expand Down
13 changes: 10 additions & 3 deletions pkg/server/web/controllers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ type CreateTask struct {
}

func (c *CreateTask) Handle(data string) error {
err := dao.CreateTask(data)
// check the validity of the data
createTask := &CreateTask{}
err := json.Unmarshal([]byte(data), createTask)
if err != nil {
return err
}

err = dao.CreateTask(data)
if err != nil {
return err
}
Expand Down Expand Up @@ -147,8 +154,8 @@ func (g *GenericTask) Stop(masterAddr string) error {
return nil
}

func (task *GenericTask) Search() error {
return nil
func (g *GenericTask) Search() (*dao.Task, error) {
return dao.SearchTask(g.ID)
}

func ListTask() ([]dao.Task, error) {
Expand Down

0 comments on commit 3130bbf

Please sign in to comment.