Example #1
0
func ListProfile(c *gin.Context) {
	conn := store.New(c)

	prof_list := make([]Profile, 0)
	out_list := make([]ProfileOut, 0)
	conn.List(&prof_list)

	var prof Profile

	for _, prof = range prof_list {
		if auth.IsAuthorized(c, prof.Consti) {
			var pout_t ProfileOut
			det_list := &datastore.PropertyList{}
			conn.PropListGet(det_list, prof.Parent)
			pout_t.Details = PropertyListToMap(det_list)
			pout_t.Details["id"] = prof.Parent.IntID()
			pout_t.Comments = prof.Comments
			pout_t.Surveys = prof.Surveys
			pout_t.Consti = prof.Consti
			pout_t.Id = prof.Id
			pout_t.Meta = prof.Meta
			pout_t.Likes = prof.Likes
			pout_t.UnLikes = prof.UnLikes
			out_list = append(out_list, pout_t)
		}

	}

	auth.SessionSave(c)
	c.JSON(http.StatusOK, out_list)
}
Example #2
0
func AddComment(c *gin.Context) {

	var prof_in *Profile
	status := http.StatusOK
	if auth.IsAuthenticated(c) {

		conn := store.New(c)
		var comment Comment
		c.BindJSON(&comment)

		prof_id, _ := strconv.ParseInt(comment.Prof_Id, 10, 64)
		det_id, _ := strconv.ParseInt(comment.Det_Id, 10, 64)
		det_key := conn.DatastoreKeyWithKind("ProfileDetails", det_id)
		prof_in = &Profile{Id: prof_id, Parent: det_key}
		conn.Get(prof_in)

		comment.Id = uuid.NewV4().String()
		comment.Time = time.Now().Format("2006-01-02 15-04-05")
		comment.Author = auth.GetUser(c).Name
		prof_in.Comments = append(prof_in.Comments, comment)
		conn.Add(prof_in)

		status = http.StatusOK

	} else {
		auth.SessionSave(c)
		auth.Login(c)
	}

	c.JSON(status, prof_in.Comments)
}
Example #3
0
func PutSampleProfile(c *gin.Context) {

	conn := store.New(c)
	status := http.StatusOK

	if auth.IsAuthorized(c, "admin") {
		prof_id, _ := strconv.ParseInt(c.Param("prof_id"), 10, 64)
		det_id, _ := strconv.ParseInt(c.Param("det_id"), 10, 64)
		det_key := conn.DatastoreKeyWithKind("ProfileDetails", det_id)
		det_list := &datastore.PropertyList{}
		conn.PropListGet(det_list, det_key)
		prof_in := &Profile{Id: prof_id, Parent: det_key}

		conn.Get(prof_in)

		for _, consti := range kyp.GetConstis() {
			prof_in.Id = 0
			prof_in.Consti = consti
			prof_in.Comments = make([]Comment, 0)
			prof_in.Likes = 0
			prof_in.UnLikes = 0
			prof_in.Status = "sample"
			s_det_key := conn.DatastoreKeyWithKind("ProfileDetails", 0)
			det_key = conn.PropListPut(det_list, s_det_key)
			prof_in.Parent = det_key
			for i, _ := range prof_in.Surveys {
				prof_in.Surveys[i].Id = uuid.NewV4().String()
				prof_in.Surveys[i].Prof_Id = ""
				prof_in.Surveys[i].Det_Id = ""
				prof_in.Surveys[i].Likes = 0
				prof_in.Surveys[i].UnLikes = 0
			}
			conn.Add(prof_in)

		}

	} else {
		status = http.StatusUnauthorized
	}

	auth.SessionSave(c)
	c.JSON(status, gin.H{"msg": "succesfully loaded"})

}
Example #4
0
func DeleteProfile(c *gin.Context) {

	conn := store.New(c)
	status := http.StatusOK
	var resp store.Response
	prof_id, _ := strconv.ParseInt(c.Param("prof_id"), 10, 64)
	det_id, _ := strconv.ParseInt(c.Param("det_id"), 10, 64)
	det_key := conn.DatastoreKeyWithKind("ProfileDetails", det_id)
	prof_in := &Profile{Id: prof_id, Parent: det_key}

	conn.Get(prof_in)

	if auth.IsAuthorized(c, prof_in.Consti) {
		log.Debugf(conn.Context, fmt.Sprintf("profiles %#v", prof_in))
		resp = conn.Remove(conn.Goon.Key(prof_in))
		resp = conn.Remove(prof_in.Parent)

	} else {
		status = http.StatusUnauthorized
	}

	auth.SessionSave(c)
	c.JSON(status, resp)
}
Example #5
0
func PutProfile(c *gin.Context) {

	conn := store.New(c)
	status := http.StatusOK

	prof_out := &ProfileOut{}
	c.BindJSON(prof_out)

	var resp store.Response
	keys := make(map[string]int64)

	if auth.IsAuthorized(c, prof_out.Consti) {
		det_id := NumberToInt(prof_out.Details["id"])
		det_key := conn.DatastoreKeyWithKind("ProfileDetails", det_id)
		det_list := &datastore.PropertyList{}
		log.Debugf(conn.Context, fmt.Sprintf("before conv %#v", det_list))
		det_list = MapToPropertyList(prof_out.Details)
		log.Debugf(conn.Context, fmt.Sprintf("after conv %#v", det_list))
		det_key = conn.PropListPut(det_list, det_key)
		log.Debugf(conn.Context, fmt.Sprintf("details %#v", det_list))

		prof_in := &Profile{Id: prof_out.Id, Parent: det_key}
		conn.Get(prof_in)
		prof_in.Parent = det_key
		prof_in.Comments = prof_out.Comments
		prof_in.Surveys = prof_out.Surveys
		if prof_in.Comments == nil {
			prof_in.Comments = make([]Comment, 0)
		}
		if prof_in.Surveys == nil {
			prof_in.Surveys = make([]Survey, 0)
		} else {
			for i, surv := range prof_in.Surveys {
				if surv.Id == "" {
					prof_in.Surveys[i].Id = uuid.NewV4().String()
				}
			}
		}
		prof_in.Consti = prof_out.Consti
		prof_in.Meta = prof_out.Meta
		resp = conn.Add(prof_in)

		keys["prof_id"] = resp.Data.(*datastore.Key).IntID()
		keys["det_id"] = det_key.IntID()

		for i, surv := range prof_in.Surveys {
			if surv.Prof_Id == "" {
				t_p_id := strconv.FormatInt(keys["prof_id"], 10)
				t_det_id := strconv.FormatInt(keys["det_id"], 10)
				prof_in.Surveys[i].Prof_Id = t_p_id
				prof_in.Surveys[i].Det_Id = t_det_id
			}
		}
		conn.Add(prof_in)
		log.Debugf(conn.Context, fmt.Sprintf("%#v", prof_in))

	} else {
		status = http.StatusUnauthorized
	}

	auth.SessionSave(c)
	c.JSON(status, keys)

}
Example #6
0
func ProcessVolunteerRequest(c *gin.Context) {
	req_id := c.Param("req_id")
	auth.SessionSet(c, "vol_req_id", req_id)
	auth.SessionSave(c)
	c.Redirect(http.StatusTemporaryRedirect, "/login")
}