models

package
v0.0.0-...-556965f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2025 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package models is made to store the structs of different data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APICollection

type APICollection struct {
	Authenticated   LinksCollection `json:"authenticated" swaggertype:"object"`
	UnAuthenticated LinksCollection `json:"unAuthenticated" swaggertype:"object"`
}

APICollection is the object that lists which apis require authentication and which do not

type APICollectionResponse

type APICollectionResponse struct {
	Status int           `json:"status" example:"200"`
	Data   APICollection `json:"data"`
}

APICollectionResponse represents the response format for api collection data.

type Api

type Api struct {
	Href          string `json:"href" example:"/api/v1/licenses"`
	RequestMethod string `json:"request_method" enums:"POST,PATCH,DELETE,PUT,GET" example:"POST"`
}

Api contains the information about an endpoint

type Audit

type Audit struct {
	Id         int64       `json:"id" gorm:"primary_key" example:"456"`
	UserId     int64       `json:"user_id" example:"123"`
	User       User        `gorm:"foreignKey:UserId;references:Id" json:"user"`
	Timestamp  time.Time   `json:"timestamp" example:"2023-12-01T18:10:25.00+05:30"`
	Type       string      `json:"type" enums:"obligation,license" example:"license"`
	TypeId     int64       `json:"type_id" example:"34"`
	Entity     interface{} `json:"entity" gorm:"-" swaggertype:"object"`
	ChangeLogs []ChangeLog `json:"-"`
}

Audit struct represents an audit entity with certain attributes and properties It has user id as a foreign key

type AuditResponse

type AuditResponse struct {
	Status int             `json:"status" example:"200"`
	Data   []Audit         `json:"data"`
	Meta   *PaginationMeta `json:"paginationmeta"`
}

AuditResponse represents the response format for audit data.

type ChangeLog

type ChangeLog struct {
	Id           int64   `json:"id" gorm:"primary_key" example:"789"`
	Field        string  `json:"field" example:"text"`
	UpdatedValue *string `json:"updated_value" example:"New license text"`
	OldValue     *string `json:"old_value" example:"Old license text"`
	AuditId      int64   `json:"audit_id" example:"456"`
	Audit        Audit   `gorm:"foreignKey:AuditId;references:Id" json:"-"`
}

ChangeLog struct represents a change entity with certain attributes and properties

type ChangeLogResponse

type ChangeLogResponse struct {
	Status int            `json:"status" example:"200"`
	Data   []ChangeLog    `json:"data"`
	Meta   PaginationMeta `json:"paginationmeta"`
}

ChangeLogResponse represents the design of API response of change log

type ContextKey

type ContextKey string

type ImportLicensesResponse

type ImportLicensesResponse struct {
	Status int           `json:"status" example:"200"`
	Data   []interface{} `json:"data"` // can be of type models.LicenseError or models.LicenseImportStatus
}

ImportObligationsResponse is the response structure for import obligation response

type ImportObligationsResponse

type ImportObligationsResponse struct {
	Status int           `json:"status" example:"200"`
	Data   []interface{} `json:"data"` // can be of type models.LicenseError or models.ObligationImportStatus
}

ImportObligationsResponse is the response structure for import obligation response

type LicenseDB

type LicenseDB struct {
	Id              int64                                        `json:"-" gorm:"primary_key;column:rf_id" example:"123"`
	Shortname       *string                                      `json:"shortname" gorm:"unique;not null;column:rf_shortname" validate:"required" example:"MIT"`
	Fullname        *string                                      `json:"fullname" gorm:"column:rf_fullname;not null" validate:"required" example:"MIT License"`
	Text            *string                                      `json:"text" gorm:"column:rf_text;not null" validate:"required" example:"MIT License Text here"`
	Url             *string                                      `json:"url" gorm:"column:rf_url;default:'';not null" example:"https://opensource.org/licenses/MIT"`
	AddDate         time.Time                                    `json:"add_date" gorm:"default:CURRENT_TIMESTAMP;column:rf_add_date" example:"2023-12-01T18:10:25.00+05:30"`
	Copyleft        *bool                                        `json:"copyleft" gorm:"column:rf_copyleft;not null;default:false"`
	FSFfree         *bool                                        `json:"FSFfree" gorm:"column:rf_FSFfree;not null;default:false"`
	OSIapproved     *bool                                        `json:"OSIapproved" gorm:"column:rf_OSIapproved;not null;default:false"`
	GPLv2compatible *bool                                        `json:"GPLv2compatible" gorm:"column:rf_GPLv2compatible;not null;default:false"`
	GPLv3compatible *bool                                        `json:"GPLv3compatible" gorm:"column:rf_GPLv3compatible;not null;default:false"`
	Notes           *string                                      `json:"notes" gorm:"column:rf_notes;not null;default:''" example:"This license has been superseded."`
	Fedora          *string                                      `json:"Fedora" gorm:"column:rf_Fedora;not null;default:''"`
	TextUpdatable   *bool                                        `json:"text_updatable" gorm:"column:rf_text_updatable;not null;default:false"`
	DetectorType    *int64                                       `json:"detector_type" gorm:"column:rf_detector_type;not null;default:1" validate:"omitempty,min=0,max=2" example:"1"`
	Active          *bool                                        `json:"active" gorm:"column:rf_active;not null;default:true"`
	Source          *string                                      `json:"source" gorm:"column:rf_source;not null;default:''"`
	SpdxId          *string                                      `json:"spdx_id" gorm:"column:rf_spdx_id;not null" validate:"required" example:"MIT"`
	Risk            *int64                                       `json:"risk" gorm:"column:rf_risk;not null;default:0" validate:"omitempty,min=0,max=5"`
	Flag            *int64                                       `json:"flag" gorm:"default:1;column:rf_flag;not null;default:0" validate:"omitempty,min=0,max=2" example:"1"`
	Marydone        *bool                                        `json:"marydone" gorm:"column:marydone;not null;default:false"`
	ExternalRef     datatypes.JSONType[LicenseDBSchemaExtension] `json:"external_ref"`
	Obligations     []*Obligation                                `gorm:"many2many:obligation_licenses;" json:"obligations"`
}

The LicenseDB struct represents a license entity with various attributes and properties associated with it. It provides structured storage for license-related information.

func (*LicenseDB) BeforeSave

func (l *LicenseDB) BeforeSave(tx *gorm.DB) (err error)

type LicenseError

type LicenseError struct {
	Status    int    `json:"status" example:"400"`
	Message   string `json:"message" example:"invalid request body"`
	Error     string `json:"error" example:"invalid request body"`
	Path      string `json:"path" example:"/api/v1/licenses"`
	Timestamp string `json:"timestamp" example:"2023-12-01T10:00:51+05:30"`
}

The LicenseError struct represents an error response related to license operations. It provides information about the encountered error, including details such as status, error message, error type, path, and timestamp.

type LicenseId

type LicenseId struct {
	Id        int64  `json:"id" example:"31"`
	Shortname string `json:"shortname" example:"MIT"`
}

LicenseId is the id of successfully imported license

type LicenseImportStatus

type LicenseImportStatus struct {
	Status int       `json:"status" example:"200"`
	Data   LicenseId `json:"data"`
}

LicenseImportStatus is the status of license records successfully inserted in the database during import

type LicenseJson

type LicenseJson struct {
	Shortname       string `json:"rf_shortname"`
	Fullname        string `json:"rf_fullname"`
	Text            string `json:"rf_text"`
	Url             string `json:"rf_url"`
	AddDate         string `json:"rf_add_date"`
	Copyleft        string `json:"rf_copyleft"`
	FSFfree         string `json:"rf_FSFfree"`
	OSIapproved     string `json:"rf_OSIapproved"`
	GPLv2compatible string `json:"rf_GPLv2compatible"`
	GPLv3compatible string `json:"rf_GPLv3compatible"`
	Notes           string `json:"rf_notes"`
	Fedora          string `json:"rf_Fedora"`
	TextUpdatable   string `json:"rf_text_updatable"`
	DetectorType    int64  `json:"rf_detector_type"`
	Active          string `json:"rf_active"`
	Source          string `json:"rf_source"`
	SpdxCompatible  string `json:"rf_spdx_compatible"`
	Risk            string `json:"rf_risk"`
	Flag            string `json:"rf_flag"`
	Marydone        string `json:"marydone"`
}

type LicenseMapShortnamesElement

type LicenseMapShortnamesElement struct {
	Shortname string `json:"shortname" example:"GPL-2.0-only"`
	Add       bool   `json:"add" example:"true"`
}

LicenseMapShortnamesElement Element to hold license shortname and action

type LicenseMapShortnamesInput

type LicenseMapShortnamesInput struct {
	MapInput []LicenseMapShortnamesElement `json:"map"`
}

LicenseMapShortnamesInput List of elements to be read as input by API

type LicensePreviewResponse

type LicensePreviewResponse struct {
	Status     int      `json:"status" example:"200"`
	Shortnames []string `json:"shortnames" example:"GPL-2.0-only,GPL-2.0-or-later"`
}

LicensePreviewResponse gets us the list of all license shortnames

type LicenseResponse

type LicenseResponse struct {
	Status int             `json:"status" example:"200"`
	Data   []LicenseDB     `json:"data"`
	Meta   *PaginationMeta `json:"paginationmeta"`
}

LicenseResponse struct is representation of design API response of license. The LicenseResponse struct represents the response data structure for retrieving license information. It is used to encapsulate license-related data in an organized manner.

type LicenseShortnamesInput

type LicenseShortnamesInput struct {
	Shortnames []string `json:"shortnames" example:"GPL-2.0-only,GPL-2.0-or-later"`
}

LicenseShortnamesInput represents the input format for adding/removing licenses from obligation map.

type LicenseUpdateJSONSchema

type LicenseUpdateJSONSchema struct {
	Id              int64                                        `json:"-" example:"123"`
	Shortname       *string                                      `json:"-" example:"MIT"`
	Fullname        *string                                      `json:"fullname" example:"MIT License"`
	Text            *string                                      `json:"text" example:"MIT License Text here"`
	Url             *string                                      `json:"url" example:"https://opensource.org/licenses/MIT"`
	AddDate         time.Time                                    `json:"-" example:"2023-12-01T18:10:25.00+05:30"`
	Copyleft        *bool                                        `json:"copyleft" example:"false"`
	FSFfree         *bool                                        `json:"FSFfree" example:"false"`
	OSIapproved     *bool                                        `json:"OSIapproved" example:"false"`
	GPLv2compatible *bool                                        `json:"GPLv2compatible" example:"false"`
	GPLv3compatible *bool                                        `json:"GPLv3compatible" example:"false"`
	Notes           *string                                      `json:"notes" example:"This license has been superseded."`
	Fedora          *string                                      `json:"Fedora" example:"Fedora"`
	TextUpdatable   *bool                                        `json:"text_updatable" example:"false"`
	DetectorType    *int64                                       `json:"detector_type" validate:"omitempty,min=0,max=2" example:"1"`
	Active          *bool                                        `json:"active" example:"true"`
	Source          *string                                      `json:"source" example:"Source"`
	SpdxId          *string                                      `json:"spdx_id" example:"MIT"`
	Risk            *int64                                       `json:"risk" validate:"omitempty,min=0,max=5" example:"1"`
	Flag            *int64                                       `json:"flag" validate:"omitempty,min=0,max=2" example:"1"`
	Marydone        *bool                                        `json:"marydone" example:"false"`
	ExternalRef     datatypes.JSONType[LicenseDBSchemaExtension] `json:"external_ref"`
	Obligations     []*Obligation                                `json:"obligations"`
}

LicenseUpdateJSONSchema struct represents the input format for updating an existing license.

type LinksCollection

type LinksCollection struct {
	Links map[string]Api `json:"_links" swaggertype:"object,string" example:"licenses:{}"`
}

LinksCollection is a collection of links

type Obligation

type Obligation struct {
	Id                         int64                     `gorm:"primary_key"`
	Topic                      *string                   `gorm:"unique;not null"`
	Text                       *string                   `gorm:"not null"`
	Modifications              *bool                     `gorm:"not null;default:false"`
	Comment                    *string                   `gorm:"not null;default:''"`
	Active                     *bool                     `gorm:"not null;default:true"`
	TextUpdatable              *bool                     `gorm:"not null;default:false"`
	Md5                        string                    `gorm:"unique;not null"`
	ObligationClassificationId int64                     `gorm:"not null"`
	ObligationTypeId           int64                     `gorm:"not null"`
	Licenses                   []*LicenseDB              `gorm:"many2many:obligation_licenses;"`
	Type                       *ObligationType           `gorm:"foreignKey:ObligationTypeId"`
	Classification             *ObligationClassification `gorm:"foreignKey:ObligationClassificationId"`
}

Obligation represents an obligation record in the database.

func (*Obligation) BeforeCreate

func (o *Obligation) BeforeCreate(tx *gorm.DB) (err error)

func (*Obligation) BeforeUpdate

func (o *Obligation) BeforeUpdate(tx *gorm.DB) (err error)

func (*Obligation) MarshalJSON

func (o *Obligation) MarshalJSON() ([]byte, error)

Custom json marshaller and unmarshaller for Obligation

func (*Obligation) UnmarshalJSON

func (o *Obligation) UnmarshalJSON(data []byte) error

Custom JSON unmarshaller for Obligation

type ObligationClassification

type ObligationClassification struct {
	Id             int64  `gorm:"primary_key" json:"-"`
	Classification string `gorm:"unique;not null" validate:"required,uppercase" example:"GREEN" json:"classification"`
	Color          string `gorm:"unique; not null" validate:"required,hexcolor" example:"#00FF00" json:"color"`
	Active         *bool  `gorm:"not null;default:true" json:"-"`
}

ObligationClassification represents one of the possible of obligation classification values

type ObligationClassificationResponse

type ObligationClassificationResponse struct {
	Status int                        `json:"status" example:"200"`
	Data   []ObligationClassification `json:"data"`
	Meta   *PaginationMeta            `json:"paginationmeta"`
}

ObligationClassificationResponse represents the response format for obligation classification data.

type ObligationDTO

type ObligationDTO struct {
	Topic          *string  `json:"topic" example:"copyleft" validate:"required"`
	Type           *string  `json:"type" example:"RISK" validate:"required"`
	Text           *string  `json:"text" example:"Source code be made available when distributing the software." validate:"required"`
	Classification *string  `json:"classification" example:"GREEN" validate:"required"`
	Modifications  *bool    `json:"modifications" example:"true"`
	Comment        *string  `json:"comment"`
	Active         *bool    `json:"active"`
	TextUpdatable  *bool    `json:"text_updatable" example:"true"`
	Shortnames     []string `json:"shortnames" validate:"required" example:"GPL-2.0-only,GPL-2.0-or-later"`
}

ObligationDTO represents an obligation json object.

type ObligationId

type ObligationId struct {
	Id    int64  `json:"id" example:"31"`
	Topic string `json:"topic" example:"copyleft"`
}

ObligationId is the id of successfully imported obligation

type ObligationImportRequest

type ObligationImportRequest struct {
	ObligationFile string `form:"file"`
}

ObligationImportRequest represents the request body structure for import obligation

type ObligationImportStatus

type ObligationImportStatus struct {
	Status  int          `json:"status" example:"200"`
	Data    ObligationId `json:"data"`
	Message string       `json:"message"`
}

ObligationImportStatus is the status of obligation records successfully inserted in the database during import

type ObligationMapResponse

type ObligationMapResponse struct {
	Status int                 `json:"status" example:"200"`
	Data   []ObligationMapUser `json:"data"`
	Meta   PaginationMeta      `json:"paginationmeta"`
}

ObligationMapResponse response format for obligation map data.

type ObligationMapUser

type ObligationMapUser struct {
	Topic      string   `json:"topic" example:"copyleft"`
	Type       string   `json:"type" example:"obligation" enums:"obligation,restriction,risk,right"`
	Shortnames []string `json:"shortnames" example:"GPL-2.0-only,GPL-2.0-or-later"`
}

ObligationMapUser Structure with obligation topic and license shortname list, a simple representation for user.

type ObligationPreview

type ObligationPreview struct {
	Topic string `json:"topic" example:"Provide Copyright Notices"`
	Type  string `json:"type" enums:"obligation,restriction,risk,right"`
}

ObligationPreview is just the Type and Topic of Obligation

type ObligationPreviewResponse

type ObligationPreviewResponse struct {
	Status int                 `json:"status" example:"200"`
	Data   []ObligationPreview `json:"data"`
}

ObligationResponse represents the response format for obligation data.

type ObligationResponse

type ObligationResponse struct {
	Status int             `json:"status" example:"200"`
	Data   []Obligation    `json:"data"`
	Meta   *PaginationMeta `json:"paginationmeta"`
}

ObligationResponse represents the response format for obligation data.

type ObligationType

type ObligationType struct {
	Id     int64  `gorm:"primary_key" json:"-"`
	Type   string `gorm:"unique;not null" validate:"required,uppercase" example:"PERMISSION" json:"type"`
	Active *bool  `gorm:"not null;default:true" json:"-"`
}

ObligationType represents one of the possible of obligation type values

type ObligationTypeResponse

type ObligationTypeResponse struct {
	Status int              `json:"status" example:"200"`
	Data   []ObligationType `json:"data"`
	Meta   *PaginationMeta  `json:"paginationmeta"`
}

ObligationTypeResponse represents the response format for obligation type data.

type ObligationUpdateDTO

type ObligationUpdateDTO struct {
	Topic          *string `json:"-" example:"copyleft"`
	Type           *string `json:"type" example:"RISK"`
	Text           *string `json:"text" example:"Source code be made available when distributing the software."`
	Classification *string `json:"classification" example:"GREEN"`
	Modifications  *bool   `json:"modifications" example:"true"`
	Comment        *string `json:"comment"`
	Active         *bool   `json:"active"`
	TextUpdatable  *bool   `json:"text_updatable" example:"true"`
}

ObligationUpdateDTO represents an obligation json object.

func (*ObligationUpdateDTO) Converter

func (obDto *ObligationUpdateDTO) Converter() *Obligation

type PaginationInput

type PaginationInput struct {
	Page  int64 `json:"page" example:"10"`
	Limit int64 `json:"limit" example:"10"`
}

The PaginationInput struct represents the input required for pagination.

func (PaginationInput) GetLimit

func (p PaginationInput) GetLimit() int64

GetLimit returns the limit value for gorm.

func (PaginationInput) GetOffset

func (p PaginationInput) GetOffset() int64

GetOffset returns the offset value for gorm.

type PaginationMeta

type PaginationMeta struct {
	ResourceCount int    `json:"resource_count" example:"200"`
	TotalPages    int64  `json:"total_pages,omitempty" example:"20"`
	Page          int64  `json:"page,omitempty" example:"10"`
	Limit         int64  `json:"limit,omitempty" example:"10"`
	Next          string `json:"next,omitempty" example:"/api/v1/licenses?limit=10&page=11"`
	Previous      string `json:"previous,omitempty" example:"/api/v1/licenses?limit=10&page=9"`
}

The PaginationMeta struct represents additional metadata associated with a license retrieval operation. It contains information that provides context and supplementary details about the retrieved license data.

type PaginationParse

type PaginationParse interface {
	GetOffset() int
	GetLimit() int
}

PaginationParse interface processes the pagination input.

type ProfileUpdate

type ProfileUpdate struct {
	Id           int64   `json:"-"`
	Username     *string `json:"-"`
	DisplayName  *string `json:"display_name" example:"fossy"`
	UserEmail    *string `json:"user_email" validate:"omitempty,email"`
	Userlevel    *string `json:"-"`
	Userpassword *string `json:"user_password"`
	Active       *bool   `json:"-"`
}

type SearchLicense

type SearchLicense struct {
	Field      string `json:"field" binding:"required" example:"text"`
	SearchTerm string `json:"search_term" binding:"required" example:"MIT License"`
	Search     string `json:"search" enums:"fuzzy,full_text_search"`
}

SearchLicense struct represents the input needed to search in a license.

type SwaggerDocAPISecurityScheme

type SwaggerDocAPISecurityScheme struct {
	BasePath string `json:"basePath" example:"/api/v1"`
	Paths    map[string]map[string]struct {
		Security    []map[string]interface{} `json:"security" swaggertype:"array,object"`
		OperationId string                   `json:"operationId" example:"GetLicense"`
	} `json:"paths"`
}

SwaggerDocAPISecurityScheme is the json schema describing info about various apis

type SwaggerObligationResponse

type SwaggerObligationResponse struct {
	Status int             `json:"status" example:"200"`
	Data   []ObligationDTO `json:"data"`
	Meta   *PaginationMeta `json:"paginationmeta"`
}

SwaggerObligationResponse represents the response format for obligation data.

type UpdateExternalRefsJSONPayload

type UpdateExternalRefsJSONPayload struct {
	ExternalRef map[string]interface{} `json:"external_ref"`
}

UpdateExternalRefsJSONPayload struct represents the external ref key value pairs for update

type User

type User struct {
	Id           int64   `json:"id" gorm:"primary_key" example:"123"`
	Username     *string `json:"username" gorm:"unique;not null" example:"fossy"`
	DisplayName  *string `json:"display_name" gorm:"not null" example:"fossy"`
	UserEmail    *string `json:"user_email" gorm:"unique;not null" example:"fossy@org.com"`
	Userlevel    *string `json:"user_level" gorm:"not null" example:"USER"`
	Userpassword *string `json:"-"`
	Active       *bool   `json:"-" gorm:"not null;default:true"`
}

User struct is representation of user information.

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(tx *gorm.DB) (err error)

type UserCreate

type UserCreate struct {
	Id           int64   `json:"-"`
	Username     *string `json:"username" validate:"required" example:"fossy"`
	DisplayName  *string `json:"display_name" validate:"required" example:"fossy"`
	UserEmail    *string `json:"user_email" validate:"required,email" example:"fossy@org.com"`
	Userlevel    *string `json:"user_level" validate:"required,oneof=USER ADMIN" example:"ADMIN"`
	Userpassword *string `json:"user_password" example:"fossy"`
	Active       *bool   `json:"-"`
}

type UserLogin

type UserLogin struct {
	Username     string `json:"username" binding:"required" example:"fossy"`
	Userpassword string `json:"password" binding:"required" example:"fossy"`
}

type UserResponse

type UserResponse struct {
	Status int             `json:"status" example:"200"`
	Data   []User          `json:"data"`
	Meta   *PaginationMeta `json:"paginationmeta"`
}

UserResponse struct is representation of design API response of user.

type UserUpdate

type UserUpdate struct {
	Id           int64   `json:"-"`
	Username     *string `json:"username" example:"fossy"`
	DisplayName  *string `json:"display_name" example:"fossy"`
	UserEmail    *string `json:"user_email" validate:"omitempty,email"`
	Userlevel    *string `json:"user_level" validate:"omitempty,oneof=USER ADMIN" example:"ADMIN"`
	Userpassword *string `json:"user_password"`
	Active       *bool   `json:"active"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL