Closed alejmedinajr closed 6 months ago
Update: This issue is also responsible for creating the database using the tables provided (note: Firebase uses document based objects, not SQL).
Post Class Update: I made two very basic post functions in API.py
. This is just to get a good starting skeleton of what I want to do with this. Also, it is not using our Firebase database or the file database.py
. The reason for this is because that file only contains basic methods for interacting with our firebase database. It needs to be updated in order to contain functionality appropriate for what we want to use it for. I also think I want to start on the connection to the react app before starting on the ability to make queries in the database. This might change depending on the status of other tickets (specifically the one related to separating the pages). Overall this is a good starting point for this ticket.
Post class update: I tried making a function in database.py
to add a user by passing parameters, but I do not have a lot of experience with NoSQL databases. The function is not working as intended, but I feel I am on the right track.
Working on this now
Update: I am working while on the road so the service is a little spotty. I did get to a point where I am testing my function from the database.py file, though I am getting an error, and I think it is because of the order I am making the queries.
Update: Currently, I am having an issue with the data being pushed being overwritten by consecutive calls to the function. Ideally, the database should maintain the new users until they are removed. I am unsure why this is happening...I am looking into the documentation further to find out why this happens.
Update: I found out that the set function overwrites data not on consecutive insertions, but when the program is run again. I thought this was interesting, but I am currently working on an approach that deals with this. Supposedly, using push fixes this, but that does not seem to be the case. I think I will try to organize my data by having a username for each user act as an additional key (making the depth one more).
Update: I am still having trouble, and I am going to stop working for now because I feel like I am going in circles. I was unable to figure out why I was not able to continue adding data without overwriting existing data. I tried looking for videos, but for some reason, I am unable to play the videos, so I will go ahead and stop here for now on this portion of the issue (until I get to the hotel (for a more stable connection). On the bright side, I know several ways to insert data into the realtime database...
I think I will now focus on updating functions, since I can create three users, then try to simply update one in the middle (so I won't think a user was updated when it was actually overwritten).
Update: After moving away from the insertion function, I was able to implement the update user function (the user is updated based on its id). I tested it by updating a newly inserted user from the middle (to make sure updating worked and it was not just overwriting the existing user). I also tested by updating multiple key values of the user (not all keys were changed to verify the changes were not a replacement of the entire user). This seemed to work. I think this is a good step forward with this database. I will then try to work on a delete function. This will make sure I can also remove a user. I am fairly close to my hotel now, so this will be my last update before I take a break from this. The next thing I will work on is functionality to remove a user (also by id).
Starting on this again
Update: I was able to easily implement the remove_user function (use case for when a user wants to delete their account). This actually seemed fairly simple since I already implemented the update function (and since the documentation allows easy manipulations (aside from adds). However, while I was testing this, I found out that when I comment out the code that inserts users, there are no users in the database. In other words, the users do not exist when the script is run again? I am not sure why this is the case, but it seems to be the same thing happening with insertion statements. Interesting enough, this does not happen when I try to mess with the Faculty table. I think this may have to do with the way the reference is being manipulated. I also think this has to do something with the fact that the depth of the reference is being altered with that code in a unique way that the code in the functions is not. I think this may be the path to fixing this problem for all functions.
Update: I was able to fix the problems by changing the structure of the database. I tested to make sure by adding multiple users on different script runs (including in different areas like student and faculty). For now this is good. This now is a fix for the insert function. On the next work interval, I will finish up the update and remove function, along with cleaning up the code so it is more mainstreamed. I think I also want to introduce a user class to make the parameters easier (at the moment there are like 8 parameters for each user field). I think if I just pass the user object, this will be easier to use. On the other hand, maybe not, we will see...
Update: I have completed the other methods, but now I am working on helper methods for making these things easier. At the moment, I am working on a helper method to find a user based on email. This will help for the update/remove user since the way users are updated will be harder without helper functions to find the reference in the database.
Update: I completed the helper method, and now the update and remove functions work successfully without overwriting. This works by removing/updating based on the email of a user since these are basically unique. The finder function finds the reference to the exact object, that way it can be referenced for the update or delete functions.
Update: I am working on the user class, which is requiring some work rewriting some of the code. It seems I am now having trouble converting the User object to a JSON object. It is not formatting as imagined, but I am close to fixing this.
Update: I have the insert function now working with the new user type, but now I am getting a key error with the update function (though it is coming from another helper function). I will start looking into this now.
Update: I am at a good stopping point where I have added some documentation (though more is needed). All existing problems were resolved, and this code is almost ready for a pull request. I will take a break on this for now.
Starting on this again, so I can update the connections to work with the FastAPI and React app (since now we have that form functionality).
Update: I spent these first thirty minutes setting up my branch so it is up to date, and also so it contains necessary files and code that is ignored by git commits. I also found out that there is a problem with the login part of the login/signup portion of the page. Any values for login result in this runtime error:
The signup part seems to be fine though (in the sense that it does not crash the app).
Update: It seems the signup page does not authenticate anything, instead it complains about the api key being used, so this will have to be explored. On the other hand, I have restructured some of the code in signup.jsx
so it will be easier to connect to the fastapi.
Update: I am working on consolidating the signup and login form into one component becuase it makes more sense to have that using the same logic. Also, I fixed the issue with the login and signup forms, and now a user can be added to our firebase users (verified by using my own email).
Update: I successfully combined both components into one component, and the functionality to create users still is maintained. I can now start with the backend part of this (connecting to fastAPI and such).
Update: I spent sometime trying to connect the react app to the FastAPI, but I am running into some trouble doing so. Still a work in progress.
Update: I am still working on connecting the signin/login form to the FastAPI, I am getting closer. The problem is the way the data is submitted, it does not match the expected input, which is interesting because it should be the same type of user object...
Update: I was successful in connecting the FastAPI and react app for user data, and both ends of the endpoint reflect this.
I was also able to use the methods from database.py
to add users to our realtime database (different from the login authenticator). I also tested to make sure the code I added to prevent the same user email from signing up works and it does ( it just returns -1, which is basic, but it is currently preventing double entries).
This image represents the first user inserted into the realtime database using the react app!
Update: I spent some time testing the changes I made to make sure it did not mess anything up (and works with presumable faculty users):
Overall, I think this is a good stopping point for today, with a good chunk of what we wanted to accomplish before the conference completed. At the same time, there is still much to do! Also, one thing I need to figure out is an easier way (if possible) to obtain all of the faculty emails from the Southwestern Directory page in an easier way than going through the alphabet manually... I started doing this manually then also decided to hold off until I asked around for easier ways on doing this.
It seems that the python functionality for interacting with the database is not needed since we are using google Auth (which integrates easily with firebase). Because of this, there is no longer any need to access the data from the form and send it to the FastAPI since its all done on the react side.
This ticket is responsible for creating the code that interacts with the database to create new users. Note that the database we are using is now Firebase. I will go ahead and put the link to the project (after I change the name to be snitch).