android-vtop-chennai icon indicating copy to clipboard operation
android-vtop-chennai copied to clipboard

Display faculty cabin details

Open ezhil56x opened this issue 1 year ago • 17 comments

Feature Request

Is your feature request related to a problem? Please describe. Currently there is no option to view a particular faculty's cabin location

Describe the solution you'd like My idea is to implement a search function to find the faculty's cabin location which includes cabin number, floor, block

  • This will be helpful for a lot of students who are having trouble in finding a faculty's cabin
  • Through this students can easily search faculty's name and find the location of the faculty's cabin

ezhil56x avatar May 26 '23 18:05 ezhil56x

It's not a good idea to hard code this data into the app, we'll need a separate project to hold this data and offer it via an API which can then be fetched by this application.

therealsujitk avatar May 27 '23 05:05 therealsujitk

Hi @therealsujitk, I am interested to work on this. Can you assign me ?

Can we host the json file in GitHub itself and query each time when the student searches for a faculty's cabin. I thought of using Firebase but the cloud functions in Firebase is not included in free plan

ezhil56x avatar Jun 01 '23 09:06 ezhil56x

Can we host the json file in GitHub itself and query each time when the student searches for a faculty's cabin. I thought of using Firebase but the cloud functions in Firebase is not included in free plan

Doing something like that is a violation of GitHub's terms of service and will be taken down eventually. Besides, we'll need the API to handle the search queries which cannot be done on GitHub. You can try other services such as Vercel or Netlify.

therealsujitk avatar Jun 01 '23 09:06 therealsujitk

Ok bro, I will try out vercel or netlify and get back to you when the API part is ready. I will add authentication to update or delete the content. Is authentication required for GET also or not needed?

ezhil56x avatar Jun 01 '23 13:06 ezhil56x

Not required for GET requests.

therealsujitk avatar Jun 01 '23 15:06 therealsujitk

@therealsujitk I have completed the API part

/api/facultycabin - faculty cabin details of all faculty /api/facultycabin?n=1000 - faculty cabin details of faculty with empid 1000 /api/facultycabin?n=sa - faculty cabin details of faculties whose name contains sa in their name

This is the project structure

- faculty-cabin-api/
  - app.js
  - data.json
  - node_modules/
  - package-lock.json
  - package.json

I have planned to host the API in https://cyclic.sh which supports upto 10,000 API requests/month.

I have also added support to add, update and delete entry through various request methods with authentication. But most of the hosting platforms have read only file system, so I could not write back to data.json. If there is any work around for that I will setup workflow which gets the updated data from the API endpoint and adds it to data.json which is in the Github repository.

ezhil56x avatar Jun 03 '23 13:06 ezhil56x

You can also use a database like MongoDB to store your data, that would fix your write problem. The app will only use the GET requests, I assume you want to use the POST requests for another application, if you proceed with the workflow idea updating a single record can take up-to 2 minutes (maybe more) and you cannot update any other record during that time.

therealsujitk avatar Jun 05 '23 04:06 therealsujitk

@therealsujitk I have recreated the API and now it is using MongoDB so that add, update and delete everything works fine. I have planned to add Faculty Cabin under Staff in Profile section

/api/faculty/search?search=1000 - faculty cabin details of faculty with empid 1000 /api/faculty/search?search=sa - faculty cabin details of faculties whose name contains sa in their name

Can you give a short description on how can I implement this API on the app. I have attached a rough design of the UI I have planned. Comment your thoughts!

UI

ezhil56x avatar Jun 14 '23 20:06 ezhil56x

The UI will have to be similar to the Receipts fragment but with a search bar on top, this search bar should not have a button, we'll have to throttle requests as the user types. Can you give an example of what the api response looks like and what information about a faculty it returns.

The API will have to be implemented similar to how it's done for Moodle - MoodleApi.java. This task can be challenging so if you want I can work on integrating it with the app.

therealsujitk avatar Jun 15 '23 12:06 therealsujitk

@therealsujitk Currently the API is live on https://android-vtop-chennai-api.cyclic.app/

/ - success message to check whether the API is working or not /api/faculty - faculty cabin details of all faculties /api/faculty/search?search=1000 - faculty cabin details of faculty with empid 1000 /api/faculty/search?=search=asa - faculty cabin details of faculty whose names contains the string asa

This is the format of the data when searched through empid or facultyname

{
    "faculty": {
        "empid": "1000",
        "facultyname": "Test",
        "dept": "Test",
        "cabinlocation": "This is a test data",
        "_id": "648b68620130066aadbb77cc",
        "created_at": "2023-06-15T19:37:06.682Z",
        "updated_at": "2023-06-15T19:37:06.682Z",
        "__v": 0
    }
}

This is the format when faculty data does not exist

{
    "faculty": []
}

Can you give me a description on how to integrate all of these with the current app. I am interest to give a try on this challenging task or can you take over from here and integrate with the app?

ezhil56x avatar Jun 15 '23 19:06 ezhil56x

Can you give me a description on how to integrate all of these with the current app. I am interest to give a try on this challenging task or can you take over from here and integrate with the app?

If you're interested in taking this up then I'll definitely guide you through it but bear in mind it'll be a very long process, otherwise I can take over from here as well. Let me know.


Lets first clean up this API.

  • Instead of /api/faculty/search?search I think we can just change it to /api/faculty?search.
  • Instead of facultyname I think we can just have name since it's understood it's for faculty. Similarly cabinlocation can be changed to just location and dept to department.
  • Lets remove fields that you're not planning to use to reduce the amount of data that is being transmitted at a time. If you're using all of them then ignore this.
  • It will be good to call a particular version of this api /api/v1.0/faculty. This way if you plan to make breaking changes in future, you can do it on a newer version and users will still be able to use the app if they haven't updated it yet (This version need not be updated if it's not going to break the current version).
  • Your search parameter searches for both empid and a substring of the name. I'd like to substring of both empid and name, i.e. the search will check if it matches a part of the empid as well as the name so if a user searches for "10", they'll still get the result of the empid "1000".
  • Your /faculty route is taking a very long time to load probably because you are not limiting the data you are retrieving. Add a page or offset and display only 10 records at a time.
  • Use a caching package (such as node-cache for Node.js) to cache your data to speed up requests and reduce the load on your server.
  • Ensure you are taking care to prevent injection attacks that can allow attackers to tamper with the database.

therealsujitk avatar Jun 16 '23 03:06 therealsujitk

API is live on https://android-vtop-chennai-api.cyclic.app/

I have implemented the suggested changes. And I think version is not required for this simple API. page parameter is used only for api/faculty/ and not for search. Field names have been changed. node-cache have been enabled.

These are the latest endpoints of the API

/api/faculty/ - Shows details first 10 /api/faculty?page=2 - Shows details of next 10 and so on /api/faculty?search=1000 - Shows faculty cabin details of faculty with empid 1000 /api/faculty?search=asa - Shows faculty cabin details of faculty whose names contains substring asa

Format of the data when searched with name or empid

[
    {
        "empid": "1000",
        "pfix": "Test",
        "name": "Test",
        "department": "Test",
        "location": "This is a test location"
    }
]

Format of data when faculty does not exist

[]

From here I think you can takeover and integrate with the app.

ezhil56x avatar Jun 18 '23 10:06 ezhil56x

  • We don't need the pfix key, let it be a part of name.
  • The page parameter is required even while using search.
    [GET] /api/faculty?search=asa&page=2
    
  • I hope you've taken care that users cannot manipulate the database using the query parameters.
  • Have you handled error cases, for example database errors and set the status code accordingly?

If possible add me as a collaborator to your repository so I can take a look at the code.

therealsujitk avatar Jun 18 '23 10:06 therealsujitk

I have updated the API with your suggested changes. I have invited you as collaborator. You would be getting an invite

ezhil56x avatar Jun 18 '23 12:06 ezhil56x

Great! One small change, instead of the response being a JSON array ([...]), change it to a JSON object ({ "faculties": [...] }). This is better in case more fields are added in future (For example the next page or whether the next page exists).

I'll work on the integration probably later this month or next month.

therealsujitk avatar Jun 18 '23 13:06 therealsujitk

I have updated this suggested change also. Can you give me a description how to integrate this with the app. I want to give a try on this.

ezhil56x avatar Jun 18 '23 13:06 ezhil56x

  • A profile item (Find Faculty) will have to be create in the profile fragment under Personal for now, we'll have to find a better place for this later.
  • A new fragment like the Receipts fragment will have to be created with a search bar (no button). Results will load as the user types by throttling requests.
  • A card layout to display the faculties will have to be created.
  • The recycler view will get data from the API and display it, this view will be infinitely scroll-able, i.e. more results will load as you reach the bottom of the view.

All of this will have to be done with similar code style to the rest of the app.

  • Properly modulated code, Adapter for the recycler view, etc.
  • An interface for the API requests.
  • Similar design to the other card layouts.
  • Consistent margin and padding with the other layouts.

therealsujitk avatar Jun 18 '23 15:06 therealsujitk