Skip to content

Commit 4a710a1

Browse files
authored
Merge pull request #4 from anqorithm/feat/swagger-and-unit-tests-impl
feat: add unit tests & swagger docs
2 parents 98f0f48 + 965668b commit 4a710a1

File tree

19 files changed

+3149
-65
lines changed

19 files changed

+3149
-65
lines changed

README.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -395,46 +395,66 @@ Data source: [Almaqased Cleansing Calculator](https://almaqased.net/cleansing-ca
395395
</div>
396396

397397
$$
398-
\text{مبلغ التطهير} = \frac{\text{عدد الأسهم} \times \text{نسبة التطهير} \times \text{عدد أيام التملك}}{365.0}
398+
\text{مبلغ التطهير} = \text{عدد الأسهم} \times \text{نسبة التطهير} \times \frac{\text{عدد أيام التملك في السنة}}{\text{إجمالي أيام السنة}}
399399
$$
400400

401401
<div dir="rtl">
402402

403403
حيث:
404404
- `عدد الأسهم`: إجمالي عدد الأسهم المملوكة
405405
- `نسبة التطهير`: نسبة التطهير السنوية (النسبة المئوية)
406-
- `عدد أيام التملك`: عدد الأيام التي تم فيها امتلاك الأسهم
407-
- `365.0`: عدد أيام السنة (ثابت)
406+
- `عدد أيام التملك في السنة`: عدد الأيام التي تم فيها امتلاك الأسهم في كل سنة على حدة
407+
- `إجمالي أيام السنة`: عدد أيام السنة (365 للسنة العادية، 366 للسنة الكبيسة)
408408

409-
### مثال
410-
لـ 100 سهم بنسبة تطهير 2.5% تم امتلاكها لمدة 180 يوم:
409+
**ملاحظة مهمة**: يأخذ النظام بعين الاعتبار السنوات الكبيسة والفترات متعددة السنوات، حيث يتم حساب كل سنة على حدة.
410+
411+
### أمثلة
412+
لـ 100 سهم بنسبة تطهير 2.5% تم امتلاكها لمدة 180 يوم في السنة العادية:
413+
414+
</div>
415+
416+
$$
417+
\text{مبلغ التطهير} = 100 \times 0.025 \times \frac{180}{365} = 1.233
418+
$$
419+
420+
<div dir="rtl">
421+
422+
لنفس المثال في السنة الكبيسة (366 يوم):
411423

412424
</div>
413425

414426
$$
415-
\text{مبلغ التطهير} = \frac{100 \times 0.025 \times 180}{365.0} = 1.23
427+
\text{مبلغ التطهير} = 100 \times 0.025 \times \frac{180}{366} = 1.230
416428
$$
417429

418430

419431
## Stock Purification Amount Calculation
420432

421-
The purification amount for stocks is calculated using the following formula:
433+
The purification amount for stocks is calculated using the following accurate formula that handles leap years and multi-year periods:
422434

423435
$$
424-
\text{purificationAmount} = \frac{\text{numberOfStocks} \times \text{purificationRate} \times \text{daysHeld}}{365.0}
436+
\text{purificationAmount} = \text{numberOfStocks} \times \text{purificationRate} \times \frac{\text{daysHeldInYear}}{\text{totalDaysInYear}}
425437
$$
426438

427439
Where:
428440
- `numberOfStocks`: Total number of stocks held
429441
- `purificationRate`: Annual purification rate (percentage)
430-
- `daysHeld`: Number of days the stocks were held
431-
- `365.0`: Days in a year (constant)
442+
- `daysHeldInYear`: Number of days the stocks were held in each year separately
443+
- `totalDaysInYear`: Total days in the year (365 for regular years, 366 for leap years)
444+
445+
**Important Note**: The system accounts for leap years and multi-year periods by calculating each year separately.
446+
447+
### Examples
448+
For 100 stocks with 2.5% purification rate held for 180 days in a regular year:
449+
450+
$$
451+
\text{purificationAmount} = 100 \times 0.025 \times \frac{180}{365} = 1.233
452+
$$
432453

433-
### Example
434-
For 100 stocks with 2.5% purification rate held for 180 days:
454+
For the same example in a leap year (366 days):
435455

436456
$$
437-
\text{purificationAmount} = \frac{100 \times 0.025 \times 180}{365.0} = 1.23
457+
\text{purificationAmount} = 100 \times 0.025 \times \frac{180}{366} = 1.230
438458
$$
439459

440460

cmd/api/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ import (
1212
"github.com/anqorithm/naqa-api/internal/seeders"
1313
"github.com/gofiber/fiber/v2"
1414
"github.com/joho/godotenv"
15+
fiberSwagger "github.com/swaggo/fiber-swagger"
16+
_ "github.com/anqorithm/naqa-api/docs"
1517
)
1618

19+
// @title NAQA API
20+
// @version 1.0
21+
// @description A stock analysis and Sharia compliance API
22+
// @contact.name API Support
23+
// @contact.email [email protected]
24+
// @host localhost:3000
25+
// @BasePath /
26+
1727
func main() {
1828
// ###############################################################################
1929
// Environment and Configuration Setup
@@ -63,6 +73,9 @@ func main() {
6373
// ###############################################################################
6474
router := routes.NewRouter(app, db)
6575
router.SetupRoutes()
76+
77+
// Swagger documentation route
78+
app.Get("/docs/*", fiberSwagger.WrapHandler)
6679

6780
port := os.Getenv("PORT")
6881
if port == "" {

0 commit comments

Comments
 (0)