@@ -53,6 +53,7 @@ func Router() *gin.Engine {
53
53
return r
54
54
}
55
55
56
+ // The HandleInvalidUrl function returns the error when an invalid url is entered
56
57
func HandleInvalidUrl (c * gin.Context ) {
57
58
58
59
er := models.LicenseError {
@@ -64,6 +65,8 @@ func HandleInvalidUrl(c *gin.Context) {
64
65
}
65
66
c .JSON (http .StatusNotFound , er )
66
67
}
68
+
69
+ // The get all License function returns all the license data present in the database
67
70
func GetAllLicense (c * gin.Context ) {
68
71
69
72
var licenses []models.LicenseDB
@@ -91,6 +94,9 @@ func GetAllLicense(c *gin.Context) {
91
94
c .JSON (http .StatusOK , res )
92
95
}
93
96
97
+ // Get license functions return data of the particular license by its shortname.
98
+ // It inputs the shortname as query parameter
99
+ // It returns error ehen no such license exists
94
100
func GetLicense (c * gin.Context ) {
95
101
var license models.LicenseDB
96
102
@@ -124,6 +130,8 @@ func GetLicense(c *gin.Context) {
124
130
c .JSON (http .StatusOK , res )
125
131
}
126
132
133
+ // The Create License function creates license in the database and add the required data
134
+ // It return the license if it already exists in the database
127
135
func CreateLicense (c * gin.Context ) {
128
136
var input models.LicenseInput
129
137
@@ -200,6 +208,9 @@ func CreateLicense(c *gin.Context) {
200
208
c .JSON (http .StatusCreated , res )
201
209
}
202
210
211
+ // The Update license functions updates the particular license with a particular shortname.
212
+ // It also creates the audit and change logs of the updates
213
+ // It returns the updated license
203
214
func UpdateLicense (c * gin.Context ) {
204
215
var update models.LicenseDB
205
216
var license models.LicenseDB
@@ -446,6 +457,8 @@ func UpdateLicense(c *gin.Context) {
446
457
447
458
}
448
459
460
+ // The filter licenses returns the licenses after passing through certain filters.
461
+ // It takes the filters as query parameters and filters accordingly.
449
462
func FilterLicense (c * gin.Context ) {
450
463
SpdxId := c .Query ("spdxid" )
451
464
DetectorType := c .Query ("detector_type" )
@@ -523,6 +536,10 @@ func FilterLicense(c *gin.Context) {
523
536
524
537
}
525
538
539
+ // SearchInLicense searches for license data based on user-provided search criteria.
540
+ // It accepts a JSON request body containing search parameters and responds with JSON
541
+ // containing the matching license data or error messages if the search request is
542
+ // invalid or if the search algorithm is not supported.
526
543
func SearchInLicense (c * gin.Context ) {
527
544
var input models.SearchLicense
528
545
@@ -570,6 +587,8 @@ func SearchInLicense(c *gin.Context) {
570
587
571
588
}
572
589
590
+ // GetAllAudit retrieves a list of all audit records from the database and responds with
591
+ // JSON containing the audit data or an error message if the records are not found.
573
592
func GetAllAudit (c * gin.Context ) {
574
593
var audit []models.Audit
575
594
@@ -595,6 +614,8 @@ func GetAllAudit(c *gin.Context) {
595
614
c .JSON (http .StatusOK , res )
596
615
}
597
616
617
+ // GetAudit retrieves a specific audit record by its ID from the database and responds
618
+ // with JSON containing the audit data or an error message if the record is not found.
598
619
func GetAudit (c * gin.Context ) {
599
620
var chngelog models.Audit
600
621
id := c .Param ("audit_id" )
@@ -620,6 +641,9 @@ func GetAudit(c *gin.Context) {
620
641
c .JSON (http .StatusOK , res )
621
642
}
622
643
644
+ // GetChangeLog retrieves a list of change history records associated with a specific
645
+ // audit by its audit ID from the database and responds with JSON containing the change
646
+ // history data or an error message if no records are found.
623
647
func GetChangeLog (c * gin.Context ) {
624
648
var changelog []models.ChangeLog
625
649
id := c .Param ("audit_id" )
@@ -646,6 +670,9 @@ func GetChangeLog(c *gin.Context) {
646
670
c .JSON (http .StatusOK , res )
647
671
}
648
672
673
+ // GetChangeLogbyId retrieves a specific change history record by its ID for a given audit.
674
+ // It responds with JSON containing the change history data or error messages if the record
675
+ // is not found or if it does not belong to the specified audit.
649
676
func GetChangeLogbyId (c * gin.Context ) {
650
677
var changelog models.ChangeLog
651
678
auditid := c .Param ("audit_id" )
@@ -682,6 +709,10 @@ func GetChangeLogbyId(c *gin.Context) {
682
709
c .JSON (http .StatusOK , res )
683
710
}
684
711
712
+ // CreateObligation creates a new obligation record based on the provided input JSON data.
713
+ // It performs validation, generates an MD5 hash of the obligation text, and associates
714
+ // the obligation with relevant licenses. The function responds with JSON containing the
715
+ // newly created obligation data or error messages in case of validation or database errors.
685
716
func CreateObligation (c * gin.Context ) {
686
717
var input models.ObligationInput
687
718
@@ -764,6 +795,8 @@ func CreateObligation(c *gin.Context) {
764
795
c .JSON (http .StatusCreated , res )
765
796
}
766
797
798
+ // GetAllObligation retrieves a list of all active obligation records from the database and
799
+ // responds with JSON containing the obligation data or an error message if no records are found.
767
800
func GetAllObligation (c * gin.Context ) {
768
801
var obligations []models.Obligation
769
802
query := db .DB .Model (& obligations )
@@ -791,6 +824,10 @@ func GetAllObligation(c *gin.Context) {
791
824
c .JSON (http .StatusOK , res )
792
825
}
793
826
827
+ // UpdateObligation updates an existing active obligation record based on the provided input JSON data.
828
+ // It performs validation, updates the specified fields, and records changes in the audit log.
829
+ // The function responds with JSON containing the updated obligation data or error messages in case
830
+ // of validation or database errors.
794
831
func UpdateObligation (c * gin.Context ) {
795
832
var update models.UpdateObligation
796
833
var oldobligation models.Obligation
@@ -948,6 +985,8 @@ func UpdateObligation(c *gin.Context) {
948
985
c .JSON (http .StatusOK , res )
949
986
}
950
987
988
+ // DeleteObligation marks an existing obligation record as inactive based on the provided topic parameter.
989
+ // It responds with an error message if the obligation is not found or if the deactivation operation fails.
951
990
func DeleteObligation (c * gin.Context ) {
952
991
var obligation models.Obligation
953
992
tp := c .Param ("topic" )
@@ -965,6 +1004,9 @@ func DeleteObligation(c *gin.Context) {
965
1004
obligation .Active = false
966
1005
}
967
1006
1007
+ // GetObligation retrieves an active obligation record based on the provided topic parameter.
1008
+ // It responds with JSON containing the obligation data or an error message if the obligation
1009
+ // is not found or if there is an error during retrieval.
968
1010
func GetObligation (c * gin.Context ) {
969
1011
var obligation models.Obligation
970
1012
query := db .DB .Model (& obligation )
0 commit comments