コード例 #1
0
ファイル: program.go プロジェクト: naikparag/lego
func (this *CCProgramHandler) AddProgram(c *gin.Context) error {

	program := models.CCProgram{}
	title := c.Query("title")
	thread_name := c.Query("thread_name")
	genre := c.Query("genre")
	volunteers := c.Query("volunteers")
	locality := c.Query("locality")
	city := c.Query("city")
	image := c.Query("image")
	description := c.Query("description")
	// Int variables

	fmt.Println("Data set to variables")

	// Generate unique id
	id_str := util.GenarateId(16, "number")

	program = models.CCProgram{
		Id: id_str, Creation_date: time.Now(), Title: title, Thread_name: thread_name, Volunteers: volunteers, Genre: genre, Locality: locality, City: city, Image: image, Description: description,
	}
	fmt.Println("Data set to program model")
	fmt.Println("Db session open ")
	err := dbObj.Insert(program)

	if err != nil {
		fmt.Println("Data insertion failed ", err.Error())
		panic(err)
		return err
	}

	return nil
}
コード例 #2
0
ファイル: user.go プロジェクト: naikparag/lego
func (this *CCUserHandler) AddUser(c *gin.Context) error {

	user := models.CCUser{}
	firstName := c.Query("firstname")
	lastName := c.Query("lastname")
	username := c.Query("username")
	password := c.Query("password")
	email_id := c.Query("email_id")
	image := c.Query("image")
	//Encryp
	password_enc := util.Encrypt(password)

	fmt.Println("Data set to variables")

	id_str := util.GenarateId(16, "number")
	if firstName != "" && lastName != "" && username != "" && email_id != "" {
		user = models.CCUser{Id: id_str, Firstname: firstName, Lastname: lastName, Username: username, Password: password_enc, Email_id: email_id, Image: image}
		fmt.Println("Data set to user model")

		fmt.Println("Db session open ")

		err := dbObj.Insert(user)

		if err != nil {
			fmt.Println("Data insertion failed ", err.Error())
			panic(err)
			return err
		}
	}
	return nil
}
コード例 #3
0
ファイル: event.go プロジェクト: naikparag/lego
func (this *CCEventHandler) AddEvent(c *gin.Context) error {
	this.Load()
	event := models.CCEvent{}
	title := c.Query("title")
	program_id := c.Query("program_id")
	created_by := c.Query("created_by")
	participants := c.Query("participants")
	volunteers := c.Query("volunteers")
	date := c.Query("date")
	duration := c.Query("duration")
	location := c.Query("location")
	image := c.Query("image")
	contact := c.Query("contact")
	layout := "2006-01-02"
	tm_Date, _ := time.Parse(layout, date)

	fmt.Println("Data set to variables")

	id_str := util.GenarateId(16, "number")

	event = models.CCEvent{Id: id_str, Program_Id: program_id, Title: title, Created_by: created_by, Created_on: time.Now(), Participants: participants, Volunteers: volunteers, Date: tm_Date, Duration: duration, Location: location, Image: image, Contact: contact}
	fmt.Println("Data set to event model")

	fmt.Println("Db session open ")

	err := dbObj.Insert(event)

	if err != nil {
		fmt.Println("Data insertion failed ", err.Error())
		panic(err)
		return err
	}

	return nil
}
コード例 #4
0
ファイル: volunteer.go プロジェクト: naikparag/lego
func (this *CCVolunteerHandler) AddVolunteer(c *gin.Context) error {

	user_id := c.Query("user_id")
	event_id := c.Query("event_id")
	role := c.Query("role")

	if user_id != "" {
		_, err := userHandler.FetchUserById(user_id)
		if err != nil {
			fmt.Println("User id not exist: ")
			return err
		}
	}

	event, err := eventHandler.FetchEvent(event_id)
	if err != nil {
		fmt.Println("Events id not exist: ")
		return err
	}

	volunteer := models.CCVolunteer{}
	program_id := event.Program_Id

	if role == "" {
		role = "common"
	}

	fmt.Println("Data set to variables")
	this.Load()

	id_str := util.GenarateId(8, "number")
	if user_id != "" && event_id != "" {
		volunteer = models.CCVolunteer{Id: id_str, User_id: user_id, Program_id: program_id, Event_id: event_id, Role: role, Creation_date: time.Now()}
		fmt.Println("Data set to volunteer model")

		fmt.Println("Db session open ")

		err := dbObj.Insert(volunteer)

		if err != nil {
			fmt.Println("Data insertion failed ", err.Error())
			return err
		}
	}
	return nil
}
コード例 #5
0
ファイル: moment.go プロジェクト: naikparag/lego
func (this *CCMomentHandler) AddMoment(c *gin.Context) error {

	moment := models.CCMoment{}
	volunteerId := c.Query("volunteer_id")
	image := c.Query("image")
	comment := c.Query("comment")

	if volunteerId == "" {
		errE := util.NewError("Volunteer Id is blank")
		return errE
	}
	if comment == "" {
		errE := util.NewError("Comment is blank")
		return errE
	}
	volunteer, err := volHandler.FetchVolunteerForId(volunteerId)
	if err != nil {
		fmt.Println("volunteer id not exist: ")
		return err
	}

	fmt.Println("Data set to variables")

	id_str := util.GenarateId(16, "number")
	this.Load()

	moment = models.CCMoment{Id: id_str, Volunteer_id: volunteerId, Event_id: volunteer.Event_id, Image: image, Comment: comment, Creation_date: time.Now()}
	fmt.Println("Data set to moment model")

	fmt.Println("Db session open ")

	err = dbObj.Insert(moment)

	if err != nil {
		fmt.Println("Data insertion failed ", err.Error())
		return err
	}

	return nil
}