Android App storing and searching data - java

I am looking for recommendations on how to have the data setup for a car wash appointment scheduler app I am making for fun.
I think there is a better way to store and search through the information with the way I have it setup below.
So far this is what I have,
On an online MYSQL Database:
User Table: name, street, zipcode, state, phone, username, password
Vehicles Table: username, year, make, model, color
On the App:
SharedPreferences with name, username, street, zipcode, state, phonenumber, password
SQLiteDatabase with year, make, model and color.
When the user logins on the main activity it checks for the username and password in the User Table on the online server. If there is a match it downloads the full user data. It also downoads all the vehicles that have the correct username from the Vehicles Table. Then this data is stored in the app in its proper place (user data in the Shared Preferences and the vehicles each entered into the SQLiteDatabase).
What I am having trouble implementing is a full history of service per vehicle. I think there is a more efficient way of getting the vehicle history without searching through an appointments of every users appointments every time I want to show the vehicles history.
Any recommendations?
EDIT:
The only other idea I have is to create a table on the server and the local SQLite that is the named "username-vehicle-appointments". That way it has to search through a smaller table and there is less data to download.
I am still trying to think a way to have the appointment request and confirmation setup.
EDIT:
Maybe have a new table on the server that is named new-appointments. The app could check the new-appointments table every few minutes to see if there are new appointment requests?
Does this sound like a good way to do this?
Thanks!

Not sure if this could help but have you thought about making an API and storing everything in JSON instead? It might work out better for your needs

Related

Multiple retrievable instances of an activity in Android Studio

I have an app, which takes input from a user (name, phone#, email) and generates a QR code. I used shared preferences to save the data so that the user does not have to fill out the fields every time. Right now, this only works for one person, and I want to add functionality for a second or third person.
Essentially, a main menu, that can open as many instances of the QR Generator as needed, and retrieve already open instances so that you can access the QR Codes of each person when you need it.
I have no idea where to start, so any help would be much appreciated. If you need to see the current code for the QR generator, I can attach that.
You should store the data in a database instead of sharedpreferences. And it should work smoothly. Database can store a lot of data and that too for multiple people. Which might help. You can store all the data of one person in one single row creating multiple columns for multiple attributes such as name, phone, email.
You can create multiple rows, and hence multiple people can store their data.
Database can used in two ways in android
Room persistence (also uses sqlite)
https://developer.android.com/training/data-storage/room
Raw SQLite database
https://developer.android.com/training/data-storage/sqlite

What is the practice in REST to name getting a resource by another resource ID

I'm creating a RESTful weather by cities service, i.e. a client knows a city ID and wants to receive a weather report in JSON from this city. For example:
{temperature:xxx, humidity:xxx, pressure:xxx}
Two issues:
What should the Get URL be? (My first idea: api/v1/WeatherByCityId/{cityid) but it looks raw and untidy... or is it OK?
Do I need to create two entities: City (table="cities") and Weather (table="weathers") and create a relationship? OR better create one entity WeathersCities(table="weathers_cities") (or whatever...)?
(I'm not gonna use 3rd party weather services, please don't suggest RestTemplate, WebClient, FeignClient, etc. Yes, I will fill the weather data by myself every hour.
Lets say you want to fetch the weather for a city, Lets store the city seperately in a City table and make City Id a primary key and put all the weather related data for the city in a seperate table Weather by keeping a foreign key City Id.
The RESTAPI would then be as such.
https://yourdomain.com/api/v1/city/{cityId}/weather
If your app's scope increases maybe later then you can reuse this same table principle and then the RESTAPI would be
https://yourdomain.com/api/v1/city/{cityId}?parameter=any_entity_you_have_mapped_with_city
To summarize this, If your APP is just going to be about weather in the city then having a same table for both entities is okay. However, if you want that your APP can be used for querying a lot of other information about multiple entities like population, schools, etc then having a seperate table is a much better approach. I would recommend keeping seperate tables for the 2. This approach also makes the DB highly manageable. Let me know if you have some questions. Hope this helps :)
A One to Many mapping of City with Weathers is preferred.
Your weather table will have city_id as a foreign key for mapping.
The URL you suggested is a good way to go and will be easier to maintain if you're going for GET Mapping.
api/v1/weather/{cityid}
It will be more flexible to use so.

What is a good practice to make authentification design(login form) for a system

Hi guys currently I am making an employee managment system.
I have made some forms of the applications like CRUD form of employee ,and stuff.
I also have implemented the login form , with users from database but I am having a problem to design the database correctly.
I want each time that I add an employee from Employee CRUD form , to be added as a user that can login into the system.. Currently I am adding users manually in the database, but I dont want this , because the users will be from 3 categories , Employee,Admin,And manager..
I am using JPA for database.Below I will show you a photo of the database schema.
What will be a good practice so each time I add an employee to be added as a USER that can login into the system,
Thank you for every answer, and for your time..
The easiest solution would be to have booleans inside your employee table, (isUser, isManager ...). This is good if you can have one or more roles and if you don't need more informations (a user is just an employee with a boolean checked).
--
If you need more informations about your roles, you can link your employee table to an other table with the fields you need.
For exemple between an employee and a user, add a foreign key inside Employee (userID) and a table named user with the fields you need. For example :
userID, password, lastConnectionDate ...
--
An other way would be to have a table "roles" and a table "employe". The idea is to add an other table "employeeRoles" that have 3 keys :
IDEmployeeRoles, IDEmployee, IDRole
Like that you will be able to link many employees with many roles.

Checking for updating mysql table

I need help with my project. I've made some swing java app which allowed to users make some operations with database (deleting, adding, inserting etc). Then this app has 2 roles, for whom who made the change (delete,add,insert into database) and for whom who check it. So for users who check, I have to make smth which alarm them, like "this user added smth to this table now". So I have no idea how to realise it, first of all I think I should write smth for check database changes like every minute? Like ScheduledExecutorService? Maybe. But I don't know how to check it for changes? For example i have table employee, it has columns like: name, surname, tel.number, salary. For example some user change salary from 100 to 200. So how it checks this table for changing? Maybe someone could show me example? Because I couldn't find it, I couldn't do it for 2 days. Please! Any help would be very much appreciated!

What's the best way to secure userID when sending reset-password-link

I created a servlet that checks for userID in LDAP and if it is there, it sends email to that
user with link:
"Please follow this link to reset your password" ;
I was told that this is not a good practice and that I should create table in MySQl with userID, timeResetRequested, GUID fields.
And pass this GUID in email instead of userID.
And to delete that record after 2 hours.
Is there a better and cleaner way to accomplish this and still have it secure?
Yes, that is a much better way.
The question about whether to send a GUID or user id doesn't matter AS much as the reset time out however.
Imagine that you reset your password one day, and then 2 months later you sell your account. You could then recover your account by resetting your password on a 2 month old email. You would not need to know the new account password to reset it, but rather just simply log in to your email and hack back your account.
Now, despite saying that the reset timer is more important than the guid/user id, you must think, do you want your users knowing their user id? If you don't, a GUID is a nice way to mask it.

Categories

Resources