Exemplo n.º 1
0
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
}
Exemplo n.º 2
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)
	}
}
Exemplo n.º 3
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)
	}
}
Exemplo n.º 4
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)
	}
}