fix: post counts

This commit is contained in:
2025-11-07 19:12:43 +02:00
parent 30edbc8330
commit 4b8394d7ba
2 changed files with 20 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ declare(strict_types=1);
namespace OCA\Forum\Controller;
use OCA\Forum\Db\CategoryMapper;
use OCA\Forum\Db\Thread;
use OCA\Forum\Db\ThreadMapper;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -24,6 +25,7 @@ class ThreadController extends OCSController {
string $appName,
IRequest $request,
private ThreadMapper $threadMapper,
private CategoryMapper $categoryMapper,
private IUserSession $userSession,
private LoggerInterface $logger,
) {
@@ -161,6 +163,19 @@ class ThreadController extends OCSController {
/** @var \OCA\Forum\Db\Thread */
$createdThread = $this->threadMapper->insert($thread);
// Update the category's thread and post counts
// A new thread includes an initial post, so increment both
try {
$category = $this->categoryMapper->find($categoryId);
$category->setThreadCount($category->getThreadCount() + 1);
$category->setPostCount($category->getPostCount() + 1);
$this->categoryMapper->update($category);
} catch (\Exception $e) {
$this->logger->warning('Failed to update category counts: ' . $e->getMessage());
// Don't fail the request if category update fails
}
return new DataResponse($createdThread->jsonSerialize(), Http::STATUS_CREATED);
} catch (\Exception $e) {
$this->logger->error('Error creating thread: ' . $e->getMessage());

View File

@@ -3102,7 +3102,7 @@
}
}
},
"/ocs/v2.php/apps/forum/api/users/me": {
"/ocs/v2.php/apps/forum/api/current-user": {
"get": {
"operationId": "forum_user-me",
"summary": "Get current user's forum profile",
@@ -3768,8 +3768,7 @@
"type": "object",
"required": [
"threadId",
"content",
"slug"
"content"
],
"properties": {
"threadId": {
@@ -3783,7 +3782,9 @@
},
"slug": {
"type": "string",
"description": "Post slug"
"nullable": true,
"default": null,
"description": "Post slug (auto-generated if not provided)"
}
}
}