Beispiel #1
0
    def post(self):
        try:
            mandatoryParams = [
                "session_id", "transaction_by", "player_details", "created_at"
            ]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            sessionID = self.request.get("session_id")
            createdBy = self.request.get("transaction_by")
            playerDetails = json.loads(self.request.get("player_details"))
            createdAt = datetime.strftime(self.request.get("created_at"),
                                          TIME_FORMAT)

            txnIDs = []
            for name, buyin in playerDetails.iteritems():
                txnIDs.append(
                    utils.CreateTransaction(sessionID, createdBy, name, buyin,
                                            createdAt))

            returnJson["transactions"] = txnIDs

            WriteSuccessJson(self, returnJson)
            return

        except Exception as e:
            logging.exception("Error occured while saving the transaction")
            WriteErrorJson(self, e.message)
            return

        WriteSuccessJson(self)
        return
Beispiel #2
0
    def post(self):
        try:
            mandatoryParams = [
                "transaction_id", "transaction_hidden", "transaction_amount"
            ]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            txnID = self.request.get("transaction_id")
            isHidden = json.loads(self.request.get("transaction_hidden"))
            txnAmount = int(self.request.get("transaction_amount"))

            txnObj = model.Transactions.all().filter("transaction_id = ",
                                                     txnID.strip()).fetch(1)

            if not txnObj:
                WriteErrorJson(self, "", ReturnCodes.TRANSACTION_NOT_FOUND)

            txnObj.transaction_hidden = isHidden
            txnObj.transaction_amount = txnAmount

            txnObj.put()

            WriteSuccessJson(self)
            return

        except Exception as e:
            logging.exception("Error occured while saving the transaction")
            WriteErrorJson(self, e.message)
            return

        WriteSuccessJson(self)
        return
Beispiel #3
0
    def post(self):
        try:
            mandatoryParams = [
                "session_id", "session_currency", "session_name"
            ]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            sessionID = self.request.get("session_id")
            name = self.request.get("session_name")
            currency = self.request.get("session_currency")

            sessionObj = utils.GetSessionEntityFromID(sessionID)
            sessionObj.session_name = name
            sessionObj.session_currency = currency
            sessionObj.session_last_updated = datetime.utcnow()
            sessionObj.put()

            WriteSuccessJson(self)
            return

        except Exception as e:
            logging.exception("Error occured while creating a session")
            WriteErrorJson(self, e.message)
            return

        WriteSuccessJson(self)
Beispiel #4
0
    def post(self):
        try:
            mandatoryParams = ["group_id"]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            utils.UpdateGroupDetails(self.request)
            WriteSuccessJson(self)

        except ValueError as ve:
            WriteErrorJson(self, "", ve.message)
Beispiel #5
0
    def post(self):
        try:
            mandatoryParams = [
                "session_name", "group_id", "player_details",
                "session_created_by", "session_currency", "created_at"
            ]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            returnJson = {}

            createdAt = datetime.strptime(self.request.get("created_at"),
                                          TIME_FORMAT)
            playerDetails = json.loads(self.request.get("player_details"))
            groupID = self.request.get("group_id")
            createdBy = self.request.get("session_created_by")
            name = self.request.get("session_name")
            currency = self.request.get("session_currency")
            isActive = json.loads(self.request.get("session_active"))

            sessionID = utils.CreateSession(name, groupID, playerDetails,
                                            createdBy, isActive, currency,
                                            createdAt)

            txnIDs = []
            for name, buyin in playerDetails.iteritems():
                txnID = utils.CreateTransaction(sessionID, createdBy, name,
                                                buyin, createdAt)

                transaction = {}
                transaction["email"] = name
                transaction["transaction_id"] = txnID
                txnIDs.append(transaction)

            returnJson["session_id"] = sessionID
            returnJson["transactions"] = txnIDs

            WriteSuccessJson(self, returnJson)
            return

        except Exception as e:
            logging.exception("Error occured creating a session")
            WriteErrorJson(self, e.message)
            return
Beispiel #6
0
    def post(self):
        try:
            mandatoryParams = ["email"]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            playerDetails = utils.GetPlayerDetails(self.request.get("email"))

            WriteSuccessJson(self, playerDetails)

        except ValueError as ve:
            WriteErrorJson(self, "", ve.message)

        except Exception as e:
            logging.exception("Error occured while getting player details")
            WriteErrorJson(self, str(e))
Beispiel #7
0
    def post(self):
        try:
            mandatoryParams = ["group_id"]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            groupID = self.request.get("group_id")
            sessions = utils.GetGroupSessions(groupID)

            returnJson = {}
            returnJson["sessions"] = sessions

            WriteSuccessJson(self, returnJson)

        except Exception as e:
            logging.exception("Error occured while getting the transactions")
            WriteErrorJson(self, e.message)
Beispiel #8
0
    def post(self):
        try:
            mandatoryParams = ["group_id"]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            groupDetails = {
                "group": utils.GetGroupDetails(self.request.get("group_id"))
            }
            WriteSuccessJson(self, groupDetails)

        except ValueError as ve:
            WriteErrorJson(self, "", ve.message)

        except Exception as e:
            logging.exception("Error occured while getting group details")
            WriteErrorJson(self, str(e))
Beispiel #9
0
    def post(self):
        try:
            mandatoryParams = ["email", "email_list"]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            returnList = []
            for eachEmail in json.loads(email_list):
                if utils.DoesPlayerExist(eachEmail):
                    returnList.append(utils.GetPlayerPictureAndName(eachEmail))

            returnJson = {"existing_players": returnList}

            WriteSuccessJson(self, returnJson)

        except ValueError as ve:
            WriteErrorJson(self, "", ve.message)
Beispiel #10
0
    def post(self):
        try:
            mandatoryParams = [
                "session_id", "player_details", "created_by", "created_at"
            ]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            returnJson = {}
            createdAt = datetime.strptime(self.request.get("created_at"),
                                          TIME_FORMAT)
            playerDetails = json.loads(self.request.get("player_details"))
            createdBy = self.request.get("created_by")
            sessionID = self.request.get("session_id")

            #Create transactions
            txnIDs = []
            for name, buyin in playerDetails.iteritems():
                txnIDs.append(
                    utils.CreateTransaction(sessionID, createdBy, name, buyin,
                                            createdAt))

            #Update Session
            sessionObj = utils.GetSessionEntityFromID(sessionID)
            sessionObj.session_ended_at = createdAt
            sessionObj.last_updated = createdAt
            sessionObj.session_active = False
            sessionObj.put()

            returnJson["transactions"] = txnIDs

            WriteSuccessJson(self, returnJson)
            return

        except Exception as e:
            logging.exception("Error occured creating a session")
            WriteErrorJson(self, e.message)
            return

        WriteSuccessJson(self)
Beispiel #11
0
    def post(self):
        try:
            mandatoryParams = [
                "group_name", "group_owner", "players", "time_created"
            ]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            for eachParam in mandatoryParams:
                logging.info(self.request.get(eachParam))

            name = self.request.get("group_name")
            owner = self.request.get("group_owner")
            picture = self.request.get("group_picture_url")
            players = json.loads(self.request.get("players"))
            timeCreated = datetime.strptime(self.request.get("time_created"),
                                            TIME_FORMAT)

            #Add yourself to the group
            if owner not in players:
                players.append(owner)

            groupID = utils.CreateGroup(name, owner, picture, players,
                                        timeCreated)
            utils.AddPlayersToGroup(groupID, players)

        except Exception as e:
            logging.exception("Error occured while creating group")
            WriteErrorJson(self, str(e))
            return

        returnJson = {}
        returnJson["group_id"] = groupID
        returnJson["group_created_at"] = datetime.strftime(
            timeCreated, TIME_FORMAT)

        WriteSuccessJson(self, returnJson)
Beispiel #12
0
    def post(self):
        try:
            mandatoryParams = ["session_id"]
            if not utils.ValidateParams(self.request, mandatoryParams):
                WriteErrorJson(self, "",
                               ReturnCodes.INCOMPLETE_PARAMETER_PROVIDED)
                return

            sessionID = self.request.get("session_id")
            transactionsObj = model.Transactions.all().filter(
                "session_id = ", sessionID.strip()).fetch(None)
            returnJson = {}

            transactionsList = []
            if transactionsObj:
                for eachTxn in transactionsObj:
                    txn = {}
                    txn["transaction_by"] = eachTxn.transaction_by
                    txn["transaction_of"] = eachTxn.transaction_of
                    txn["transaction_amount"] = eachTxn.transaction_amount
                    txn["transaction_time"] = eachTxn.transaction_time.strftime(
                        TIME_FORMAT)
                    txn["transaction_id"] = eachTxn.transaction_id

                    transactionsList.append(txn)

            returnJson["session_id"] = sessionID
            returnJson["transactions"] = transactionsList

            WriteSuccessJson(self, returnJson)
            return

        except Exception as e:
            logging.exception("Error occured while getting the transactions")
            WriteErrorJson(self, e.message)
            return