コード例 #1
0
func Create(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	var ch channel.Channel
	if err := json.Unmarshal([]byte(r.FormValue("channel")), &ch); err != nil {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
	userId := context.Get(r, "user_id").(int)

	channel := channel.Create(ch.OwnerId, ch.Name, ch.Description)
	channeldetail.Create(userId, channel.Id)

	responseJson, responseCode := helper.GetResponseJson(channel)
	middleware.Output.Response = responseJson
	middleware.Output.ResponseCode = responseCode
}
コード例 #2
0
func Create(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	channelIdStr := r.FormValue("channel_id")
	userId := context.Get(r, "user_id").(int)

	if helper.IsValidRequest(channelIdStr) {
		channelId, _ := strconv.Atoi(channelIdStr)
		channelDetail := channeldetail.Create(userId, channelId)
		if channelDetail != (channeldetail.ChannelDetail{}) {
			channel.Update(channelId, 1)
			responseJson, responseCode := helper.GetResponseJson(channelDetail)
			middleware.Output.Response = responseJson
			middleware.Output.ResponseCode = responseCode
		}
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}