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

update staging #572

Closed
wants to merge 87 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
73d3073
fix: checking sending email template
RaphAlemoh Aug 15, 2024
8e2a7c2
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
RaphAlemoh Aug 15, 2024
bcaaf4c
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
RaphAlemoh Aug 19, 2024
5a47aa8
fix: resolve conflit in api.php
RaphAlemoh Aug 21, 2024
1d70ee0
fix: resolve conflict in api file
RaphAlemoh Aug 23, 2024
ef6bf14
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
RaphAlemoh Aug 23, 2024
f23f842
fix:refactoring-blog-creation-endpoint-to-meet-c#-standard
sparkybug Aug 24, 2024
5a422b5
added test script
Olat-nji Aug 24, 2024
7a159e2
fix:Fixed workflow for postman api tests
Olat-nji Aug 24, 2024
3fbab9c
Merge branch 'hngprojects:dev' into dev
Olat-nji Aug 24, 2024
caa2033
Merge pull request #552 from sparkybug/fix/refactoring-blog-creation-…
tulbadex Aug 24, 2024
2973bae
Merge pull request #553 from Olat-nji/dev
timiajayi Aug 24, 2024
e91586b
fix: update user profile
abdielbytes Aug 24, 2024
0e55ec1
fix: notification route to match fe
abdielbytes Aug 24, 2024
33aba37
fix
abdielbytes Aug 24, 2024
ffd57df
fix:refactoring-user-deletion-endpoint-to-meet-c#-standard
sparkybug Aug 24, 2024
28d21bd
Merge https://github.com/Muhammad235/hng_boilerplate_php_laravel_web …
Muhammad235 Aug 24, 2024
871480f
update: get user notifucation payload
Muhammad235 Aug 24, 2024
871a99d
fix: Roles and Permissions migrations
ezeanyimhenry Aug 24, 2024
3d73421
fix: Roles and permissions relationship
ezeanyimhenry Aug 24, 2024
4dc1df9
fix: roles and permissions controllers and tests
ezeanyimhenry Aug 24, 2024
42344e1
Merge branch 'hngprojects:dev' into newsletter
abdielbytes Aug 24, 2024
779fcb7
Merge branch 'dev' of https://github.com/ezeanyimhenry/hng_boilerplat…
ezeanyimhenry Aug 24, 2024
b33328c
refactor: clear all notifications
abdielbytes Aug 24, 2024
ec29a00
fix: roles test
ezeanyimhenry Aug 24, 2024
1cf2abe
fix: BlogController Image Path
ezeanyimhenry Aug 24, 2024
0ad7145
Merge pull request #559 from ezeanyimhenry/fix/roles-and-permissions
Dev-Tonia Aug 24, 2024
f52edf5
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
sparkybug Aug 24, 2024
6769adf
Merge pull request #554 from abdielbytes/abdiel
Dev-Tonia Aug 24, 2024
eecbe24
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
sparkybug Aug 24, 2024
b6a830f
Merge pull request #557 from Muhammad235/feat/user-notification
Dev-Tonia Aug 24, 2024
957e163
fix:refactoring-job-deletion-endpoint-to-meet-c#-standard
sparkybug Aug 24, 2024
7dd83b2
fix: helpcenter
Dev-Tonia Aug 24, 2024
2b1977a
Refactoring API Endpoint for-Retrieves a Specific Help Center Topic b…
timiajayi Aug 24, 2024
9082ea3
Refactoring API Endpoint for-Retrieves a Specific Help Center Topic b…
timiajayi Aug 24, 2024
7f112f7
Merge pull request #556 from sparkybug/fix/refactoring-user-deletion-…
Dev-Tonia Aug 24, 2024
04b344c
fix:refactoring-job-deletion-endpoint-to-meet-c#-standard
sparkybug Aug 24, 2024
717bf70
fix/refactoring-endpoint-for-creating-an-email-to-meet-c#-standard
sparkybug Aug 24, 2024
ff4ad44
[FIX](PHP) Refactoring API Endpoint for-Updates an Existing Help Cent…
timiajayi Aug 24, 2024
b9afa1d
Merge pull request #561 from Dev-Tonia/feat/profile-page
timiajayi Aug 24, 2024
2f128d1
Merge pull request #555 from abdielbytes/newsletter
timiajayi Aug 24, 2024
5f878a4
jobpost
bamo100 Aug 24, 2024
acb0042
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
bamo100 Aug 24, 2024
6db8f22
Merge branch 'hngprojects:dev' into fix/refactorHelpUpdate
timiajayi Aug 24, 2024
b362477
Merge branch 'hngprojects:dev' into fix/refactorhelpid
timiajayi Aug 24, 2024
8070e4e
refactor:product-categories-endpoint
Muhammad235 Aug 24, 2024
5478ec8
[FIX](PHP) Refactoring API Endpoint for-Deletes a Help Center Topic
timiajayi Aug 24, 2024
6b117f9
Update postman-api-tests.yml
Olat-nji Aug 24, 2024
682f395
Merge pull request #573 from hngprojects/Olat-nji-patch-3
timiajayi Aug 24, 2024
1f95017
Merge pull request #569 from Muhammad235/refactor/endpoint-for-produc…
timiajayi Aug 24, 2024
c49200c
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
bamo100 Aug 24, 2024
36fb921
Merge branch 'hngprojects:dev' into fix/refactorhelpdelete
timiajayi Aug 24, 2024
f02ad95
Merge pull request #562 from timiajayi/fix/refactorhelpid
Dev-Tonia Aug 24, 2024
7123072
Update test.yml
Olat-nji Aug 24, 2024
741b303
latest
bamo100 Aug 24, 2024
4d18548
Merge pull request #565 from timiajayi/fix/refactorHelpUpdate
Dev-Tonia Aug 24, 2024
bca3cea
Merge pull request #571 from timiajayi/fix/refactorhelpdelete
Dev-Tonia Aug 24, 2024
bb4ce99
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
sparkybug Aug 24, 2024
0c66b54
fix: image url on blog controller test
sparkybug Aug 24, 2024
625f60b
Merge pull request #575 from hngprojects/Olat-nji-patch-5
timiajayi Aug 24, 2024
268b630
Merge pull request #579 from sparkybug/fix/blog-controller-test
timiajayi Aug 24, 2024
9178e0b
Merge pull request #577 from bamo100/storejob
timiajayi Aug 24, 2024
62ca618
deleteplan
bamo100 Aug 24, 2024
d93064a
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
bamo100 Aug 24, 2024
14fac9a
fix: added product search to use product name
tulbadex Aug 24, 2024
ddafeda
fix: PRODUCT delete endpoint
amowogbaje Aug 24, 2024
b5f7251
Merge pull request #583 from tulbadex/fix/search-product-by-names
timiajayi Aug 24, 2024
f79e351
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
amowogbaje Aug 24, 2024
24465c4
fix: added comment to blog details
Cytochrome123 Aug 24, 2024
a9abcae
Merge pull request #582 from bamo100/deleteplan
timiajayi Aug 24, 2024
4384119
Merge pull request #585 from Goldengide/fix/product-delete-endpoint
timiajayi Aug 24, 2024
1f59b67
feat: added update of subscription plan
tulbadex Aug 24, 2024
ab622f2
Merge pull request #591 from Cytochrome123/fix/show-blog
timiajayi Aug 24, 2024
eef9949
feat: added update of subscription plan
tulbadex Aug 24, 2024
ee8d754
feat: added update of subscription plan
tulbadex Aug 24, 2024
45d6ec4
fix: included comment with blogs data on retrieval
Cytochrome123 Aug 24, 2024
bf1ec3c
fix: fix remove user from organization endpoint
tulbadex Aug 25, 2024
d6f2a45
Merge pull request #594 from tulbadex/feat/update-billing-plan
timiajayi Aug 25, 2024
7dbcff8
Merge pull request #597 from tulbadex/fix/remove-user-from-org
timiajayi Aug 25, 2024
abfb116
Merge pull request #595 from Cytochrome123/fix/get-blogs-with-comment
timiajayi Aug 25, 2024
27cc0af
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
RaphAlemoh Aug 25, 2024
578c2da
Merge remote-tracking branch 'origin/staging' into dev
Olat-nji Aug 25, 2024
3762dad
Merge pull request #605 from hngprojects/fix/ApiStatusMergeConlict
tulbadex Aug 25, 2024
e18da50
Merge branch 'dev' of https://github.com/hngprojects/hng_boilerplate_…
RaphAlemoh Aug 25, 2024
19027f4
fix: return correct article id after creation
RaphAlemoh Aug 25, 2024
e290a74
fix: modify get all articles response same as c# docs get all articles
RaphAlemoh Aug 25, 2024
36dfd47
Merge pull request #601 from RaphAlemoh/fix/return-correct-response-f…
tulbadex Aug 25, 2024
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
22 changes: 10 additions & 12 deletions .github/workflows/postman-api-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Scheduled Postman API Tests
name: Scheduled API Tests

on:
schedule:
Expand All @@ -23,17 +23,15 @@ jobs:
- name: Run Postman Collection
run: newman run postman-api-tests.json -r cli,json --reporter-json-export result.json
continue-on-error: true



- name: Transfer test results via SCP
uses: appleboy/[email protected]
- name: Set up PHP
uses: nanasess/setup-php@v4
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
password: ${{ secrets.SSH_PASSWORD }}
source: "result.json"
target: "/var/www/boilerplate-be"
php-version: '8.2'

- name: Clean up
run: rm -f result.json
- name: Send parsed result to Hosted Application
run: |
export APP_URL=${{ secrets.APP_URL }}
php send-postman-api-tests-results.php


6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Code Quality

on:
push:
branches:
- dev
pull_request_target:

jobs:
lint:
Expand Down Expand Up @@ -31,6 +29,8 @@ jobs:

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up PHP
uses: nanasess/setup-php@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ docker-compose.yml
/public/uploads
ResponseHTTP_OK,
can
result.json
21 changes: 17 additions & 4 deletions app/Console/Commands/ApiStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use DateTime;
use DateTimeZone;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;

class StoreApiStatus extends Command
Expand Down Expand Up @@ -64,13 +63,13 @@ public function handle()
$data = [
'api_group' => $item['name'],
'method' => $item['request']['method'],
'status' => $status,
'status' => $this->determineStatus($execution),
'response_time' => $response_time,
'last_checked' => $last_checked,
'details' => $this->getDetails($execution)
];

$url = config('app.url') . '/api/v1/api-status';
$url = "https://staging.api-php.boilerplate.hng.tech/api/v1/api-status";

$response = Http::post($url, $data);

Expand All @@ -93,10 +92,24 @@ private function getDetails($execution)

if ($response_code >= 500 || $response_code === null) {
return 'API not responding (HTTP ' . ($response_code ?? 'Unknown') . ')';
} elseif ($response_time > 400) {
} elseif ($response_time > 600) {
return 'High response time detected';
} else {
return 'All tests passed';
}
}

private function determineStatus($execution)
{
$responseCode = $execution['response']['code'] ?? null;
$responseTime = $execution['response']['responseTime'] ?? null;

if ($responseCode >= 500 || $responseCode === null) {
return 'Down';
} elseif ($responseTime > 600) {
return 'Degraded';
} else {
return 'Operational';
}
}
}
97 changes: 73 additions & 24 deletions app/Http/Controllers/Api/V1/Admin/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,30 @@ public function latest(Request $request)
public function index()
{
try{
$blogPosts = Blog::orderBy('created_at', 'desc')
->select('id', 'title', 'content', 'author', 'created_at', 'category', 'image_url')
->get();
$blogPosts = Blog::with('comments')
->orderBy('created_at', 'desc')
->select('id', 'title', 'content', 'author', 'created_at', 'category', 'image_url')
->get();

$blogPosts = $blogPosts->map(function ($blog) {
return [
'id' => $blog->id,
'title' => $blog->title,
'content' => $blog->content,
'published_date' => $blog->created_at?->toIso8601String(),
'updated_date' => $blog->updated_at?->toIso8601String(),
'author_id' => $blog->author_id,
'category' => $blog->category,
'image_url' => $blog->image_url,
'comments' => $blog->comments->map(function ($comment) {
return [
'id' => $comment->id,
'content' => $comment->content,
'created_at' => $comment->created_at?->toIso8601String(),
];
}),
];
});

return response()->json([
'data' => $blogPosts,
Expand All @@ -93,17 +114,17 @@ public function create()
*/
public function store(Request $request)
{
$author = User::where('id', Auth::id())->first();
if(!$author){
return response()->json(['error' => 'User Not found.'], 404);
$author = User::find(Auth::id());

if (!$author) {
return response()->json(['error' => 'User not found.'], 404);
}

Log::error('Error creating blog post: ' . Auth::id());
$validator = Validator::make($request->all(), [
'title' => ['required', 'string', 'max:255'],
'content' => ['required', 'string'],
'image_url' => ['required', 'mimes:jpeg,png,jpg,gif,svg'],
'category' => ['required', 'string', 'max:255'],
'title' => 'required|string|max:255',
'content' => 'required|string',
'category' => 'required|string|max:255',
'image_url' => 'required|mimes:jpeg,png,jpg,gif,svg',
]);

if ($validator->fails()) {
Expand All @@ -112,27 +133,47 @@ public function store(Request $request)
'status_code' => 422,
], 422);
}

try {
DB::beginTransaction();
$saved = Storage::disk('public')->put('images', $request->file('image_url'));

$savedPath = Storage::disk('public')->put('images', $request->file('image_url'));
$imageUrl = 'storage/' . $savedPath;

$blog = Blog::create([
'title' => $request->get('title'),
'content' => (string)$request->get('content'),
'author' => $author->name ? $author->name : "",
'image_url' => 'storage/'.$saved,
'content' => $request->get('content'),
'author' => $author->name ?? '',
'image_url' => $imageUrl,
'category' => $request->get('category'),
'author_id' => $author->id
'author_id' => $author->id,
]);

DB::commit();

return response()->json([
'data' => $blog,
'message' => 'Blog post created successfully.',
'status_code' => Response::HTTP_CREATED,
'id' => $blog->id,
'title' => $blog->title,
'image_url' => $blog->image_url,
'content' => $blog->content,
'published_date' => $blog->created_at->toIso8601String(),
'updated_date' => $blog->updated_at->toIso8601String(),
'author_id' => $blog->author_id,
'category' => $blog->category,
'comments' => $blog->comments->map(function ($comment) {
return [
'id' => $comment->id,
'content' => $comment->content,
'created_at' => $comment->created_at->toIso8601String(),
];
}),
], Response::HTTP_CREATED);


} catch (\Exception $exception) {
Log::error('Error creating blog post: ' . $exception->getMessage());
DB::rollBack();

return response()->json(['error' => 'Internal server error.'], 500);
}
}
Expand All @@ -143,11 +184,12 @@ public function store(Request $request)
public function show(Request $request, string $id)
{
try {
$blog = Blog::find($id);
$blog = Blog::with('comments')->find($id);

if(!$blog){
return response()->json([
'error' => 'Blog not found.',
'message' => 'Blog not found.',
'status_code' => Response::HTTP_NOT_FOUND,
], 404);
}
Expand All @@ -158,14 +200,21 @@ public function show(Request $request, string $id)
'category' => $blog->category,
'content' => $blog->content,
'image_url' => $blog->image_url,
'created_at' => $blog->created_at,
'published_date' => $blog->created_at?->toIso8601String(),
'updated_date' => $blog->updated_at?->toIso8601String(),
'author_id' => $blog->author_id,
'comments' => $blog->comments->map(function ($comment) {
return [
'id' => $comment->id,
'content' => $comment->content,
'created_at' => $comment->created_at?->toIso8601String(),
];
}),
],
'message' => 'Blog post fetched sucessfully.',
'message' => 'Blog post details fetched sucessfully.',
'status_code' => Response::HTTP_OK,
], Response::HTTP_OK);
} catch (Exception $exception) {
// Log::error('Error creating blog post: ' . $exception->getMessage());
DB::rollBack();
return response()->json(['error' => 'Internal server error.'], 500);
}
}
Expand Down
18 changes: 14 additions & 4 deletions app/Http/Controllers/Api/V1/Admin/EmailTemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function index(Request $request)
'limit' => $templates->perPage(),
], 200);
}

public function update(Request $request, $id)
{
// Validate the request data
Expand Down Expand Up @@ -97,7 +98,6 @@ public function update(Request $request, $id)

public function store(Request $request)
{

// Validate request data
$validatedData = $request->validate([
'title' => 'required|string|max:255|unique:email_templates,title',
Expand All @@ -108,13 +108,23 @@ public function store(Request $request)
// Create email template
$emailTemplate = EmailTemplate::create($validatedData);

// Format the response to match the API schema in the screenshot
return response()->json([
'status_code' => 200,
'data' => [
'id' => $emailTemplate->id,
'name' => $emailTemplate->title,
'subject' => '', // Add subject if applicable
'template_body' => $emailTemplate->template,
'placeholders' => [
// Add placeholders if available
],
],
'message' => 'Email template created successfully',
'data' => $emailTemplate
], 200);
'status_code' => 201
], 201);
}


public function destroy($id)
{
// Find the email template by ID
Expand Down
39 changes: 5 additions & 34 deletions app/Http/Controllers/Api/V1/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,19 @@ class CategoryController extends Controller
public function index(Request $request)
{
try {
// Optional query parameters
$limit = $request->query('limit', 100);
$offset = $request->query('offset', 0);
$parent_id = $request->query('parent_id', null);

// Validate query parameters
$request->validate([
'limit' => 'integer|min:1',
'offset' => 'integer|min:0',
'parent_id' => 'integer|nullable',
]);

$categories = Category::when($parent_id, function ($query) use ($parent_id) {
return $query->where('parent_id', $parent_id);
})
->limit($limit)
->offset($offset)
->get(['id', 'name', 'description', 'slug', 'parent_id']);

\Log::info($categories);
$categories = Category::all();

return response()->json([
'status_code' => 200,
'categories' => $categories,
'message' => 'Categories returned successfully',
'data' => $categories,
]);
} catch (\Illuminate\Validation\ValidationException $e) {
return response()->json([
'status_code' => 400,
'error' => [
'code' => 'INVALID_QUERY_PARAMETER',
'message' => 'The provided query parameter is invalid.',
'details' => [
'invalid_parameter' => $e->validator->errors()->keys()[0],
'reason' => $e->validator->errors()->first(),
],
],
], 400);
} catch (\Exception $e) {

}catch (\Exception $e) {
return response()->json([
'status_code' => 500,
'error' => [
'code' => 'INTERNAL_SERVER_ERROR',
'message' => 'An unexpected error occurred while processing your request.',
'details' => [
'support_email' => '[email protected]',
Expand Down
Loading
Loading