def editTeamRecord(self, recordid, json):
     if json['team_id'] and json['wins'] and json['loss'] and json[
             'draw'] and json['year']:
         new_teamRecord = TeamRecords(recordid, json['team_id'],
                                      json['wins'], json['loss'],
                                      json['draw'], json['year'])
         record = RecordsDAO().edit(new_teamRecord)
         return jsonify(TeamRecords=record.__dict__), OK
     else:
         return jsonify(Error='Unexpected attributes in post'), BAD_REQUEST
Esempio n. 2
0
 def get(self, tid):
     cursor = self.conn.cursor()
     query = "SELECT team.id, team_name, info, sportname FROM ((team JOIN team_sport ON team.id = team_id) JOIN sport ON sport_id = sport.id) WHERE team.id = ?"
     cursor.execute(query, (tid, ))
     team_tup = cursor.fetchall()
     team_obj = [
         Team(team[0], team[1], team[2], team[3]) for team in team_tup
     ]
     for team in team_obj:
         dao = TeamStatisticDAOFactory().getDAO(team.sport_name)
         team.sportStatistic = dao.getByTeamid(team.team_id)
         team.managers = ManagerDAO().getByTeamID(team.team_id)
         team.teamRecords = RecordsDAO().getByTeamID(team.team_id)
     cursor.close()
     return team_obj
 def add(self, soccerTeam, int):
     self.conn = utils.connectDB()
     cursor = self.conn.cursor()
     query = "SELECT id FROM team_sport WHERE team_id = ?"
     cursor.execute(query, (soccerTeam.team_id, ))
     team_sportid = cursor.fetchone()[0]
     query1 = "INSERT INTO soccer_team_statistics(team_sport_id, goals_for, goals_allowed, shots, shots_on_goal, saves, passes, possession, fouls, date) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
     cursor.execute(query1, (
         team_sportid,
         soccerTeam.goals_for,
         soccerTeam.goals_allowed,
         soccerTeam.shots,
         soccerTeam.shots_on_goal,
         soccerTeam.saves,
         soccerTeam.passes,
         soccerTeam.possession,
         soccerTeam.fouls,
         soccerTeam.date,
     ))
     statid = cursor.lastrowid
     stat_obj = self.get(statid)
     self.conn.commit()
     date = datetime.strptime(soccerTeam.date, "%Y-%m-%d")
     year = date.year
     if RecordsDAO().getByTeamIDAndYear(soccerTeam.team_id, year):
         pass
     else:
         RecordsDAO().add(TeamRecords(0, soccerTeam.team_id, 0, 0, 0, year))
     recordid = RecordsDAO().getByTeamIDAndYear(soccerTeam.team_id, year)
     if int == 0:
         RecordsDAO().addWinToRecord(recordid)
     elif int == 1:
         RecordsDAO().addLossToRecord(recordid)
     elif int == 2:
         RecordsDAO().addDrawToRecord(recordid)
     cursor.close()
     self.conn.close()
     return stat_obj
 def deleteTeamRecord(self, recordid):
     record = RecordsDAO().delete(recordid)
     return jsonify(TeamRecords=record.__dict__), OK