예제 #1
0
파일: articles.go 프로젝트: henrydo/ags
func Register() {
	log.Info("articles registered")

	ws := new(restful.WebService)
	ws.Path("/articles").
		Consumes(restful.MIME_JSON, restful.MIME_XML).
		Produces(restful.MIME_JSON, restful.MIME_XML)

	ws.Route(ws.GET("").To(getAllArticles))
	ws.Route(ws.GET("/totalpage/number").To(getTotalPageNumber))
	ws.Route(ws.GET("/page/{pageNumber}").To(getPageArticles))

	ws.Route(ws.GET("/{article-id}").To(findArticleById).
		Doc("get an article").
		Param(ws.PathParameter("article-id", "id of the article").DataType("string")).
		Writes(Article{}))

	ws.Route(ws.GET("/name/{navname}").To(findArticleByNavName))
	ws.Route(ws.PUT("/{article-id}").To(updateArticle).Filter(auth.AuthEmployeeFilter))
	ws.Route(ws.POST("").To(createArticle).Filter(auth.AuthEmployeeFilter))

	ws.Route(ws.DELETE("/{article-id}").To(removeArticle).Filter(auth.AuthFilter))

	restful.Add(ws)
}
예제 #2
0
파일: report.go 프로젝트: henrydo/ags
func Register() {
	log.Info("report registered")
	ws := new(restful.WebService)
	ws.Path("/report").
		Consumes(restful.MIME_XML, restful.MIME_JSON).
		Produces(restful.MIME_JSON, restful.MIME_XML)
	ws.Route(ws.GET("/{cond}").To(genDataByCond).Filter(auth.AuthEmployeeFilter))
	restful.Add(ws)
}
예제 #3
0
파일: app.go 프로젝트: henrydo/ags
func main() {
	sc := make(chan os.Signal, 1)
	signal.Notify(sc,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGTERM,
		syscall.SIGQUIT)
	go func() {
		s := <-sc
		log.Info("signal recieved: %v", s)
		clean()
	}()

	service.RegService()

	log.Info("start listening on localhost:8080")
	fmt.Println("ags server started on port 8080")
	http.ListenAndServe(":8080", nil)
}
예제 #4
0
파일: enquire.go 프로젝트: henrydo/ags
func dbGetEnquire(e *Enquire, userId int64) int {
	log.Debug("get enquire detail for %s", e.Id)
	dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
	if err != nil {
		log.Fatal("%v", err)
	}
	defer dbHandler.Close()

	querySql := "SELECT id, status, customer_id, customer_name,  subject, message, employee_id, followup,  create_time, last_modify_time FROM enquires WHERE id=?"
	var enquire_id, status, customer_id, employee_id sql.NullInt64
	var customer_name, subject, message, followup sql.NullString
	var create_time, last_modify_time time.Time
	err = dbHandler.QueryRow(querySql, e.Id).Scan(&enquire_id, &status, &customer_id, &customer_name, &subject, &message, &employee_id, &followup, &create_time, &last_modify_time)
	if err != nil {
		if err == sql.ErrNoRows {
			log.Info("No enquire found for %s", e.Id)
			return http.StatusNotFound
		} else {
			log.Debug("sql : %s", querySql)
			log.Error("DB query failed: %v", err)
			return http.StatusInternalServerError
		}
	}
	if userId != customer_id.Int64 {
		u := users.DbFindUser(strconv.FormatInt(userId, 10))
		if u == nil || (u.Type == 1 || u.Type == 2) {
			return http.StatusForbidden
		}
	}

	if !status.Valid {
		return http.StatusNotFound
	} else {
		e.Products = dbGetEnquireProducts(e.Id)
		e.Status = status.Int64
		e.CustomerId = customer_id.Int64
		e.CustomerName = customer_name.String
		e.Subject = subject.String
		e.Message = message.String
		e.EmployeeId = employee_id.Int64
		e.Followup = followup.String
		e.CreateTime = create_time.Format(timeLayout)
		e.ModifyTime = last_modify_time.Format(timeLayout)

		return http.StatusOK
	}
}
예제 #5
0
파일: product.go 프로젝트: henrydo/ags
func dbGetAllProducts() ([]Product, int) {
	dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
	if err != nil {
		log.Fatal("%v", err)
	}
	defer dbHandler.Close()

	var getSql = "SELECT count(*) FROM product ORDER BY id DESC "
	var product_count sql.NullInt64
	err = dbHandler.QueryRow(getSql).Scan(&product_count)
	if err != nil {
		if err == sql.ErrNoRows {
			log.Info("sql error")
			return nil, http.StatusInternalServerError
		} else {
			log.Error("DB query failed: %v", err)
			return nil, http.StatusInternalServerError
		}
	}
	if product_count.Int64 == 0 {
		log.Error("No product in db")
		return nil, http.StatusNotFound
	}

	stmt, err := dbHandler.Prepare("SELECT id, nav_name, status, en_name, cn_name, cover_photo, introduction, spec, price, discount FROM product ORDER BY id desc ")
	if err != nil {
		log.Error("Prepare all product failed : %v", err)
		return nil, http.StatusInternalServerError
	}
	defer stmt.Close()
	rows, err := stmt.Query()
	if err != nil {
		log.Fatal("Query all product failed, something changed on db schema? : %v ", err)
		return nil, http.StatusNotFound
	}
	defer rows.Close()

	products := make([]Product, 0, product_count.Int64)
	for rows.Next() {
		var productId, status sql.NullInt64
		var navName, enName, cnName, coverPhoto, introduction, spec sql.NullString
		var price, discount sql.NullFloat64
		rows.Scan(&productId, &navName, &status, &enName, &cnName, &coverPhoto, &introduction, &spec, &price, &discount)
		products = append(products, Product{productId.Int64, navName.String, status.Int64, enName.String, cnName.String, coverPhoto.String, introduction.String, spec.String, price.Float64, discount.Float64, nil, nil, nil, nil, nil, nil})
	}
	return products, http.StatusOK
}
예제 #6
0
파일: share.go 프로젝트: henrydo/ags
func getSessionUploadFileUrls(session string) (int, string) {
	dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
	if err != nil {
		log.Fatal("%v", err)
	}
	defer dbHandler.Close()

	var getSql = "SELECT urls FROM session_upload_files WHERE session=?"
	var value sql.NullString
	err = dbHandler.QueryRow(getSql, session).Scan(&value)
	if err != nil {
		if err == sql.ErrNoRows {
			log.Info("No value found for %s", session)
			return http.StatusNotFound, ""
		} else {
			log.Error("DB query failed: %v", err)
			return http.StatusInternalServerError, ""
		}
	}
	return http.StatusOK, value.String
}
예제 #7
0
파일: product.go 프로젝트: henrydo/ags
func FindProductName(id string) string {
	dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
	if err != nil {
		log.Fatal("%v", err)
	}
	defer dbHandler.Close()

	querySql := "SELECT cn_name FROM product WHERE id=? "
	var cnName sql.NullString

	err = dbHandler.QueryRow(querySql, id).Scan(&cnName)
	if err != nil {
		if err == sql.ErrNoRows {
			log.Info("No product found for %s", id)
			return ""
		} else {
			log.Error("DB query failed: %v", err)
			return ""
		}
	}
	return cnName.String

}
예제 #8
0
파일: product.go 프로젝트: henrydo/ags
func FindProductNames(id string) (string, string) {
	log.Debug("find prodcut names for id %s", id)
	dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
	if err != nil {
		log.Fatal("%v", err)
	}
	defer dbHandler.Close()

	querySql := "SELECT en_name, nav_name FROM product WHERE id=?"
	var eName, navName sql.NullString

	err = dbHandler.QueryRow(querySql, id).Scan(&eName, &navName)
	if err != nil {
		if err == sql.ErrNoRows {
			log.Info("No product found for %s", id)
			return "", ""
		} else {
			log.Error("DB query failed: %v", err)
			return "", ""
		}
	}
	return eName.String, navName.String
}
예제 #9
0
파일: mail.go 프로젝트: henrydo/ags
func SendMail(receiver string, subject string, message string) int {
	if auth == nil {
		auth = smtp.PlainAuth(
			"",
			config.GetValue("SenderEmail"),
			config.GetValue("SenderPassword"),
			config.GetValue("SmtpServer"))
	}

	log.Debug("auth is %v", auth)
	body := "To: " + receiver + "\r\nSubject: " + subject + "\r\n\r\n" + message
	err := smtp.SendMail(
		config.GetValue("SmtpServer")+":"+config.GetValue("SmtpPort"),
		auth,
		config.GetValue("SenderEmail"),
		[]string{receiver},
		[]byte(body))
	if err != nil {
		log.Info("mail %s sent to %s", subject, receiver)
		return http.StatusForbidden
	}
	return http.StatusOK
}
예제 #10
0
파일: enquire.go 프로젝트: henrydo/ags
func Register() {
	log.Info("enquire registered")

	ws := new(restful.WebService)
	ws.Path("/enquire").
		Consumes(restful.MIME_XML, restful.MIME_JSON).
		Produces(restful.MIME_JSON, restful.MIME_XML)
	ws.Route(ws.GET("/search/{searchtext}/page/{pagenumber}").To(searchEnquires).Filter(auth.AuthEmployeeFilter))
	ws.Route(ws.GET("/search/{searchtext}/count").To(searchEnquiresCount).Filter(auth.AuthEmployeeFilter))
	ws.Route(ws.GET("/count/{cond}").To(getEnquiresCountByCond).Filter(auth.AuthEmployeeFilter))
	ws.Route(ws.GET("/cond/{cond}").To(findEnquiresByCond).Filter(auth.AuthEmployeeFilter))
	ws.Route(ws.GET("/id/{EnquireId}").To(getEnquire).Filter(auth.AuthFilter))
	ws.Route(ws.POST("").To(addEnquire).Filter(auth.AuthFilter))
	ws.Route(ws.PUT("/id/{EnquireId}").To(followupEnquire).Filter(auth.AuthEmployeeFilter))
	restful.Add(ws)

	wsr := new(restful.WebService)
	wsr.Path("/reviewboard").
		Consumes(restful.MIME_XML, restful.MIME_JSON).
		Produces(restful.MIME_JSON, restful.MIME_XML)
	wsr.Route(wsr.GET("").To(getReviewboardDetail))
	wsr.Route(wsr.POST("").To(addProductToReviewboard))
	restful.Add(wsr)
}
예제 #11
0
파일: product.go 프로젝트: henrydo/ags
func Register() {
	log.Info("product registered")
	ws := new(restful.WebService)
	ws.Path("/product").
		Consumes(restful.MIME_XML, restful.MIME_JSON).
		Produces(restful.MIME_JSON, restful.MIME_XML)
	ws.Route(ws.GET("").To(getAllProducts).Filter(auth.AuthEmployeeFilter))
	ws.Route(ws.GET("/{navname}").To(findProductByNavName))
	ws.Route(ws.POST("").To(addProduct).Filter(auth.AuthEmployeeFilter))
	ws.Route(ws.PUT("").To(saveProduct).Filter(auth.AuthEmployeeFilter))

	ws.Route(ws.GET("/search/{searchtext}/page/{pagenumber}").To(searchProducts).Filter(auth.AuthEmployeeFilter))
	ws.Route(ws.GET("/search/{searchtext}/count").To(searchProductsCount).Filter(auth.AuthEmployeeFilter))
	restful.Add(ws)

	wsDeal := new(restful.WebService)
	wsDeal.Path("/deals").
		Consumes(restful.MIME_XML, restful.MIME_JSON).
		Produces(restful.MIME_JSON, restful.MIME_XML)
	wsDeal.Route(wsDeal.GET("").To(getAllProducts))
	wsDeal.Route(wsDeal.GET("/{navname}").To(findProductByNavName))
	wsDeal.Route(wsDeal.GET("/page/{pageNumber}").To(getPageDeals))
	restful.Add(wsDeal)
}
예제 #12
0
파일: share.go 프로젝트: henrydo/ags
func Register() {
	log.Info("share service registered")

	http.HandleFunc("/uploadphoto", uploadPhotoHandler)
}
예제 #13
0
파일: product.go 프로젝트: henrydo/ags
func dbFindProductByNavName(p *Product) int {
	dbHandler, err := sql.Open("sqlite3", config.GetValue("DbFile"))
	if err != nil {
		log.Fatal("%v", err)
	}
	defer dbHandler.Close()

	navname := p.NavName
	log.Debug("get product detail for %s", navname)
	querySql := "SELECT id, nav_name, status, en_name, cn_name, cover_photo, introduction, spec, price, discount FROM product WHERE nav_name=? "
	var productId, status sql.NullInt64
	var navName, enName, cnName, coverPhoto, introduction, spec sql.NullString
	var price, discount sql.NullFloat64
	err = dbHandler.QueryRow(querySql, navname).Scan(&productId, &navName, &status, &enName, &cnName, &coverPhoto, &introduction, &spec, &price, &discount)
	if err != nil {
		if err == sql.ErrNoRows {
			log.Info("No product found for %s", navname)
			return http.StatusNotFound
		} else {
			log.Error("DB query failed: %v", err)
			return http.StatusInternalServerError
		}
	}
	p.Id = productId.Int64
	p.NavName = navName.String
	p.Status = status.Int64
	p.EnName = enName.String
	p.CnName = cnName.String
	p.CoverPhoto = coverPhoto.String
	p.Introduction = introduction.String
	p.Spec = spec.String
	p.Price = price.Float64
	p.Discount = discount.Float64

	queryPhotoSql := "SELECT url FROM product_photo WHERE product_id=? ORDER BY id DESC LIMIT 100"
	rows, err := dbHandler.Query(queryPhotoSql, p.Id)
	defer rows.Close()

	ps := make([]string, 0, 100)
	for rows.Next() {
		var url sql.NullString
		rows.Scan(&url)
		if len(url.String) > 0 {
			ps = append(ps, url.String)
		}
	}
	p.Photos = ps

	querySaleUrlSql := "SELECT url FROM product_saleurl WHERE product_id=? ORDER BY id DESC LIMIT 100"
	surows, err := dbHandler.Query(querySaleUrlSql, p.Id)
	defer surows.Close()

	su := make([]string, 0, 100)
	for surows.Next() {
		var url sql.NullString
		surows.Scan(&url)
		if len(url.String) > 0 {
			su = append(su, url.String)
		}
	}
	p.SaleURL = su

	return http.StatusOK
}