Implement Create for Question
This commit is contained in:
parent
d547cf320e
commit
fea4b6902b
1 changed files with 24 additions and 2 deletions
|
@ -1,8 +1,10 @@
|
|||
package orm
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"net/http"
|
||||
|
||||
"git.andreafazzi.eu/andrea/oef/renderer"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
type Question struct {
|
||||
|
@ -18,7 +20,20 @@ func (q *Question) String() string {
|
|||
}
|
||||
|
||||
func (q *Question) Create(args map[string]string, r *http.Request) (interface{}, error) {
|
||||
return nil, nil
|
||||
if r.Method == "GET" {
|
||||
return make([]*Question, 0), nil
|
||||
} else {
|
||||
question := new(Question)
|
||||
err := renderer.Decode(question, r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
question, err = CreateQuestion(question)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return question, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Question) Read(args map[string]string, r *http.Request) (interface{}, error) {
|
||||
|
@ -40,3 +55,10 @@ func (q *Question) Update(args map[string]string, r *http.Request) (interface{},
|
|||
func (q *Question) Delete(args map[string]string, r *http.Request) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CreateQuestion(question *Question) (*Question, error) {
|
||||
if err := DB().Create(question).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return question, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue