Exemplo n.º 1
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)
		channel.DeleteById(channelId, userId)
	}
}
Exemplo n.º 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)
			}
		}
	}
}