Hello,
I am currently developping a nextcloud app for the first time and I got this error then trying to use services :
Could not resolve service! Class "service" does not exist
Service :
namespace OCA\Accountancy\Service;
use OCA\Accountancy\Db\AccountMapper;
class AccountService {
private AccountMapper $mapper;
public function __construct() {
}
public function findAll(string $userId): array {
return $this->mapper->findAll($this->userId);
}
}
Mapper :
namespace OCA\Accountancy\Db;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
class AccountMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'accountancy_accounts');
}
public function findAll(string $userId) : array {
}
}
And the controller :
namespace OCA\Accountancy\Controller;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use OCA\Accountancy\Service\AccountService;
class AccountAPIController extends ApiController {
private AccountService $accountService;
private ?string $userId;
/**
* @param string $appName
* @param IRequest $request
* @param AccountService $service
* @param $userId
*/
public function __construct(string $appName, IRequest $request, AccountService $service, ?string $userId = null) {
parent::__construct($appName, $request);
$this->accountService = $service;
$this->userId = $userId;
}
/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* Return all of the boards that the current user has access to.
* @throws StatusException
*/
public function index() : DataResponse {
$accounts = $this->accountService->findAll($this->userId);
return new DataResponse($accounts, HTTP::STATUS_OK);
}
}
I really don’t see what I missed. Could it be related to the migration or some other config ?
I am running on docker if thats help.
Any help would be appreciated !
Edit
Full log entry :
{
"reqId": "g0YVIYTHLAaXQjpsMIf5",
"level": 3,
"time": "2022-11-28T21:42:09+00:00",
"remoteAddr": "172.22.0.1",
"user": "nextcloud",
"app": "index",
"method": "GET",
"url": "/apps/accountancy/api/v1/accounts",
"message": "Could not resolve service! Class \"service\" does not exist",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0",
"version": "24.0.6.1",
"exception": {
"Exception": "OCP\\AppFramework\\QueryException",
"Message": "Could not resolve service! Class \"service\" does not exist",
"Code": 0,
"Trace": [
{
"function": "OC\\AppFramework\\Utility\\{closure}",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
"*** sensitive parameters replaced ***"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"line": 108,
"function": "array_map",
"args": [
{
"__class__": "Closure"
},
[
{
"__class__": "ReflectionParameter",
"name": "appName"
},
{
"__class__": "ReflectionParameter",
"name": "request"
},
"*** sensitive parameters replaced ***",
{
"__class__": "ReflectionParameter",
"name": "userId"
}
]
]
},
{
"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"line": 116,
"function": "buildClass",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
{
"__class__": "ReflectionClass",
"name": "OCA\\Accountancy\\Controller\\AccountAPIController"
}
]
},
{
"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"line": 133,
"function": "resolve",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
"line": 465,
"function": "query",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
"line": 437,
"function": "queryNoFallback",
"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/App.php",
"line": 159,
"function": "query",
"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController"
]
},
{
"file": "/var/www/html/lib/private/Route/Router.php",
"line": 298,
"function": "main",
"class": "OC\\AppFramework\\App",
"type": "::",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController",
"index",
{
"__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
},
[
"1",
"accountancy.account_api.index"
]
]
},
{
"file": "/var/www/html/lib/base.php",
"line": 1030,
"function": "match",
"class": "OC\\Route\\Router",
"type": "->",
"args": [
"/apps/accountancy/api/v1/accounts"
]
},
{
"file": "/var/www/html/index.php",
"line": 36,
"function": "handleRequest",
"class": "OC",
"type": "::",
"args": []
}
],
"File": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"Line": 102,
"Previous": {
"Exception": "OCP\\AppFramework\\QueryException",
"Message": "Could not resolve OCA\\Accountancy\\Service\\AccountService! Class \"OCA\\Accountancy\\Service\\AccountService\" does not exist",
"Code": 0,
"Trace": [
{
"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"line": 133,
"function": "resolve",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Service\\AccountService"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
"line": 465,
"function": "query",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Service\\AccountService"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
"line": 437,
"function": "queryNoFallback",
"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Service\\AccountService"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"line": 89,
"function": "query",
"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Service\\AccountService",
true
]
},
{
"function": "OC\\AppFramework\\Utility\\{closure}",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
"*** sensitive parameters replaced ***"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"line": 108,
"function": "array_map",
"args": [
{
"__class__": "Closure"
},
[
{
"__class__": "ReflectionParameter",
"name": "appName"
},
{
"__class__": "ReflectionParameter",
"name": "request"
},
"*** sensitive parameters replaced ***",
{
"__class__": "ReflectionParameter",
"name": "userId"
}
]
]
},
{
"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"line": 116,
"function": "buildClass",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
{
"__class__": "ReflectionClass",
"name": "OCA\\Accountancy\\Controller\\AccountAPIController"
}
]
},
{
"file": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"line": 133,
"function": "resolve",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
"line": 465,
"function": "query",
"class": "OC\\AppFramework\\Utility\\SimpleContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php",
"line": 437,
"function": "queryNoFallback",
"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController"
]
},
{
"file": "/var/www/html/lib/private/AppFramework/App.php",
"line": 159,
"function": "query",
"class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
"type": "->",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController"
]
},
{
"file": "/var/www/html/lib/private/Route/Router.php",
"line": 298,
"function": "main",
"class": "OC\\AppFramework\\App",
"type": "::",
"args": [
"OCA\\Accountancy\\Controller\\AccountApiController",
"index",
{
"__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
},
[
"1",
"accountancy.account_api.index"
]
]
},
{
"file": "/var/www/html/lib/base.php",
"line": 1030,
"function": "match",
"class": "OC\\Route\\Router",
"type": "->",
"args": [
"/apps/accountancy/api/v1/accounts"
]
},
{
"file": "/var/www/html/index.php",
"line": 36,
"function": "handleRequest",
"class": "OC",
"type": "::",
"args": []
}
],
"File": "/var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php",
"Line": 122
},
"CustomMessage": "--"
}
}
Github link : https://github.com/NicolasDeGheselle/nextcloud-accountancy