Allow users to declare their State & District via their profile
Problem statement:
As a sunbird user, one should be able to do declare their District (Choose State -> Choose District).
Proposed solution 1:
Storing the location of the user in separate table & separate API for updating location
Pros:
- Implementation will not impact existing API for create/update
Cons:
- Data to be loaded from multiple calls to database.
- Read user would require a flag to fetch whether location data is required by end-user or not.
DB changes
New user_location table
Column | Changes |
---|---|
id(Primary Key) | Auto generated |
userId | User Id of the user |
locationIds | Location id of the location selected by User (Eg. state locationId, district location id) |
APIs Added
- Update location
POST /user/v1/update/location{ "request": {
Response
"locationCode" : "locationCode"
}
}
Note: User Id will be taken from "x-authenticated-user-token".200 OK - Location of user is successfully stored
401 Unauthorised - In case user API is called without proper user-access token.
400 Bad Request - Invalid location code or invalid type of location passed (only district is valid as of now)
Proposed solution 2:
Using the same table for storage and update using same API.
Pros:
- Getting user location data will be available directly with user information.
- We can create/update the location of user in Create/Update user request.
Cons:
- Changes in current create/update API logic & extending the storage structure of existing tables.
DB changes
user table changes
Column | Changes |
---|---|
locationIds | Added - Location id of the location selected by User (Eg. state locationId, district location id) |
APIs Added
- Update location
POST /user/v1/create or /user/v1/update
Note: Other parameter can be same as create/update user request, we will add one more parameter to update the location{
{ "request": {
"locationCode" : "locationCode"
}
}
}Response
200 OK - Location of user is successfully stored
401 Unauthorised - In case user API is called without proper user-access token.
400 Bad Request - Invalid location type or invalid location id. (only code for location type district will be allowed)
Note: User read api will return the location data as follows, for ease of display.
Read is made efficient by storing locationIds in database, which has informaiton for district + state (full hierarchy)
{
"locations": [{
"type":"locationType"
"value":"locationValue"
}],
"locationIds" : ["locationId1", "locationId2"]
}