Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add messages api #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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
56 changes: 56 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

# TS/JS-Files
[*.{ts,js}]
indent_size = 2

# JSON-Files
[*.json]
indent_style = tab

# ReST-Files
[*.rst]
indent_size = 4
max_line_length = 80

# YAML-Files
[*.{yaml,yml}]
indent_size = 2

# NEON-Files
[*.neon]
indent_size = 2
indent_style = tab

# package.json
[package.json]
indent_size = 2

# TypoScript
[*.{typoscript,tsconfig}]
indent_size = 2

# XLF-Files
[*.xlf]
indent_style = tab

# SQL-Files
[*.sql]
indent_style = tab
indent_size = 2

# .htaccess
[{_.htaccess,.htaccess}]
indent_style = tab
50 changes: 50 additions & 0 deletions Classes/Controller/MessageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package slub/slub-profile-messages
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace Slub\SlubProfileMessages\Controller;

use Psr\Http\Message\ResponseInterface;
use Slub\SlubProfileMessages\Domain\Model\Category;
use Slub\SlubProfileMessages\Domain\Repository\MessageRepository;
use Slub\SlubProfileMessages\Mvc\View\JsonView;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class MessageController extends ActionController
{
protected $view;
protected $defaultViewObjectName = JsonView::class;
protected MessageRepository $messageRepository;

/**
* @param MessageRepository $messageRepository
*/
public function __construct(MessageRepository $messageRepository)
{
$this->messageRepository = $messageRepository;
}

/**
* @param Category $category
* @return ResponseInterface
*/
public function listAction(Category $category): ResponseInterface
{
$messages = $this->messageRepository->findByCategoryUid(
$category->getUid(),
(int)$this->settings['message']['list']['limit']
);

$this->view->setVariablesToRender(['messageList']);
$this->view->assign('messageList', $messages);

return $this->jsonResponse();
}
}
52 changes: 52 additions & 0 deletions Classes/Domain/Model/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package slub/slub-profile-messages
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace Slub\SlubProfileMessages\Domain\Model;

use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;

class Category extends AbstractEntity
{
protected string $title = '';
protected string $code = '';

/**
* @return string $title
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @param string $title
*/
public function setTitle(string $title): void
{
$this->title = $title;
}

/**
* @return string $code
*/
public function getCode(): string
{
return $this->code;
}

/**
* @param string $code
*/
public function setCode(string $code): void
{
$this->code = $code;
}
}
102 changes: 102 additions & 0 deletions Classes/Domain/Model/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package slub/slub-profile-messages
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace Slub\SlubProfileMessages\Domain\Model;

use DateTime;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

class Message extends AbstractEntity
{
protected string $title = '';
protected string $content = '';
protected ?DateTime $datetime = null;
/**
* @Extbase\ORM\Lazy
* @var ?ObjectStorage<Category>
*/
protected ?ObjectStorage $categories = null;

/**
* Message constructor.
*/
public function __construct()
{
$this->categories = new ObjectStorage();
}

/**
* @return string $title
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @param string $title
*/
public function setTitle(string $title): void
{
$this->title = $title;
}

/**
* @return string $content
*/
public function getContent(): string
{
/** @extensionScannerIgnoreLine */
return $this->content;
}

/**
* @param string $content
*/
public function setContent(string $content): void
{
$this->content = $content;
}

/**
* @return DateTime $datetime
*/
public function getDatetime(): DateTime
{
return $this->datetime;
}

/**
* @param DateTime $datetime
*/
public function setDatetime(DateTime $datetime): void
{
$this->datetime = $datetime;
}

/**
* @return ObjectStorage<Category>
*/
public function getCategories(): ?ObjectStorage
{
return $this->categories;
}

/**
* @param ObjectStorage $categories
*/
public function setCategories(ObjectStorage $categories): void
{
$this->categories = $categories;
}
}
18 changes: 18 additions & 0 deletions Classes/Domain/Repository/CategoryRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package slub/slub-profile-messages
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace Slub\SlubProfileMessages\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\Repository;

class CategoryRepository extends Repository
{
}
39 changes: 39 additions & 0 deletions Classes/Domain/Repository/MessageRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package slub/slub-profile-messages
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace Slub\SlubProfileMessages\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;

class MessageRepository extends Repository
{
protected $defaultOrderings = [
'datetime' => QueryInterface::ORDER_DESCENDING
];

/**
* @param int $categoryUid
* @param int $limit
* @return QueryResultInterface
*/
public function findByCategoryUid(int $categoryUid, int $limit = 10): QueryResultInterface
{
$query = $this->createQuery();
$constraint = $query->equals('categories.uid', $categoryUid);

$query->matching($constraint);
$query->setLimit($limit);

return $query->execute();
}
}
Loading