コード例 #1
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
	}
}
コード例 #2
0
func Delete(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)
		channels := channel.ReadById(channelId)
		if channels[0].OwnerId == userId {
			channeldetail.DeleteByChannel(channelId)
			channel.DeleteById(channelId, userId)
		} else {
			isDelete := channeldetail.Delete(userId, channelId)
			if isDelete {
				channel.Update(channelId, -1)
			}
		}
	}
}