예제 #1
0
func PlatinumEtailers(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	cust, err := customer.GetWhereToBuyDealers(dtx)
	if err != nil {
		apierror.GenerateError("Error retrieving platinum etailers.", err, w, r)
	}
	return encoding.Must(enc.Encode(cust))
}
예제 #2
0
파일: salesrep.go 프로젝트: ninnemana/API
func GetAllSalesReps(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder) string {
	reps, err := salesrep.GetAllSalesReps()
	if err != nil {
		apierror.GenerateError("Trouble getting all sales reps", err, rw, req)
	}
	return encoding.Must(enc.Encode(reps))
}
예제 #3
0
func Search(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var err error

	title := r.FormValue("title")
	slug := r.FormValue("slug")
	text := r.FormValue("text")
	createdDate := r.FormValue("createdDate")
	publishedDate := r.FormValue("publishedDate")
	lastModified := r.FormValue("lastModified")
	userID := r.FormValue("userID")
	metaTitle := r.FormValue("metaTitle")
	metaDescription := r.FormValue("metaDescription")
	keywords := r.FormValue("keywords")
	active := r.FormValue("active")

	page := r.FormValue("page")
	results := r.FormValue("results")

	l, err := blog_model.Search(title, slug, text, publishedDate, createdDate, lastModified, userID, metaTitle, metaDescription, keywords, active, page, results, dtx)
	if err != nil {
		apierror.GenerateError("Trouble searching for blog", err, rw, r)
	}

	return encoding.Must(enc.Encode(l))
}
예제 #4
0
파일: menu.go 프로젝트: ninnemana/API
func GetAllMenus(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	m, err := site.GetAllMenus(dtx)
	if err != nil {
		apierror.GenerateError("Trouble getting all site menus", err, rw, req)
	}
	return encoding.Must(enc.Encode(m))
}
예제 #5
0
파일: menu.go 프로젝트: ninnemana/API
func SaveMenu(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	var m site.Menu
	var err error
	idStr := params["id"]
	if idStr != "" {
		m.Id, err = strconv.Atoi(idStr)
		err = m.Get(dtx)
		if err != nil {
			apierror.GenerateError("Trouble getting site menu ID", err, rw, req)
		}
	}

	//json
	requestBody, err := ioutil.ReadAll(req.Body)
	if err != nil {
		apierror.GenerateError("Trouble reading request body for saving site menu", err, rw, req)
	}
	err = json.Unmarshal(requestBody, &m)
	if err != nil {
		apierror.GenerateError("Trouble unmarshalling request body for saving site menu", err, rw, req)
	}
	//create or update
	if m.Id > 0 {
		err = m.Update()
	} else {
		err = m.Create()
	}

	if err != nil {
		apierror.GenerateError("Trouble saving site menu", err, rw, req)
	}
	return encoding.Must(enc.Encode(m))
}
예제 #6
0
파일: account.go 프로젝트: ninnemana/API
// Create a customer for a
// given shop.
func AddAccount(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop) string {

	var c cart.Customer
	defer req.Body.Close()

	data, err := ioutil.ReadAll(req.Body)
	if err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	if err = json.Unmarshal(data, &c); err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	c.ShopId = shop.Id

	if err = c.Insert(req.Referer()); err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	return encoding.Must(enc.Encode(c))
}
예제 #7
0
파일: groups.go 프로젝트: ninnemana/API
func GetAllGroups(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	groups, err := forum.GetAllGroups(dtx)
	if err != nil {
		apierror.GenerateError("Trouble getting all forum groups", err, rw, req)
	}
	return encoding.Must(enc.Encode(groups))
}
예제 #8
0
// GetCategory
func GetCategory(rw http.ResponseWriter, r *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var c category.Category
	var err error
	c.CategoryID, err = strconv.Atoi(params["id"])
	if err != nil || c.CategoryID == 0 {
		apierror.GenerateError("Trouble getting category identifier", err, rw, r)
		return ""
	}

	qs := r.URL.Query()
	page := 1
	count := 50
	if pg := qs.Get("page"); pg != "" {
		page, _ = strconv.Atoi(pg)
	}
	if ct := qs.Get("count"); ct != "" {
		count, _ = strconv.Atoi(ct)
	}

	err = c.Get(page, count)
	if err != nil || c.CategoryID == 0 {
		apierror.GenerateError("Trouble getting category", err, rw, r)
		return ""
	}

	return encoding.Must(enc.Encode(c))
}
예제 #9
0
func GetCategoryParts(rw http.ResponseWriter, r *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	catIdStr := params["id"]
	catId, err := strconv.Atoi(catIdStr)
	if err != nil {
		apierror.GenerateError("Trouble getting category Id", err, rw, r)
		return ""
	}

	qs := r.URL.Query()
	page := 1
	count := 50
	if pg := qs.Get("page"); pg != "" {
		page, _ = strconv.Atoi(pg)
	}
	if ct := qs.Get("count"); ct != "" {
		count, _ = strconv.Atoi(ct)
	}

	parts, err := category.GetCategoryParts(catId, page, count)
	if err != nil {
		apierror.GenerateError("Trouble getting parts", err, rw, r)
		return ""
	}

	return encoding.Must(enc.Encode(parts))
}
예제 #10
0
func CreateApplication(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext, params martini.Params) string {
	var app products.NoSqlVehicle
	collection := params["collection"]
	if collection == "" {
		apierror.GenerateError("No Collection in URL", nil, w, r)
		return ""
	}

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		apierror.GenerateError("Error reading request body", nil, w, r)
		return ""
	}

	if err = json.Unmarshal(body, &app); err != nil {
		apierror.GenerateError("Error decoding vehicle application", nil, w, r)
		return ""
	}

	if err = app.Create(collection); err != nil {
		apierror.GenerateError("Error updating vehicle", nil, w, r)
		return ""
	}
	return encoding.Must(enc.Encode(app))
}
예제 #11
0
파일: topics.go 프로젝트: ninnemana/API
func AddTopic(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var err error
	var topic forum.Topic

	if topic.GroupID, err = strconv.Atoi(req.FormValue("groupID")); err != nil {
		apierror.GenerateError("Trouble getting forum group ID for new topic", err, rw, req)
	}

	if req.FormValue("closed") != "" {
		if topic.Closed, err = strconv.ParseBool(req.FormValue("closed")); err != nil {
			apierror.GenerateError("Trouble adding forum topic -- boolean closed parameter is invalid", err, rw, req)
		}
	}

	topic.Name = req.FormValue("name")
	topic.Description = req.FormValue("description")
	topic.Image = req.FormValue("image")
	topic.Active = true

	if err = topic.Add(); err != nil {
		apierror.GenerateError("Trouble adding forum topic", err, rw, req)
	}

	return encoding.Must(enc.Encode(topic))
}
예제 #12
0
파일: brand.go 프로젝트: ninnemana/API
func UpdateBrand(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder) string {
	var err error
	var br brand.Brand

	if br.ID, err = strconv.Atoi(params["id"]); err != nil {
		apierror.GenerateError("Trouble getting brand ID", err, rw, req)
	}

	if err = br.Get(); err != nil {
		apierror.GenerateError("Trouble getting brand", err, rw, req)
	}

	if req.FormValue("name") != "" {
		br.Name = req.FormValue("name")
	}

	if req.FormValue("code") != "" {
		br.Code = req.FormValue("code")
	}

	if err := br.Update(); err != nil {
		apierror.GenerateError("Trouble updating brand", err, rw, req)
	}

	return encoding.Must(enc.Encode(br))
}
예제 #13
0
파일: brand.go 프로젝트: ninnemana/API
func GetAllBrands(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder) string {
	brands, err := brand.GetAllBrands()
	if err != nil {
		apierror.GenerateError("Trouble getting all brands", err, rw, req)
	}
	return encoding.Must(enc.Encode(brands))
}
예제 #14
0
파일: content.go 프로젝트: ninnemana/API
func GetContent(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	var c site.Content
	var err error
	idStr := params["id"]
	id, err := strconv.Atoi(idStr)

	if err == nil {
		//Thar be an Id int
		c.Id = id
		err = c.Get(dtx)
		if err != nil {
			apierror.GenerateError("Trouble getting site content by Id.", err, rw, req)
			return ""
		}
	}

	//Thar be a slug
	c.Slug = idStr
	err = c.GetBySlug(dtx)
	if err != nil {
		apierror.GenerateError("Trouble getting site content by slug.", err, rw, req)
		return ""
	}

	return encoding.Must(enc.Encode(c))
}
예제 #15
0
func Create(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var n news_model.News
	var err error

	n.Title = r.FormValue("title")
	n.Lead = r.FormValue("lead")
	n.Content = r.FormValue("content")
	start := r.FormValue("start")
	end := r.FormValue("end")
	active := r.FormValue("active")
	n.Slug = r.FormValue("slug")
	if start != "" {
		n.PublishStart, err = time.Parse(timeFormat, start)
	}
	if end != "" {
		n.PublishEnd, err = time.Parse(timeFormat, end)
	}
	if active != "" {
		n.Active, err = strconv.ParseBool(active)
	}
	err = n.Create(dtx)
	if err != nil {
		apierror.GenerateError("Trouble creating news", err, rw, r)
		return ""
	}
	return encoding.Must(enc.Encode(n))
}
예제 #16
0
func Update(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	var f faq_model.Faq
	var err error

	idStr := r.FormValue("id")
	if idStr != "" {
		f.ID, err = strconv.Atoi(idStr)
		if err != nil {
			apierror.GenerateError("Trouble getting faq ID", err, rw, r)
		}
	} else {
		f.ID, err = strconv.Atoi(params["id"])
		if err != nil {
			apierror.GenerateError("Trouble getting faq ID", err, rw, r)
		}
	}
	f.Get(dtx)
	question := r.FormValue("question")
	answer := r.FormValue("answer")
	if question != "" {
		f.Question = question
	}
	if answer != "" {
		f.Answer = answer
	}

	err = f.Update(dtx)
	if err != nil {
		apierror.GenerateError("Trouble updating faq", err, rw, r)
	}
	return encoding.Must(enc.Encode(f))
}
예제 #17
0
func Lookup(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var v products.NoSqlVehicle
	var collection string //e.g. interior/exterior

	//Get collection
	collection = r.FormValue("collection")
	delete(r.Form, "collection")

	// Get vehicle year
	v.Year = r.FormValue("year")
	delete(r.Form, "year")

	// Get vehicle make
	v.Make = r.FormValue("make")
	delete(r.Form, "make")

	// Get vehicle model
	v.Model = r.FormValue("model")
	delete(r.Form, "model")

	// Get vehicle submodel
	v.Style = r.FormValue("style")
	delete(r.Form, "style")

	l, err := products.FindVehicles(v, collection, dtx)
	if err != nil {
		apierror.GenerateError("Trouble finding vehicles.", err, w, r)
		return ""
	}

	return encoding.Must(enc.Encode(l))
}
예제 #18
0
파일: customer.go 프로젝트: ninnemana/API
// Edit an existing customer for a
// given shop.
func EditCustomer(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop) string {

	var c cart.Customer
	defer req.Body.Close()

	data, err := ioutil.ReadAll(req.Body)
	if err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	if err = json.Unmarshal(data, &c); err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	customerId := params["id"]

	if !bson.IsObjectIdHex(customerId) {
		apierror.GenerateError("invalid customer reference", nil, w, req)
		return ""
	}
	c.Id = bson.ObjectIdHex(customerId)
	c.ShopId = shop.Id

	if err = c.Update(); err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	return encoding.Must(enc.Encode(c))
}
예제 #19
0
파일: account.go 프로젝트: ninnemana/API
// Edit an account for a given shop.
func EditAccount(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop, token string) string {

	var c cart.Customer
	defer req.Body.Close()

	data, err := ioutil.ReadAll(req.Body)
	if err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	if err = json.Unmarshal(data, &c); err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	c.ShopId = shop.Id

	c.Id, err = cart.IdentifierFromToken(token)
	if err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	if err = c.Update(); err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	return encoding.Must(enc.Encode(c))
}
예제 #20
0
파일: price_ctlr.go 프로젝트: ninnemana/API
func GetPricesByPart(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params) string {
	var err error
	var ps customer.Prices
	var partID int

	id := r.FormValue("id")
	if id == "" {
		id = params["id"]
	}

	if partID, err = strconv.Atoi(id); err != nil {
		apierror.GenerateError("Trouble getting part ID", err, rw, r)
		return ""
	}

	if ps, err = customer.GetPricesByPart(partID); err != nil {
		apierror.GenerateError("Trouble getting prices by part", err, rw, r)
		return ""
	}

	sort := r.FormValue("sort")
	direction := r.FormValue("direction")
	if sort != "" {
		if strings.ContainsAny(direction, "esc") {
			sortutil.DescByField(ps, sort)
		} else {
			sortutil.AscByField(ps, sort)
		}
	}

	return encoding.Must(enc.Encode(ps))
}
예제 #21
0
파일: groups.go 프로젝트: ninnemana/API
func UpdateGroup(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var err error
	var group forum.Group

	if group.ID, err = strconv.Atoi(params["id"]); err != nil {
		apierror.GenerateError("Trouble getting forum group ID", err, rw, req)
	}

	if err = group.Get(dtx); err != nil {
		apierror.GenerateError("Trouble getting forum group", err, rw, req)
	}

	if req.FormValue("name") != "" {
		group.Name = req.FormValue("name")
	}

	if req.FormValue("description") != "" {
		group.Description = req.FormValue("description")
	}

	if err := group.Update(dtx); err != nil {
		apierror.GenerateError("Trouble updating forum group", err, rw, req)
	}

	return encoding.Must(enc.Encode(group))
}
예제 #22
0
파일: showcase.go 프로젝트: ninnemana/API
func GetAllShowcases(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var err error
	var page int
	var count int
	var randomize bool

	qs := req.URL.Query()

	if qs.Get("page") != "" {
		if pg, err := strconv.Atoi(qs.Get("page")); err == nil {
			page = pg
		}
	}
	if qs.Get("count") != "" {
		if c, err := strconv.Atoi(qs.Get("count")); err == nil {
			count = c
		}
	}

	if qs.Get("randomize") != "" {
		randomize, err = strconv.ParseBool(qs.Get("randomize"))
	}

	shows, err := showcase.GetAllShowcases(page, count, randomize, dtx)
	if err != nil {
		apierror.GenerateError("Trouble getting all", err, rw, req)
	}
	return encoding.Must(enc.Encode(shows))
}
예제 #23
0
파일: menu.go 프로젝트: ninnemana/API
func GetMenuWithContents(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	var m site.Menu
	var err error
	idStr := params["id"]
	id, err := strconv.Atoi(idStr)

	if err == nil {
		//Thar be an Id int
		m.Id = id
		err = m.Get(dtx)

	} else {
		//Thar be a name
		m.Name = idStr
		err = m.GetByName(dtx)
	}

	if err != nil {
		apierror.GenerateError("Trouble getting site menu", err, rw, req)
		return ""
	}

	err = m.GetContents()
	if err != nil {
		apierror.GenerateError("Trouble getting site menu with contents", err, rw, req)
		return ""
	}

	return encoding.Must(enc.Encode(m))
}
예제 #24
0
파일: showcase.go 프로젝트: ninnemana/API
func Save(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	var show showcase.Showcase
	var err error
	idStr := params["id"]
	if idStr != "" {
		show.ID, err = strconv.Atoi(idStr)
		err = show.Get(dtx)
		if err != nil {
			apierror.GenerateError("Trouble getting testimonial", err, rw, req)
		}
	}
	//json
	requestBody, err := ioutil.ReadAll(req.Body)
	if err != nil {
		apierror.GenerateError("Trouble reading request body for saving testimonial", err, rw, req)
	}
	err = json.Unmarshal(requestBody, &show)
	if err != nil {
		apierror.GenerateError("Trouble unmarshalling request body for saving testimonial", err, rw, req)
	}
	//create or update
	if show.ID > 0 {
		err = show.Update()
	} else {
		err = show.Create()
	}

	if err != nil {
		apierror.GenerateError("Trouble saving testimonial", err, rw, req)
	}
	return encoding.Must(enc.Encode(show))
}
예제 #25
0
파일: geography.go 프로젝트: ninnemana/API
func GetAllStates(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder) string {
	states, err := geography.GetAllStates()
	if err != nil {
		apierror.GenerateError("Trouble getting all states", err, rw, req)
	}
	return encoding.Must(enc.Encode(states))
}
예제 #26
0
//Import a Csv
//Fields are expected to be: Part (oldpartnumber), Make, Model, Style, Year - 5 columns total
func ImportCsv(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	contentTypeHeader := r.Header.Get("Content-Type")
	contentTypeArr := strings.Split(contentTypeHeader, ";")
	if len(contentTypeArr) < 1 {
		apierror.GenerateError("Content-Type is not multipart/form-data", nil, w, r)
		return ""
	}
	contentType := contentTypeArr[0]
	if contentType != "multipart/form-data" {
		apierror.GenerateError("Content-Type is not multipart/form-data", nil, w, r)
		return ""
	}
	file, header, err := r.FormFile("file")

	if err != nil {
		apierror.GenerateError("Error getting file", err, w, r)
		return ""
	}
	defer file.Close()

	collectionName := header.Filename

	conversionErrs, insertErrs, err := products.Import(file, collectionName)
	if err != nil {
		apierror.GenerateError("Error importing", err, w, r)
		return ""
	}

	errResp := ErrorResp{
		ConversionErrs: conversionErrs,
		InsertErrs:     insertErrs,
	}

	return encoding.Must(enc.Encode(errResp))
}
예제 #27
0
파일: salesrep.go 프로젝트: ninnemana/API
func UpdateSalesRep(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder) string {
	var err error
	var rep salesrep.SalesRep

	if rep.ID, err = strconv.Atoi(params["id"]); err != nil {
		apierror.GenerateError("Trouble getting sales rep ID", err, rw, req)
	}

	if err = rep.Get(); err != nil {
		apierror.GenerateError("Trouble getting sales rep", err, rw, req)
	}

	if req.FormValue("name") != "" {
		rep.Name = req.FormValue("name")
	}

	if req.FormValue("code") != "" {
		rep.Code = req.FormValue("code")
	}

	if err := rep.Update(); err != nil {
		apierror.GenerateError("Trouble updating sales rep", err, rw, req)
	}

	return encoding.Must(enc.Encode(rep))
}
예제 #28
0
func Get(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	var f news_model.News
	var err error

	idStr := r.FormValue("id")
	if idStr != "" {
		f.ID, err = strconv.Atoi(idStr)
		if err != nil {
			apierror.GenerateError("Trouble getting news ID", err, rw, r)
			return ""
		}
	} else {
		f.ID, err = strconv.Atoi(params["id"])
		if err != nil {
			apierror.GenerateError("Trouble getting news ID", err, rw, r)
			return ""
		}
	}
	err = f.Get(dtx)
	if err != nil {
		apierror.GenerateError("Trouble getting news", err, rw, r)
		return ""
	}
	return encoding.Must(enc.Encode(f))
}
예제 #29
0
func CreateBlog(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var b blog_model.Blog
	var err error

	b.Title = r.FormValue("title")
	b.Slug = r.FormValue("slug")
	b.Text = r.FormValue("text")
	b.PublishedDate, err = time.Parse(timeFormat, r.FormValue("publishedDate"))
	b.UserID, err = strconv.Atoi(r.FormValue("userID"))
	b.MetaTitle = r.FormValue("metaTitle")
	b.MetaDescription = r.FormValue("metaDescription")
	b.Keywords = r.FormValue("keywords")
	b.Active, err = strconv.ParseBool(r.FormValue("active"))
	categoryIDs := r.Form["categoryID"]
	for _, v := range categoryIDs {
		var bc blog_model.BlogCategory
		bc.Category.ID, err = strconv.Atoi(v)
		b.BlogCategories = append(b.BlogCategories, bc)
	}

	err = b.Create(dtx)
	if err != nil {
		apierror.GenerateError("Trouble creating blog", err, rw, r)
	}
	return encoding.Must(enc.Encode(b))
}
예제 #30
0
func GetLocalDealerTypes(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	types, err := customer.GetLocalDealerTypes(dtx)
	if err != nil {
		apierror.GenerateError("Error retrieving dealer types.", err, w, r)
	}
	return encoding.Must(enc.Encode(types))
}