Beispiel #1
0
Datei: topics.go Projekt: ovh/tat
// Create creates a new topic
func (*TopicsController) Create(ctx *gin.Context) {
	var topicIn tat.TopicCreateJSON
	ctx.Bind(&topicIn)

	var user = tat.User{}
	found, err := userDB.FindByUsername(&user, getCtxUsername(ctx))
	if !found {
		ctx.JSON(http.StatusUnauthorized, gin.H{"error": "User unknown"})
		return
	} else if err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Error while fetching user."})
		return
	}

	var topic tat.Topic
	topic.Topic = topicIn.Topic
	topic.Description = topicIn.Description

	err = topicDB.Insert(&topic, &user)
	if err != nil {
		log.Errorf("Error while InsertTopic %s", err)
		ctx.JSON(tat.Error(err))
		return
	}
	ctx.JSON(http.StatusCreated, topic)
}
Beispiel #2
0
Datei: topic.go Projekt: ovh/tat
// CheckAndFixName Add a / to topic name is it is not present
// return an error if length of name is < 4 or > 100
func CheckAndFixName(topic *tat.Topic) error {
	name, err := tat.CheckAndFixNameTopic(topic.Topic)
	if err != nil {
		return err
	}
	topic.Topic = name
	return nil
}
Beispiel #3
0
func insertTopicDM(userFrom, userTo tat.User) (tat.Topic, error) {
	var topic = tat.Topic{}
	topicName := "/Private/" + userFrom.Username + "/DM/" + userTo.Username
	topic.Topic = topicName
	topic.Description = userTo.Fullname
	if err := topicDB.Insert(&topic, &userFrom); err != nil {
		log.Errorf("Error while InsertTopic %s", err)
		return topic, err
	}
	return topic, nil
}