func Read(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { requestType := r.FormValue("request_type") channelIdStr := r.FormValue("channel_id") userId := context.Get(r, "user_id").(int) var channels []channel.Channel if strings.EqualFold(requestType, "owner") { channels = channel.Read(userId) } else if strings.EqualFold(requestType, "id") { if helper.IsValidRequest(channelIdStr) { channelId, _ := strconv.Atoi(channelIdStr) channels = channel.ReadById(channelId) } } else { channels = nil } if channels != nil { responseJson, responseCode := helper.GetResponseJson(channels) middleware.Output.Response = responseJson middleware.Output.ResponseCode = responseCode } else { middleware.Output.ResponseCode = http.StatusBadRequest } }
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) } } } }