コード例 #1
0
ファイル: buoyService.go プロジェクト: jharlap/beego-mgo
// FindStation retrieves the specified station
func FindStation(service *services.Service, stationId string) (buoyStation *buoyModels.BuoyStation, err error) {
	defer helper.CatchPanic(&err, service.UserId, "FindStation")

	tracelog.Started(service.UserId, "FindStation")

	queryMap := bson.M{"station_id": stationId}

	buoyStation = &buoyModels.BuoyStation{}
	err = service.DBAction(Config.Database, "buoy_stations",
		func(collection *mgo.Collection) error {
			tracelog.Trace(service.UserId, "FindStation", "Query : %s", mongo.ToString(queryMap))
			return collection.Find(queryMap).One(buoyStation)
		})

	if err != nil {
		if strings.Contains(err.Error(), "not found") == false {
			tracelog.CompletedError(err, service.UserId, "FindStation")
			return buoyStation, err
		}

		err = nil
	}

	tracelog.Completed(service.UserId, "FindStation")
	return buoyStation, err
}
コード例 #2
0
ファイル: buoyService.go プロジェクト: ZloiBubr/beego-mgo
// FindRegion retrieves the stations for the specified region
func FindRegion(service *services.Service, region string) ([]buoyModels.BuoyStation, error) {
	log.Startedf(service.UserID, "FindRegion", "region[%s]", region)

	var buoyStations []buoyModels.BuoyStation
	f := func(collection *mgo.Collection) error {
		queryMap := bson.M{"region": region}

		log.Trace(service.UserID, "FindRegion", "Query : db.buoy_stations.find(%s)", mongo.ToString(queryMap))
		return collection.Find(queryMap).All(&buoyStations)
	}

	if err := service.DBAction(Config.Database, "buoy_stations", f); err != nil {
		log.CompletedError(err, service.UserID, "FindRegion")
		return nil, err
	}

	log.Completedf(service.UserID, "FindRegion", "buoyStations%+v", buoyStations)
	return buoyStations, nil
}
コード例 #3
0
ファイル: buoyService.go プロジェクト: jharlap/beego-mgo
// FindRegion retrieves the stations for the specified region
func FindRegion(service *services.Service, region string) (buoyStations []*buoyModels.BuoyStation, err error) {
	defer helper.CatchPanic(&err, service.UserId, "FindRegion")

	tracelog.Started(service.UserId, "FindRegion")

	queryMap := bson.M{"region": region}

	buoyStations = []*buoyModels.BuoyStation{}
	err = service.DBAction(Config.Database, "buoy_stations",
		func(collection *mgo.Collection) error {
			tracelog.Trace(service.UserId, "FindRegion", "Query : %s", mongo.ToString(queryMap))
			return collection.Find(queryMap).All(&buoyStations)
		})

	if err != nil {
		tracelog.CompletedError(err, service.UserId, "FindRegion")
		return buoyStations, err
	}

	tracelog.Completed(service.UserId, "FindRegion")
	return buoyStations, err
}
コード例 #4
0
ファイル: buoyService.go プロジェクト: pmljm/beego-mgo
// FindStation retrieves the specified station
func FindStation(service *services.Service, stationId string) (buoyStation *buoyModels.BuoyStation, err error) {
	defer helper.CatchPanic(&err, service.UserId, "FindStation")

	tracelog.STARTED(service.UserId, "FindStation")

	queryMap := bson.M{"station_id": stationId}
	tracelog.TRACE(service.UserId, "FindStation", "Query : %s", mongo.ToString(queryMap))

	buoyStation = &buoyModels.BuoyStation{}
	err = service.DBAction(Config.Database, "buoy_stations",
		func(collection *mgo.Collection) error {
			return collection.Find(queryMap).One(buoyStation)
		})

	if err != nil {
		tracelog.COMPLETED_ERROR(err, service.UserId, "FindStation")
		return buoyStation, err
	}

	tracelog.COMPLETED(service.UserId, "FindStation")
	return buoyStation, err
}
コード例 #5
0
ファイル: buoyService.go プロジェクト: vegansk/beego-mgo
// FindRegion retrieves the stations for the specified region
func FindRegion(service *services.Service, region string) (buoyStations []*buoyModels.BuoyStation, err error) {
	defer helper.CatchPanic(&err, service.UserId, "FindRegion")

	tracelog.STARTED(service.UserId, "FindRegion")

	// Find the specified region
	queryMap := bson.M{"region": region}
	tracelog.TRACE(service.UserId, "FindRegion", "Query : %s", mongo.ToString(queryMap))

	// Capture the specified buoy
	buoyStations = []*buoyModels.BuoyStation{}
	err = service.DBAction(Config.Database, "buoy_stations",
		func(collection *mgo.Collection) error {
			return collection.Find(queryMap).All(&buoyStations)
		})

	if err != nil {
		tracelog.COMPLETED_ERROR(err, service.UserId, "FindRegion")
		return buoyStations, err
	}

	tracelog.COMPLETED(service.UserId, "FindRegion")
	return buoyStations, err
}
コード例 #6
0
ファイル: buoyService.go プロジェクト: ZloiBubr/beego-mgo
// FindStation retrieves the specified station
func FindStation(service *services.Service, stationID string) (*buoyModels.BuoyStation, error) {
	log.Startedf(service.UserID, "FindStation", "stationID[%s]", stationID)

	var buoyStation buoyModels.BuoyStation
	f := func(collection *mgo.Collection) error {
		queryMap := bson.M{"station_id": stationID}

		log.Trace(service.UserID, "FindStation", "MGO : db.buoy_stations.find(%s).limit(1)", mongo.ToString(queryMap))
		return collection.Find(queryMap).One(&buoyStation)
	}

	if err := service.DBAction(Config.Database, "buoy_stations", f); err != nil {
		if err != mgo.ErrNotFound {
			log.CompletedError(err, service.UserID, "FindStation")
			return nil, err
		}
	}

	log.Completedf(service.UserID, "FindStation", "buoyStation%+v", &buoyStation)
	return &buoyStation, nil
}