Skip to content

Commit

Permalink
Merge pull request #10 from janakhpon/updates/2021-09-06/strapi-custo…
Browse files Browse the repository at this point in the history
…m-endpoint

[updates] - added an example repo for strapi-custom-endpoint
  • Loading branch information
janakhpon authored Sep 6, 2021
2 parents 001ff16 + 6aa23d9 commit 33cfe58
Show file tree
Hide file tree
Showing 58 changed files with 15,836 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ A collection of mono repos from my personal blog posts.
[Graphql Subscriptions with Nest.js](https://janakhpon.gitlab.io/posts/nest-graphql-subscriptions)

[Nestjs graphql-redis-subscriptions](https://janakhpon.gitlab.io/posts/nest-graphql-redis-subscriptions)

[Strapi Custom Endpoint](https://janakhpon.gitlab.io/posts/strapi-custom-endpoint)
16 changes: 16 additions & 0 deletions strapi-custom-endpoint/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions strapi-custom-endpoint/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HOST=0.0.0.0
PORT=1337
3 changes: 3 additions & 0 deletions strapi-custom-endpoint/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.cache
build
**/node_modules/**
27 changes: 27 additions & 0 deletions strapi-custom-endpoint/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"parser": "babel-eslint",
"extends": "eslint:recommended",
"env": {
"commonjs": true,
"es6": true,
"node": true,
"browser": false
},
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": false
},
"sourceType": "module"
},
"globals": {
"strapi": true
},
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"no-console": 0,
"quotes": ["error", "single"],
"semi": ["error", "always"]
}
}
114 changes: 114 additions & 0 deletions strapi-custom-endpoint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
############################
# OS X
############################

.DS_Store
.AppleDouble
.LSOverride
Icon
.Spotlight-V100
.Trashes
._*


############################
# Linux
############################

*~


############################
# Windows
############################

Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp


############################
# Packages
############################

*.7z
*.csv
*.dat
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.com
*.class
*.dll
*.exe
*.o
*.seed
*.so
*.swo
*.swp
*.swn
*.swm
*.out
*.pid


############################
# Logs and databases
############################

.tmp
*.log
*.sql
*.sqlite
*.sqlite3


############################
# Misc.
############################

*#
ssl
.idea
nbproject
public/uploads/*
!public/uploads/.gitkeep

############################
# Node.js
############################

lib-cov
lcov.info
pids
logs
results
node_modules
.node_history

############################
# Tests
############################

testApp
coverage

############################
# Strapi
############################

.env
license.txt
exports
*.cache
build
.strapi-updater.json
3 changes: 3 additions & 0 deletions strapi-custom-endpoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Strapi application

A quick description of your strapi application
Empty file.
60 changes: 60 additions & 0 deletions strapi-custom-endpoint/api/article/config/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"routes": [
{
"method": "GET",
"path": "/articles",
"handler": "article.find",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/customarticles",
"handler": "article.customFind",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/articles/count",
"handler": "article.count",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/articles/:slug",
"handler": "article.findOne",
"config": {
"policies": []
}
},
{
"method": "POST",
"path": "/articles",
"handler": "article.create",
"config": {
"policies": []
}
},
{
"method": "PUT",
"path": "/articles/:id",
"handler": "article.update",
"config": {
"policies": []
}
},
{
"method": "DELETE",
"path": "/articles/:id",
"handler": "article.delete",
"config": {
"policies": []
}
}
]
}
24 changes: 24 additions & 0 deletions strapi-custom-endpoint/api/article/controllers/article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { sanitizeEntity } = require('strapi-utils');

module.exports = {
/**
* Retrieve a record.
*
* @return {Object}
*/


async customFind() {
const entity = await strapi.query('article').model.fetchAll( {
columns: ['id','title', 'description']
});
return sanitizeEntity(entity, { model: strapi.models.article });
},

async findOne(ctx) {
const { slug } = ctx.params;

const entity = await strapi.services.article.findOne({ slug });
return sanitizeEntity(entity, { model: strapi.models.article });
},
};
8 changes: 8 additions & 0 deletions strapi-custom-endpoint/api/article/models/article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/models.html#lifecycle-hooks)
* to customize this model
*/

module.exports = {};
53 changes: 53 additions & 0 deletions strapi-custom-endpoint/api/article/models/article.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"kind": "collectionType",
"collectionName": "articles",
"info": {
"name": "article",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"title": {
"type": "string",
"required": true
},
"description": {
"type": "text",
"required": true
},
"content": {
"type": "richtext",
"required": true
},
"slug": {
"type": "uid",
"targetField": "title",
"required": true
},
"category": {
"model": "category",
"via": "articles"
},
"image": {
"model": "file",
"via": "related",
"allowedTypes": [
"files",
"images",
"videos"
],
"plugin": "upload",
"required": true,
"pluginOptions": {}
},
"author": {
"via": "articles",
"model": "writer"
}
}
}
8 changes: 8 additions & 0 deletions strapi-custom-endpoint/api/article/services/article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/services.html#core-services)
* to customize this service
*/

module.exports = {};
52 changes: 52 additions & 0 deletions strapi-custom-endpoint/api/category/config/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"routes": [
{
"method": "GET",
"path": "/categories",
"handler": "category.find",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/categories/count",
"handler": "category.count",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/categories/:slug",
"handler": "category.findOne",
"config": {
"policies": []
}
},
{
"method": "POST",
"path": "/categories",
"handler": "category.create",
"config": {
"policies": []
}
},
{
"method": "PUT",
"path": "/categories/:id",
"handler": "category.update",
"config": {
"policies": []
}
},
{
"method": "DELETE",
"path": "/categories/:id",
"handler": "category.delete",
"config": {
"policies": []
}
}
]
}
Loading

0 comments on commit 33cfe58

Please sign in to comment.