|
|
@ -30,6 +30,12 @@ var routes = Routes{ |
|
|
|
"/user", |
|
|
|
NewUser, |
|
|
|
}, |
|
|
|
Route{ |
|
|
|
"SelectItem", |
|
|
|
"GET", |
|
|
|
"/selectItem/{userid}/{itemid}", |
|
|
|
SelectItem, |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
//ROUTES
|
|
|
@ -39,6 +45,7 @@ func Index(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
|
|
|
|
func NewUser(w http.ResponseWriter, r *http.Request) { |
|
|
|
ipFilter(w, r) |
|
|
|
decoder := json.NewDecoder(r.Body) |
|
|
|
var newUser UserModel |
|
|
|
err := decoder.Decode(&newUser) |
|
|
@ -51,6 +58,7 @@ func NewUser(w http.ResponseWriter, r *http.Request) { |
|
|
|
fmt.Fprintln(w, "new user added: ", newUser.ID) |
|
|
|
} |
|
|
|
func Recommendations(w http.ResponseWriter, r *http.Request) { |
|
|
|
ipFilter(w, r) |
|
|
|
vars := mux.Vars(r) |
|
|
|
userid := vars["userid"] |
|
|
|
nrec, err := strconv.Atoi(vars["nrec"]) |
|
|
@ -61,3 +69,38 @@ func Recommendations(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
fmt.Fprintln(w, "recommendations") |
|
|
|
} |
|
|
|
func SelectItem(w http.ResponseWriter, r *http.Request) { |
|
|
|
ipFilter(w, r) |
|
|
|
vars := mux.Vars(r) |
|
|
|
userid := vars["userid"] |
|
|
|
itemid := vars["itemid"] |
|
|
|
//find item
|
|
|
|
item, err := getItemById(itemid) |
|
|
|
if err != nil { |
|
|
|
fmt.Fprintln(w, "item "+itemid+" not found") |
|
|
|
} |
|
|
|
|
|
|
|
//increase TActed in item
|
|
|
|
item.TActed = item.TActed + 1 |
|
|
|
|
|
|
|
//save item
|
|
|
|
item, err = updateItem(item) |
|
|
|
check(err) |
|
|
|
fmt.Println(item) |
|
|
|
|
|
|
|
//find user
|
|
|
|
user, err := getUserById(userid) |
|
|
|
if err != nil { |
|
|
|
fmt.Fprintln(w, "user "+userid+" not found") |
|
|
|
} |
|
|
|
|
|
|
|
//add item to []Actions of user
|
|
|
|
user.Actions = append(user.Actions, itemid) |
|
|
|
|
|
|
|
//save user
|
|
|
|
user, err = updateUser(user) |
|
|
|
check(err) |
|
|
|
fmt.Println(user) |
|
|
|
|
|
|
|
fmt.Fprintln(w, "user: "+userid+", selects item: "+itemid) |
|
|
|
} |