{"id":20604830,"url":"https://github.com/themost-framework/content-service-example","last_synced_at":"2025-03-06T16:53:14.361Z","repository":{"id":220278659,"uuid":"751192178","full_name":"themost-framework/content-service-example","owner":"themost-framework","description":"An example of managing files and users upload at @themost-framework ","archived":false,"fork":false,"pushed_at":"2024-02-01T07:11:41.000Z","size":171,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-17T02:21:48.301Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/themost-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-01T05:34:37.000Z","updated_at":"2024-02-01T07:08:51.000Z","dependencies_parsed_at":"2024-02-01T08:27:25.594Z","dependency_job_id":"a405925d-67ca-4b6c-9616-1845c96cfce8","html_url":"https://github.com/themost-framework/content-service-example","commit_stats":null,"previous_names":["themost-framework/content-service-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Fcontent-service-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Fcontent-service-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Fcontent-service-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Fcontent-service-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/themost-framework","download_url":"https://codeload.github.com/themost-framework/content-service-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242250872,"owners_count":20096895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T09:25:01.779Z","updated_at":"2025-03-06T16:53:14.326Z","avatar_url":"https://github.com/themost-framework.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# File Management with @themost/data\n\nThis project is an example of how to use `Attachment` model and `PrivateContentService` for managing files and user uploads.\n\nIt extends api services provided by `@themost/test` package at https://github.com/themost-framework/test\n\n## Installation\n\nClone this repository and install dependencies:\n\n```bash\ngit clone https://github.com/themost-framework/content-service-example\ncd content-service-example\nnpm install\n```\n\n## Test\n\nStart the application by running the following command:\n\n```bash\nnpm start\n```\nUse postman collection at `test/themost-test.postman_collection.json` for testing application services\n\nIMPORTANT NOTE: `@themost/test` package recycles the database on each test run. \n\n## Description\n\nThis example extends test api services and adds 3 new models:\n\n### Attachment\n\nThis model represents a file attachment and it is used for storing file metadata. It has the following properties: \n\n- `id` - the unique identifier of the attachment\n- `name` - the name of the attachment\n- `description` - the description of the attachment\n- `contentType` - the mime type of the attachment\n- `size` - the size of the attachment\n- `url` - the url of the attachment\n- `version` - the version of the attachment\n- `thumbnail` - the url of the thumbnail of the attachment\n- `dateCreated` - the date and time that the attachment was created\n- `dateModified` - the date and time that the attachment was modified\n- `datePublished` - the date and time that the attachment was published\n- `published` - a boolean value which indicates whether the attachment is published or not\n- `keywords` - a collection which contains keywords for the attachment\n- `attachmentType` - the type of the attachment (e.g. `image`, `video`, `audio`, `document`, `archive`, `other`)\n- `owner` - a user which is the owner of this attachment\n- `createdBy` - a user which created this attachment\n- `modifiedBy` - a user which modified this attachment\n\n### AttachmentType\n\nThis model represents a type of attachment. It has the following properties:\n\n- `id` - the unique identifier of the attachment type\n- `name` - the name of the attachment type\n- `description` - the description of the attachment type\n- `alternateName` - the alternate name of the attachment type which is also used as a key\n- `description` - the description of the attachment type\n- `dateCreated` - the date and time that the attachment type was created\n- `dateModified` - the date and time that the attachment type was modified\n- `createdBy` - a user which created this attachment\n- `modifiedBy` - a user which modified this attachment\n\n### CustomerOrder\n\nThis model represents a customer order and inherits from `Order` model provided by `@themost/test` package. It has the following properties:\n\n- `id` - the unique identifier of the order\n- `customer` - the customer which placed this order\n- `dateCreated` - the date and time that the order was created\n- `dateModified` - the date and time that the order was modified\n- `createdBy` - a user which created this order\n- `modifiedBy` - a user which modified this order\n- `orderedItem` - the ordered item e.g. a product\n- `orderNumber` - the order number\n- `orderStatus` - the status of the order\n- `paymentMethod` - the payment method of the order\n- `attachments` - a collection of attachments which are associated with this order\n\n\n### ExtraSchemaLoader\n\n`ExtraSchemaLoader` is being for loading extra data models during startup. \n\n```javascript\n// now try to embed a new schema loader which adds a collection of models\n// get application configuration\nconst configuration = app.getConfiguration();\n/**\n * Get the default schema loader strategy\n * @type {import('@themost/data').DefaultSchemaLoaderStrategy}\n */\nconst schemaLoader = configuration.getStrategy(SchemaLoaderStrategy);\n// extend DefaultSchemaLoaderStrategy.loaders collection and add our extra schema loader\n// which loads models from config/models folder\nschemaLoader.loaders.push(\n    new ExtraSchemaLoader(configuration)\n);\n```\n\n### PrivateContentService\n\n`PrivateContentService` is being used for managing content uploaded by end users. This service inherits from `ApplicationService` and it's being registered also during startup.\n\n```javascript\n// register private content service\napp.useService(PrivateContentService);\n\n```\n\nIt extends service router by adding a new route `/api/content/private/:file` for downloading files\n\n## Customer Order Flow\n\n1. Get access token\n\n```bash\ncurl --location 'http://localhost:3000/auth/token' \\\n--header 'Content-Type: application/x-www-form-urlencoded' \\\n--data-urlencode 'username=alexis.rees@example.com' \\\n--data-urlencode 'password=secret' \\\n--data-urlencode 'client_id=9165351833584149' \\\n--data-urlencode 'client_secret=hTgqFBUhCfHs/quf/wnoB+UpDSfUusKA' \\\n--data-urlencode 'grant_type=password' \\\n--data-urlencode 'scope=profile'\n```\n\n2. Create new order\n\n```bash\ncurl --location 'http://localhost:3000/api/CustomerOrders' \\\n--header 'Content-Type: application/json' \\\n--header 'Authorization: Bearer \u003caccess token\u003e' \\\n--data-raw '{\n    \"orderedItem\": {\n        \"name\": \"Apple MacBook Air (13.3-inch, 2013 Version)\"\n    },\n    \"customer\": {\n        \"email\": \"eric.stokes@example.com\"\n    }\n}'\n```\n\n3. Add attachment\n\n```bash\ncurl --location 'http://localhost:3000/api/CustomerOrders/811/AddAttachment' \\\n--header 'Authorization: Bearer \u003caccess token\u003e' \\\n--form 'file=@\"/tmp/lorem-ipsum.pdf\"' \\\n--form 'attachmentType[alternateName]=\"Other\"'\n```\n\n4. Download attachment\n\n```bash\ncurl --location 'http://localhost:3000/api/content/private/5JXFsvwnxNJf' \\\n--header 'Authorization: Bearer \u003caccess token\u003e'\n```\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemost-framework%2Fcontent-service-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthemost-framework%2Fcontent-service-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemost-framework%2Fcontent-service-example/lists"}