I. Problem
The current system only supports file image upload. There are many issues will arise in the future with the current implementation. Because the image upload API can only handle Post request which makes it not restful API. The first sub-task is to make image upload API restful. Having image API to be restful increases consistency with other API endpoints. So as an API user, I can query for an image with an ID and it will return URL pointing to the location of that image. The functionality of the image API will stay the same, but it will be easier for admin to delete the image that is not being referenced anywhere in platform.
II. Idea
The proposed solution will consist of adding a new Mongo Schema. For now, we can call it Attachment. The reason for that is because of each of the file uploaded to the platform, we have to efficiently manage the data, eliminating junk data in the platform that is not referenced anywhere.
Having an attachment object in place, we use Mongoosecrudify to create a restful API to manage attachment record. The relation of the attachment object with person record is many to one, ie: each person will have one or many attachments uploaded.
Attachment schema for Mongo DB:
Field | Description |
---|---|
ID | Auto generated by Mongoose |
File Name | When user upload a file or multiple files, each of the file will have a name of it. This will be useful for user to remember what file they have uploaded |
Type | For simplicity, we will only have 2 type which are documents and pictures. The field cloud be an enum type of those 2 |
MetaData | This meta data will contain information such as id of user who upload the image, the date and time of the file uploaded. Meta data will be helpful when user removed from the system. The system would just find all reference of the that user id and delete all database record about it |
Add Comment