func PostLoginPageData(loginInfo *PostLogin) (*LoginStatus, error) {

	l.PutInfo(l.I_M_PostPage, loginInfo, nil)

	var admin bool
	_, ok := users[loginInfo.UserId]
	if ok {
		var teamName string
		for _, team := range teams {
			for _, userid := range team.UserIds {
				if userid == loginInfo.UserId {
					teamName = team.Name
				}
			}
		}

		l.Output(
			logrus.Fields{
				"User ID":   loginInfo.UserId,
				"User Name": users[loginInfo.UserId].Name,
			},
			"login success",
			l.Debug,
		)

		if players[loginInfo.UserId].Admin == true {
			admin = true
		} else {
			admin = false
		}
		loginStatus := &LoginStatus{
			Status:   "success",
			UserId:   loginInfo.UserId,
			UserName: users[loginInfo.UserId].Name,
			Team:     teamName,
			Admin:    admin,
		}
		return loginStatus, nil
	} else {
		l.Output(
			logrus.Fields{
				"User ID": loginInfo.UserId,
			},
			"login faild",
			l.Debug,
		)
		return &LoginStatus{Status: "failed"}, nil
	}
}
Esempio n. 2
0
func shutdownHook() {
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
	<-sigs
	l.Output(nil, "Shutdown", l.Info)
	os.Exit(0)
}
Esempio n. 3
0
func RequestTakePicture(userIds []string) (*RequestTakePictureStatus, error) {

	db, session := mongoConn()
	col := db.C("thread")
	defer session.Close()

	threadCol := ThreadCol{}
	for _, userId := range userIds {
		findQuery := bson.M{"imgurl": "", "userid": userId}
		if err = col.Find(findQuery).One(&threadCol); err != nil {
			l.Output(
				logrus.Fields{"User Id": userId, "User Name": users[userId].Name},
				"Need not take any picture",
				l.Debug,
			)
		}

		if len(threadCol.ThreadId) != 0 {
			requestTakePictureStatus := &RequestTakePictureStatus{
				Status:      "take a picture",
				UserId:      threadCol.UserId,
				TeamUserIds: userIds,
				Name:        users[threadCol.UserId].Name,
				Positive:    threadCol.Positive,
				ThreadId:    threadCol.ThreadId,
				ThreadMsg:   threadCol.Msg,
				PhotoUrl:    "",
			}

			return requestTakePictureStatus, nil
		}
	}
	return &RequestTakePictureStatus{Status: "success"}, nil
}
func PostApplyScoreData(teamName string, ApplyScore *PostApplyScore) (*Status, error) {
	l.PutInfo(l.I_M_PostPage, teamName, ApplyScore)

	//更新情報をGlobal変数に格納する
	defer SetPlayerCol(ApplyScore.UserIds)

	AUserIdInTheTeam := teams[teamName].UserIds[0]
	if players[AUserIdInTheTeam].Apply != 0 {
		l.Output(
			logrus.Fields{
				"User Apply": l.Sprintf(players[AUserIdInTheTeam].Apply),
			},
			"Apply score is already registered",
			l.Debug,
		)
		return &Status{"already registered"}, nil
	}
	for playerIndex, userId := range ApplyScore.UserIds {

		findQuery := bson.M{"userid": userId}
		setQuery := bson.M{"$set": bson.M{"apply": ApplyScore.Apply[playerIndex]}}
		if err = UpdateMongoData("player", findQuery, setQuery); err != nil {
			l.PutErr(err, l.Trace(), l.E_M_Update, ApplyScore.Apply[playerIndex])
			return &Status{"failed"}, err
		}
	}

	return &Status{"success"}, nil
}
Esempio n. 5
0
func getCol(c *gin.Context) {
	col := c.Params.ByName("col")

	l.Output(
		logrus.Fields{"Collection": l.Sprintf(col)},
		"Get access to collection router",
		l.Debug,
	)

	if col == "player" || col == "field" || col == "team" {
		data, err := m.GetAllColData(col)
		pp.Println(data)
		if err != nil {
			panic(err)
		}
		c.JSON(200, data)
	}
}
Esempio n. 6
0
func register(c *gin.Context) {
	date := c.Params.ByName("date")
	collection := c.Params.ByName("collection")
	//		if origin := req.HeaderParameter(restful.HEADER_Origin); origin != "" {
	//			if len(resp.Header().Get(restful.HEADER_AccessControlAllowOrigin)) == 0 {
	//				resp.AddHeader(restful.HEADER_AccessControlAllowOrigin, origin)
	//			}
	//		}

	pp.Println(date)
	l.Output(
		logrus.Fields{
			"Date":       date,
			"Collection": collection,
			"Context":    l.Sprintf(c),
		},
		"Post access to register router",
		l.Debug,
	)

	switch collection {

	case "user":

		userCols := new([]m.UserCol)
		if !c.Bind(userCols) {
			c.JSON(404, gin.H{"status": "wrong queries"})
			return
		}

		status, err := m.RegisterUserColData(*userCols)
		if err != nil {
			l.PutErr(err, l.Trace(), l.E_R_RegisterCol, userCols)
		}
		c.JSON(200, status)

	case "team":

		teamCols := new([]m.TeamCol)
		if !c.Bind(teamCols) {
			c.JSON(404, gin.H{"status": "wrong queries"})
			return
		}

		status, err := m.RegisterTeamColData(date, *teamCols)
		if err != nil {
			l.PutErr(err, l.Trace(), l.E_R_RegisterCol, teamCols)
		}
		c.JSON(200, status)

	case "field":

		fieldCols := new([]m.FieldCol)
		if !c.Bind(fieldCols) {
			c.JSON(404, gin.H{"status": "wrong queries"})
			return
		}

		status, err := m.RegisterFieldColData(date, *fieldCols)
		if err != nil {
			l.PutErr(err, l.Trace(), l.E_R_RegisterCol, fieldCols)
		}
		c.JSON(200, status)

	case "thread":

		requestTakePictureStatus := new(m.RequestTakePictureStatus)
		if !c.Bind(requestTakePictureStatus) {
			c.JSON(404, gin.H{"status": "wrong queries"})
			return
		}

		status, err := m.RegisterThreadImg(requestTakePictureStatus)
		if err != nil {
			l.PutErr(err, l.Trace(), l.E_R_RegisterCol, requestTakePictureStatus)
		}

		c.JSON(200, status)
	}
}
Esempio n. 7
0
func postOne(c *gin.Context) {
	page := c.Params.ByName("page")
	team := c.Params.ByName("team")
	hole := c.Params.ByName("hole")
	//		if origin := req.HeaderParameter(restful.HEADER_Origin); origin != "" {
	//			if len(resp.Header().Get(restful.HEADER_AccessControlAllowOrigin)) == 0 {
	//				resp.AddHeader(restful.HEADER_AccessControlAllowOrigin, origin)
	//			}
	//		}

	l.Output(
		logrus.Fields{
			"Page":    page,
			"Team":    team,
			"Hole":    hole,
			"Context": l.Sprintf(c),
		},
		"Post access to page router",
		l.Debug,
	)
	switch page {

	case "login":

		loginInfo := new(m.PostLogin)
		if !c.Bind(loginInfo) {
			c.JSON(404, gin.H{"status": "wrong queries"})
			return
		}

		status, err := m.PostLoginPageData(loginInfo)
		if err != nil {
			l.PutErr(err, l.Trace(), l.E_R_PostPage, loginInfo)
		}
		c.JSON(200, status)

	case "scoreViewSheet":

		definedTeam := new(m.PostDefinedTeam)
		if !c.Bind(definedTeam) {
			c.JSON(404, gin.H{"status": "wrong queries"})
			return
		}

		status, err := m.PostScoreViewSheetPageData(team, definedTeam)
		if err != nil {
			l.PutErr(err, l.Trace(), l.E_R_PostPage, definedTeam)
		}
		c.JSON(200, status)

	case "scoreEntrySheet":

		updatedTeamScore := new(m.PostTeamScore)
		if !c.Bind(updatedTeamScore) {
			c.JSON(404, gin.H{"status": "wrong queries"})
			return
		}

		status, err := m.PostScoreEntrySheetPageData(team, hole, updatedTeamScore)
		if err != nil {
			l.PutErr(err, l.Trace(), l.E_R_PostPage, updatedTeamScore)
		}
		c.JSON(200, status)

	case "applyScore":
		if hole != "" {
			return
		}
		registeredApplyScore := new(m.PostApplyScore)
		if !c.Bind(registeredApplyScore) {
			c.JSON(404, gin.H{"status": "wrong queries"})
			return
		}

		status, err := m.PostApplyScoreData(team, registeredApplyScore)
		if err != nil {
			l.PutErr(err, l.Trace(), l.E_R_PostPage, registeredApplyScore)
		}
		c.JSON(200, status)
	}
}
Esempio n. 8
0
func main() {
	l.Output(nil, "Start API server", l.Info)
	r.Register()
	shutdownHook()
}
Esempio n. 9
0
func getPage(c *gin.Context) {
	var page, team, hole string
	url := strings.Split(c.Params.ByName("page"), "/")
	pp.Println(url)

	l.Output(
		logrus.Fields{"Page": page, "Team": team, "Hole": hole, "URL": url},
		"Get access to page router",
		l.Debug,
	)
	page = url[1]
	if len(url) > 2 {
		team = url[2]
	}
	if len(url) > 3 {
		hole = url[3]
	}

	pp.Println(page)
	switch page {
	case "index":
		if team != "" || hole != "" {
			return
		}
		data, err := m.GetIndexPageData()
		if err != nil {
			panic(err)
		}
		c.JSON(200, data)

	case "leadersBoard":
		if team != "" || hole != "" {
			return
		}
		data, err := m.GetLeadersBoardPageData()
		if err != nil {
			panic(err)
		}
		c.JSON(200, data)

	case "scoreEntrySheet":
		data, err := m.GetScoreEntrySheetPageData(team, hole)
		if err != nil {
			panic(err)
		}
		c.JSON(200, data)

	case "scoreViewSheet":
		if hole != "" {
			return
		}
		data, err := m.GetScoreViewSheetPageData(team)
		if err != nil {
			panic(err)
		}
		c.JSON(200, data)

	case "entireScore":

		data, err := m.GetEntireScorePageData()
		if err != nil {
			panic(err)
		}
		c.JSON(200, data)

	case "timeLine":

		data, err := m.GetTimeLinePageData()
		if err != nil {
			panic(err)
		}
		c.JSON(200, data)

	default:
		c.JSON(404, gin.H{"status": "not found"})
	}
}