Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{css,less,scss}]
indent_style = space
indent_size = 2

[*.yml]
indent_style = space
indent_size = 2

[*.{js,jsx,json}]
indent_style = space
indent_size = 2
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
"extends": "airbnb",
"rules":{
// Prevent warnings for webpack resolve aliases.
"import/no-unresolved": "off",
// Prevent warnings for webpack extension resolution.
"import/extensions": "off",
// Prevent warnings for import statements with aliases.
"import/first": "off",
},
"settings": {
"react": {
"version": "latest"
}
}
};
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Build files
/dist/
/resources/styles/frontend/_sprite.scss
/resources/styles/*.config.scss

# Development files
/config.json

# Build modules
/node_modules/

# Composer packages
/vendor/

# NPM lockfile as it causes more problems than it solves
package-lock.json

# WordPress test environment
/tests/environment

# CLI tools
drone.json

# Common
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
.idea
18 changes: 18 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "stylelint-config-recommended-scss",
"plugins": [
"stylelint-order",
"stylelint-scss"
],
"rules": {
"no-empty-source": null,
"indentation": 2,
"order/order": [
"custom-properties",
"dollar-variables",
"declarations",
"rules",
"at-rules"
]
}
}
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

37 changes: 17 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# WordPress Backend Challenge

## Desafio para programadores backend em WordPress na CoffeeCode.

**Introdução**
**Endpoint**

O endpoint para consulta utilizando o parametro paged é o seguinte:

http://localhost/wp-json/myapp/v1/products?paged=1,1 (itens por página, página)

Produzirá um resultado como este:

Desenvolva um Plugin em WordPress usando o boilerplate do [WP Emerge](https://docs.wpemerge.com/#/starter/plugin/quickstart) que crie uma [rota personalizada](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/) que aceite pelo menos os paramentro `paged` que busque e liste os produtos em ordem de preço crescente, paginando de 5 em 5 e retorne o resultado como `JSON`, na seguinte estrutura:
```
{
id: 123,
Expand All @@ -16,29 +22,20 @@ Desenvolva um Plugin em WordPress usando o boilerplate do [WP Emerge](https://do
}
```

**Especifícações:**

* Criar uma rota personalizada com um parametro `paged` (opcional);
* Busque pelos produtos usando as rotas do Woocommerce no site [challenge.homolog.tech](https://challenge.homolog.tech/);
* Retorne o resultado em formato `JSON`;
* De preferencia utilizando o [WP Emerge Plugin](https://docs.wpemerge.com/#/starter/plugin/quickstart).
Obs: sem o parametro paged, irá trazer a quantidade padrão de 10 itens

**Instruções**
**Especifícações:**

1. Efetue o fork deste repositório e crie um branch com o seu nome e sobrenome. (exemplo: fulano-dasilva)
2. Após finalizar o desafio, crie um Pull Request.
3. Aguarde algum contribuidor realizar o code review.
✅ Criar uma rota personalizada com um parametro `paged` (opcional);

**Extra**
✅ Busque pelos produtos usando as rotas do Woocommerce no site [challenge.homolog.tech](https://challenge.homolog.tech/);

Opcional
1. Criar uma página no frontend que usando a rota personalizada via javascript.
✅ Retorne o resultado em formato `JSON`;

**Pré-requisitos**
✅ De preferencia utilizando o [WP Emerge Plugin](https://docs.wpemerge.com/#/starter/plugin/quickstart).

* PHP >= 8.1
* Orientado a objetos
✅ Criar uma página no frontend que use a rota personalizada via javascript. (página criada na ativação em: /external-product-listing/)

**Dúvidas**
**Notas Finais:**

> Em caso de dúvidas, crie uma issue.
Para o funcionamento correto após ser clonado o repoitório, ainda é necessário rodar `composer install` para configurar corretamente.
122 changes: 122 additions & 0 deletions app/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php
/**
* WP Emerge configuration.
*
* @link https://docs.wpemerge.com/#/framework/configuration
*
* @package MyApp
*/

return [
/**
* Default class namespace prefix.
*/
'namespace' => 'MyApp\\',

/**
* Array of service providers you wish to enable.
*/
'providers' => [
\WPEmergeAppCore\AppCore\AppCoreServiceProvider::class,
\WPEmergeAppCore\Assets\AssetsServiceProvider::class,
\WPEmergeAppCore\Avatar\AvatarServiceProvider::class,
\WPEmergeAppCore\Config\ConfigServiceProvider::class,
\WPEmergeAppCore\Image\ImageServiceProvider::class,
\WPEmergeAppCore\Sidebar\SidebarServiceProvider::class,
\MyApp\Routing\RouteConditionsServiceProvider::class,
\MyApp\View\ViewServiceProvider::class,
\MyApp\WordPress\AdminServiceProvider::class,
\MyApp\WordPress\AssetsServiceProvider::class,
\MyApp\WordPress\ContentTypesServiceProvider::class,
\MyApp\WordPress\ShortcodesServiceProvider::class,
\MyApp\WordPress\PluginServiceProvider::class,
\MyApp\WordPress\WidgetsServiceProvider::class,
\MyApp\CarbonFields\CarbonFieldsServiceProvider::class,
],

/**
* Array of route group definitions and default attributes.
* All of these are optional so if we are not using
* a certain group of routes we can skip it.
* If we are not using routing at all we can skip
* the entire 'routes' option.
*/
'routes' => [
'web' => [
'definitions' => __DIR__ . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'web.php',
],
'admin' => [
'definitions' => __DIR__ . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'admin.php',
],
'ajax' => [
'definitions' => __DIR__ . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'ajax.php',
],
],

/**
* Register middleware class aliases.
* Use fully qualified middleware class names.
*
* Internal aliases that you should avoid overriding:
* - 'flash'
* - 'old_input'
* - 'csrf'
* - 'user.logged_in'
* - 'user.logged_out'
* - 'user.can'
*/
'middleware' => [
// phpcs:ignore
// 'mymiddleware' => \MyApp\Middleware\MyMiddleware::class,
],

/**
* Register middleware groups.
* Use fully qualified middleware class names or registered aliases.
* There are a couple built-in groups that you may override:
* - 'web' - Automatically applied to web routes.
* - 'admin' - Automatically applied to admin routes.
* - 'ajax' - Automatically applied to ajax routes.
* - 'global' - Automatically applied to all of the above.
* - 'wpemerge' - Internal group applied the same way 'global' is.
*
* Warning: The 'wpemerge' group contains some internal WP Emerge
* middleware which you should avoid overriding.
*/
'middleware_groups' => [
'global' => [],
'web' => [],
'ajax' => [],
'admin' => [],
],

/**
* Optionally specify middleware execution order.
* Use fully qualified middleware class names.
*/
'middleware_priority' => [
// phpcs:ignore
// \MyApp\Middleware\MyMiddlewareThatShouldRunFirst::class,
// \MyApp\Middleware\MyMiddlewareThatShouldRunSecond::class,
],

/**
* Custom directories to search for views.
* Use absolute paths or leave blank to disable.
* Applies only to the default PhpViewEngine.
*/
'views' => [ dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'views' ],

/**
* App Core configuration.
*/
'app_core' => [
'path' => dirname( __DIR__ ),
'url' => plugin_dir_url( MY_APP_PLUGIN_FILE ),
],

/**
* Other config goes after this comment.
*/

];
15 changes: 15 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Load helpers.
* Define any generic functions in a helper file and then require that helper file here.
*
* @package MyApp
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Load helpers.
// phpcs:ignore
// require_once __DIR__ . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'myhelper.php';
Empty file added app/helpers/.gitkeep
Empty file.
15 changes: 15 additions & 0 deletions app/hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Declare any actions and filters here.
* In most cases you should use a service provider, but in cases where you
* just need to add an action/filter and forget about it you can add it here.
*
* @package MyApp
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// phpcs:ignore
// add_action( 'some_action', 'some_function' );
18 changes: 18 additions & 0 deletions app/routes/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* WordPress Admin Routes.
* WARNING: Do not use \MyApp::route()->all() here, otherwise you will override
* ALL custom admin pages which you most likely do not want to do.
*
* @link https://docs.wpemerge.com/#/framework/routing/methods
*
* @package MyApp
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Using our ExampleController to handle a custom admin page registered using add_menu_page(), for example.
// phpcs:ignore
// \MyApp::route()->get()->where( 'admin', 'my-custom-admin-page-slug' )->handle( 'ExampleController@admin' );
18 changes: 18 additions & 0 deletions app/routes/ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* WordPress AJAX Routes.
* WARNING: Do not use \MyApp::route()->all() here, otherwise you will override
* ALL AJAX requests which you most likely do not want to do.
*
* @link https://docs.wpemerge.com/#/framework/routing/methods
*
* @package MyApp
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Using our ExampleController to handle a custom ajax action, for example.
// phpcs:ignore
// \MyApp::route()->get()->where( 'ajax', 'my-custom-ajax-action' )->handle( 'ExampleController@ajax' );
22 changes: 22 additions & 0 deletions app/routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Web Routes.
* WARNING: Do not use \MyApp::route()->all() here, otherwise you will override
* ALL web requests which you most likely do not want to.
*
* @link https://docs.wpemerge.com/#/framework/routing/methods
*
* @package MyApp
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Using our ExampleController to handle the homepage, for example.
// phpcs:ignore
// \MyApp::route()->get()->url( '/' )->handle( 'ExampleController@home' );

// If we do not want to hardcode a url, we can use one of the available route conditions instead.
// phpcs:ignore
// \MyApp::route()->get()->where( 'post_id', get_option( 'page_on_front' ) )->handle( 'ExampleController@home' );
Loading