예제 #1
0
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
	}
}
예제 #2
0
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 channelDetails []channeldetail.ChannelDetail

	if strings.EqualFold(requestType, "id") {
		channelDetails = channeldetail.Read(userId)
	} else if strings.EqualFold(requestType, "channel") {
		if helper.IsValidRequest(channelIdStr) {
			channelId, _ := strconv.Atoi(channelIdStr)
			channelDetails = channeldetail.ReadByChannel(channelId)
		}
	} else {
		channelDetails = nil
	}
	if channelDetails != nil {
		responseJson, responseCode := helper.GetResponseJson(channelDetails)
		middleware.Output.Response = responseJson
		middleware.Output.ResponseCode = responseCode
	} else {
		middleware.Output.ResponseCode = http.StatusBadRequest
	}
}
예제 #3
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
	}
}
예제 #4
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
}
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
	}
}
예제 #7
0
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
	}
}
예제 #9
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
	}
}
예제 #10
0
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 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
	}
}