You are browsing as a guest. Sign up (or log in) to start making projects!

5h 48m 41s logged

Fixing some forgoten code and more

So at this devlog i were fixing some bugs in a specific ui / route called ¨copa¨, this is a special route added because a teacher asked our team to create them to use at some football games in our school. But since it was a hiddend route and mostly like a easter egg it hasnt been updated in a while and wasnt working anymore.

What i fixed

  • i was following a pattern where most of the images that each route used should be in a special foulder of storage (literally called /storage), but this mode (copa) where created before it and was following the old way
  • Also there was some errors ocurred afther i changed the entire folder structure, so the copa mode where completely broken, i fixed it too.

What i added

  • I had a class about PHP + Laravel | API | Controlers in my course, afther that class i realized that the way the API (copa) where searching for data based on ID where wrong (was doing copa?id=…), i changed it to /copa/id
  • There is a function that show the teams to the user to select one that he wants, but the teams list where hard coded and wasnt synced with the database. I made it use the database data instead of a hardcoded value

** That where all for that mode, but i didnt spent 5 hours just on it, i made more: **

Fixing (or making) some other bugs

  • There is a script that controls the database that where holding and infinite single connection with the database, something like this
conn =  mysql.connector.connect(**configs)
cursor  = conn.cursor(Dictionary=True)

But all the codes where using the same connection and cursor, so i decided to apply a connecton pool and make each database call get a connection and a new cursor.
Also i added some functions to abstrac the connection and query part:

def __get_connection(self):
        conn = self.db_pool.get_connection()
        conn.ping(reconnect=True, attempts=3, delay=1)
        return conn

    def __execute_query(self, query: str, params: list | None = None, dictionary=True, query_type: QueryTypes = QueryTypes.ALL):
        conn = self.__get_connection()

        try:
            with conn.cursor(dictionary=dictionary) as cursor:
                cursor.execute(query, (params) or ())

                match query_type:
                    case QueryTypes.ALL:
                        return cursor.fetchall()
                    case QueryTypes.ONE:
                        return cursor.fetchone()
                    case QueryTypes.EXECUTE:
                        cursor.commit()
                        return cursor.lastrowid or cursor.rowcount
                    case _:
                        raise ValueError(f"Tipo de consulta não suportado: {query_type}")

If yall want to see it check here at my repo

That was also the first time that i used a Enum (on code) and branchs (on github, but i didnt used them properly)

Others

There was also some other changes, check the repo GF-Silva/Ritualia

What next

Now i will add some bug checks on a piece of code that handle the video display using an youtube iframe.

0
17

Comments 0

No comments yet. Be the first!