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 SchemaMongoose Schema. The documentation of how to create a Schema can be found here. 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.
However there, there is another use case where the user enters an external URL. For the external URL, we don't need to create a database record for it. The easiest way to implement this would be checking for the input field in the form. In the implementation of the form, there is a text field for images and uploader. Check if the input field is not empty then set the object as a URL string if the data is coming from the uploader then create a new database record
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 | Reason | |||||
---|---|---|---|---|---|---|---|
ID | Auto generated by Mongoose | This will be convenience for API user retrieve information about the attachment | |||||
File Name | A string represents file name of the attachment file uploaded | When user upload a user uploads a file or multiple files, each of the files will have a name of it. This will be useful for the user to remember what file they have uploaded when the user uploads a file or multiple files, each of the file will have a name of it. This will be useful for the user to remember what file they have uploaded | |||||
Type | Enumerated type with 2 possible value which are Image and docs | For simplicity, we will only have 2 type which are documents and pictures. The field cloud be an enum type of those 2 | |||||
MetaData | An example of how meta data object should contains:
| 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 |
...