func Read(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	requestType := r.FormValue("request_type")
	objectLikeIdStr := r.FormValue("object_like_id")
	objectIdStr := r.FormValue("object_id")
	objectType := r.FormValue("object_type")
	userId := context.Get(r, "user_id").(int)

	var objectLikes []objectlike.ObjectLike

	if strings.EqualFold(requestType, "user") {
		objectLikes = objectlike.Read(userId)
	} else if strings.EqualFold(requestType, "object") {
		if helper.IsValidRequest(objectIdStr) {
			objectId, _ := strconv.Atoi(objectIdStr)
			objectLikes = objectlike.ReadByObject(objectId, objectType)
		}
	} else if strings.EqualFold(requestType, "id") {
		if helper.IsValidRequest(objectLikeIdStr) {
			objectLikeId, _ := strconv.Atoi(objectLikeIdStr)
			objectLikes = objectlike.ReadById(objectLikeId)
		}
	}
	if objectLikes != nil {
		responseJson, responseCode := helper.GetResponseJson(objectLikes)
		middleware.Output.Response = responseJson
		middleware.Output.ResponseCode = responseCode
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}
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 channelshareobjects []channelshareobject.ChannelShareObject

	if strings.EqualFold(requestType, "id") {
		if helper.IsValidRequest(channelIdStr) {
			channelId, _ := strconv.Atoi(channelIdStr)
			channelshareobjects = channelshareobject.Read(channelId, userId)
		}
	} else if strings.EqualFold(requestType, "channel") {
		if helper.IsValidRequest(channelIdStr) {
			channelId, _ := strconv.Atoi(channelIdStr)
			channelshareobjects = channelshareobject.ReadByChannel(channelId)
		}
	} else {
		channelshareobjects = nil
	}
	if channelshareobjects != nil {
		responseJson, responseCode := helper.GetResponseJson(channelshareobjects)
		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)
		channel.DeleteById(channelId, userId)
	}
}
func Create(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	channelIdStr := r.FormValue("channel_id")
	objectIdStr := r.FormValue("object_id")
	objectType := r.FormValue("object_type")
	message := r.FormValue("message")
	userId := context.Get(r, "user_id").(int)

	if helper.IsValidRequest(channelIdStr, objectIdStr, objectType) || helper.IsValidRequest(channelIdStr, message) {
		channelId, _ := strconv.Atoi(channelIdStr)
		objectId, _ := strconv.Atoi(objectIdStr)
		channelshareobject := channelshareobject.Create(userId, channelId, objectId, objectType, message)
		responseJson, responseCode := helper.GetResponseJson(channelshareobject)
		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) {
	requestType := r.FormValue("request_type")
	objectLikeIdStr := r.FormValue("object_like_id")
	objectIdStr := r.FormValue("object_id")
	objectType := r.FormValue("object_type")
	userId := context.Get(r, "user_id").(int)

	if strings.EqualFold(requestType, "object") {
		if helper.IsValidRequest(objectIdStr) {
			objectId, _ := strconv.Atoi(objectIdStr)
			objectlike.Delete(userId, objectId, objectType)
		}
	} else if strings.EqualFold(requestType, "id") {
		if helper.IsValidRequest(objectLikeIdStr) {
			objectLikeId, _ := strconv.Atoi(objectLikeIdStr)
			objectlike.DeleteById(objectLikeId)
		}
	}
}
Exemple #6
0
func Create(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	email := r.FormValue("email")

	if helper.IsValidRequest(email) {
		user := user.Create(email)

		responseJson, responseCode := helper.GetResponseJson(user)
		middleware.Output.Response = responseJson
		middleware.Output.ResponseCode = responseCode
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}
func Update(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	channelIdStr := r.FormValue("channel_id")
	name := r.FormValue("name")

	if helper.IsValidRequest(channelIdStr) {
		channelId, _ := strconv.Atoi(channelIdStr)
		channelProperty := channelproperty.Read(channelId, name)
		responseJson, responseCode := helper.GetResponseJson(channelProperty)
		middleware.Output.Response = responseJson
		middleware.Output.ResponseCode = responseCode
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}
func Update(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	commentIdStr := r.FormValue("comment_id")
	comment := r.FormValue("comment")

	if helper.IsValidRequest(commentIdStr) {
		commentId, _ := strconv.Atoi(commentIdStr)
		objectComment := objectcomment.Update(commentId, comment)
		responseJson, responseCode := helper.GetResponseJson(objectComment)
		middleware.Output.Response = responseJson
		middleware.Output.ResponseCode = responseCode
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}
func Read(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	objectIdStr := r.FormValue("object_id")
	objectType := r.FormValue("object_type")

	if helper.IsValidRequest(objectIdStr, objectType) {
		objectId, _ := strconv.Atoi(objectIdStr)
		objectDetail := objectdetail.Read(objectId, objectType)

		responseJson, responseCode := helper.GetResponseJson(objectDetail)
		middleware.Output.Response = responseJson
		middleware.Output.ResponseCode = responseCode
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}
func Create(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	channelIdStr := r.FormValue("channel_id")
	name := r.FormValue("name")
	value := r.FormValue("value")
	userId := context.Get(r, "user_id").(int)

	if helper.IsValidRequest(channelIdStr, name) {
		channelId, _ := strconv.Atoi(channelIdStr)
		channelProperty := channelproperty.Create(channelId, userId, name, value)
		responseJson, responseCode := helper.GetResponseJson(channelProperty)
		middleware.Output.Response = responseJson
		middleware.Output.ResponseCode = responseCode
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}
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
	}
}
func Create(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	objectIdStr := r.FormValue("object_id")
	objectType := r.FormValue("object_type")
	userId := context.Get(r, "user_id").(int)

	if helper.IsValidRequest(objectIdStr, objectType) {
		objectId, _ := strconv.Atoi(objectIdStr)

		objectLike := objectlike.Create(userId, objectId, objectType)

		responseJson, responseCode := helper.GetResponseJson(objectLike)
		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)
			}
		}
	}
}