Skip to content

Commit

Permalink
Merge branch 'v2/comment' of https://github.com/uasoft-indonesia/bada…
Browse files Browse the repository at this point in the history
…so-post-module into v2/comment
  • Loading branch information
miftahurrahmi committed Feb 20, 2024
2 parents 3686061 + cbbb882 commit a04fc97
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 62 deletions.
22 changes: 11 additions & 11 deletions src/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function add(Request $request)

try {
$request->validate([
'title' => 'required|string|max:255',
'title' => 'required|string|max:255',
'meta_title' => 'nullable|string|max:255',
'slug' => 'required|string|max:255|unique:Uasoft\Badaso\Module\Post\Models\Category',
'content' => 'nullable|string',
'parent_id' => 'nullable|exists:Uasoft\Badaso\Module\Post\Models\Category,id',
'slug' => 'required|string|max:255|unique:Uasoft\Badaso\Module\Post\Models\Category',
'content' => 'nullable|string',
'parent_id' => 'nullable|exists:Uasoft\Badaso\Module\Post\Models\Category,id',
]);

$category = Category::create($request->all());
Expand All @@ -54,7 +54,7 @@ public function read(Request $request)
{
try {
$request->validate([
'id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Category',
'id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Category',
'except' => 'nullable|in:true,false',
]);

Expand All @@ -76,7 +76,7 @@ public function readBySlug(Request $request)
{
try {
$request->validate([
'slug' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Category',
'slug' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Category',
'except' => 'nullable|in:true,false',
]);

Expand All @@ -100,12 +100,12 @@ public function edit(Request $request)

try {
$request->validate([
'id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Category',
'title' => 'required|string|max:255',
'id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Category',
'title' => 'required|string|max:255',
'meta_title' => 'nullable|string|max:255',
'slug' => 'required|string|max:255|exists:Uasoft\Badaso\Module\Post\Models\Category,slug',
'content' => 'nullable|string',
'parent_id' => 'nullable|exists:Uasoft\Badaso\Module\Post\Models\Category,id',
'slug' => 'required|string|max:255|exists:Uasoft\Badaso\Module\Post\Models\Category,slug',
'content' => 'nullable|string',
'parent_id' => 'nullable|exists:Uasoft\Badaso\Module\Post\Models\Category,id',
]);

$category = Category::findOrFail($request->id);
Expand Down
22 changes: 11 additions & 11 deletions src/Controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ public function add(Request $request)
try {
if (Auth::check()) {
$request->validate([
'post_id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Post,id',
'post_id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Post,id',
'parent_id' => 'nullable|exists:Uasoft\Badaso\Module\Post\Models\Comment,id',
'content' => 'required|string',
'content' => 'required|string',
]);

$post = Post::find($request->post_id);

$comment = Comment::create([
'post_id' => $request->post_id,
'post_id' => $request->post_id,
'parent_id' => $request->parent_id ?? null,
'user_id' => auth()->user()->id,
'content' => $request->content,
'user_id' => auth()->user()->id,
'content' => $request->content,
]);

$post->comment_count += 1;
Expand Down Expand Up @@ -144,19 +144,19 @@ public function edit(Request $request)

try {
$request->validate([
'id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Comment,id',
'post_id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Post,id',
'id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Comment,id',
'post_id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Post,id',
'parent_id' => 'nullable|exists:Uasoft\Badaso\Module\Post\Models\Comment,id',
'content' => 'required|string',
'content' => 'required|string',
'approved' => 'required',
]);

$comment = Comment::findOrFail($request->id);
$comment->update([
'post_id' => $request->post_id,
'post_id' => $request->post_id,
'parent_id' => $request->parent_id ?? null,
'user_id' => auth()->user()->id,
'content' => $request->content,
'user_id' => auth()->user()->id,
'content' => $request->content,
'approved' => $request->approved,
]);

Expand Down
14 changes: 7 additions & 7 deletions src/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function add(Request $request)

try {
$request->validate([
'title' => 'required|string|max:255',
'title' => 'required|string|max:255',
'meta_title' => 'nullable|string|max:255',
'slug' => 'required|string|max:255|unique:Uasoft\Badaso\Module\Post\Models\Tag',
'content' => 'nullable|string',
'slug' => 'required|string|max:255|unique:Uasoft\Badaso\Module\Post\Models\Tag',
'content' => 'nullable|string',
]);

$tags = Tag::create($request->all());
Expand Down Expand Up @@ -89,11 +89,11 @@ public function edit(Request $request)

try {
$request->validate([
'id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Tag,id',
'title' => 'required|string|max:255',
'id' => 'required|exists:Uasoft\Badaso\Module\Post\Models\Tag,id',
'title' => 'required|string|max:255',
'meta_title' => 'nullable|string|max:255',
'slug' => 'required|string|max:255|exists:Uasoft\Badaso\Module\Post\Models\Tag,slug',
'content' => 'nullable|string',
'slug' => 'required|string|max:255|exists:Uasoft\Badaso\Module\Post\Models\Tag,slug',
'content' => 'nullable|string',
]);

$tags = Tag::findOrFail($request->id);
Expand Down
13 changes: 6 additions & 7 deletions src/Helpers/GetData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public static function getData($model, $request, $relations = [])
{
$posts = [];
$builder_params = [
'limit' => isset($request['limit']) ? $request['limit'] : 10,
'page' => isset($request['page']) ? $request['page'] : null,
'category' => isset($request['category']) ? $request['category'] : null,
'tag' => isset($request['tag']) ? $request['tag'] : null,
'order_field' => isset($request['order_field']) ? $request['order_field'] : 'id',
'limit' => isset($request['limit']) ? $request['limit'] : 10,
'page' => isset($request['page']) ? $request['page'] : null,
'category' => isset($request['category']) ? $request['category'] : null,
'tag' => isset($request['tag']) ? $request['tag'] : null,
'order_field' => isset($request['order_field']) ? $request['order_field'] : 'id',
'order_direction' => isset($request['order_direction']) ? $request['order_direction'] : 'asc',
'search' => isset($request['search']) ? $request['search'] : '',
'search' => isset($request['search']) ? $request['search'] : '',
];

$posts = GetData::serverSide($model, $builder_params, $relations);
Expand Down Expand Up @@ -157,7 +157,6 @@ public static function getPopularPosts($model, $request, $relations, $oldest)

$response = json_decode($res->getBody()->getContents());
if (array_key_exists('rows', (array) $response)) {

// sort and limited google track view
$response->rows = collect($response->rows)->sortByDesc(function ($row) {
[$slug, $count] = $row;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MakeUserIdNullableOnBadasoCommentsTable extends Migration
*/
public function up()
{
Schema::table(config('badaso.database.prefix') . 'comments', function (Blueprint $table) {
Schema::table(config('badaso.database.prefix').'comments', function (Blueprint $table) {
$table->foreignId('user_id')->nullable()->change();
});
}
Expand All @@ -25,7 +25,7 @@ public function up()
*/
public function down()
{
Schema::table(config('badaso.database.prefix') . 'comments', function (Blueprint $table) {
Schema::table(config('badaso.database.prefix').'comments', function (Blueprint $table) {
$table->foreignId('user_id')->nullable(false)->change();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AddNewColumnToBadasoCommentsTable extends Migration
*/
public function up()
{
Schema::table(config('badaso.database.prefix') . 'comments', function (Blueprint $table) {
Schema::table(config('badaso.database.prefix').'comments', function (Blueprint $table) {
$table->string('guest_name')->nullable()->after('parent_id');
$table->string('guest_email')->nullable()->after('guest_name');
$table->boolean('approved')->default(false)->after('content');
Expand All @@ -27,7 +27,7 @@ public function up()
*/
public function down()
{
Schema::table(config('badaso.database.prefix') . 'comments', function (Blueprint $table) {
Schema::table(config('badaso.database.prefix').'comments', function (Blueprint $table) {
$table->dropColumn('guest_name');
$table->dropColumn('guest_email');
$table->dropColumn('approved');
Expand Down
31 changes: 31 additions & 0 deletions src/Swagger/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* tags={"category"},
* summary="Browse Category",
* description="Returns list of Category",
*
* @OA\Response(response=200, description="Successful operation"),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=401, description="Unauthorized"),
Expand All @@ -21,23 +22,28 @@
* tags={"category"},
* summary="Get Category based on id",
* description="Returns Category based on id",
*
* @OA\Parameter(
* name="id",
* required=true,
* in="query",
*
* @OA\Schema(
* type="integer"
* )
* ),
*
* @OA\Parameter(
* name="except",
* required=false,
* in="query",
* description="Get the rest of categories.",
*
* @OA\Schema(
* type="boolean"
* )
* ),
*
* @OA\Response(response=200, description="Successful operation"),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=401, description="Unauthorized"),
Expand All @@ -52,24 +58,29 @@
* tags={"category"},
* summary="Get Category based on slug",
* description="Returns Category based on slug",
*
* @OA\Parameter(
* name="slug",
* required=true,
* in="query",
* example="category-example",
*
* @OA\Schema(
* type="string"
* )
* ),
*
* @OA\Parameter(
* name="except",
* required=false,
* in="query",
* description="Get the rest of categories.",
*
* @OA\Schema(
* type="boolean"
* )
* ),
*
* @OA\Response(response=200, description="Successful operation"),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=401, description="Unauthorized"),
Expand All @@ -84,10 +95,14 @@
* tags={"category"},
* summary="Insert new Category",
* description="Insert new Category into database",
*
* @OA\RequestBody(
*
* @OA\MediaType(
* mediaType="application/json",
*
* @OA\Schema(
*
* @OA\Property(
* property="title",
* type="object",
Expand Down Expand Up @@ -116,6 +131,7 @@
* )
* )
* ),
*
* @OA\Response(response=200, description="Successful operation"),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=401, description="Unauthorized"),
Expand All @@ -133,10 +149,14 @@
* tags={"category"},
* summary="Edit an existing Category",
* description="Edit an existing Category",
*
* @OA\RequestBody(
*
* @OA\MediaType(
* mediaType="application/json",
*
* @OA\Schema(
*
* @OA\Property(
* property="id",
* type="object",
Expand Down Expand Up @@ -170,6 +190,7 @@
* )
* )
* ),
*
* @OA\Response(response=200, description="Successful operation"),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=401, description="Unauthorized"),
Expand All @@ -187,10 +208,14 @@
* tags={"category"},
* summary="Delete one record of Category",
* description="Delete one record of Category",
*
* @OA\RequestBody(
*
* @OA\MediaType(
* mediaType="application/json",
*
* @OA\Schema(
*
* @OA\Property(
* property="id",
* type="object",
Expand All @@ -199,6 +224,7 @@
* )
* )
* ),
*
* @OA\Response(response=200, description="Successful operation"),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=401, description="Unauthorized"),
Expand All @@ -216,10 +242,14 @@
* tags={"category"},
* summary="Delete multiple record of Category",
* description="Delete multiple record of Category",
*
* @OA\RequestBody(
*
* @OA\MediaType(
* mediaType="application/json",
*
* @OA\Schema(
*
* @OA\Property(
* property="ids",
* type="object",
Expand All @@ -228,6 +258,7 @@
* )
* )
* ),
*
* @OA\Response(response=200, description="Successful operation"),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=401, description="Unauthorized"),
Expand Down
Loading

0 comments on commit a04fc97

Please sign in to comment.