Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions cmd/database/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func MigrateUsers(oldDbConn *gorm.DB) {
Home: true,
Visiting: false,
Status: "Active",
DeletedAt: nil,
DeletedAt: time.Time{},
}

if err := roster.Create(); err != nil {
Expand All @@ -220,7 +220,7 @@ func MigrateUsers(oldDbConn *gorm.DB) {
Home: false,
Visiting: true,
Status: "Active",
DeletedAt: nil,
DeletedAt: time.Time{},
}

if err := roster.Create(); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/swaggo/swag v1.16.3
go.uber.org/zap v1.27.0
golang.org/x/oauth2 v0.23.0
gorm.io/datatypes v1.2.5
gorm.io/driver/mysql v1.5.7
gorm.io/gorm v1.25.12
)
Expand All @@ -45,6 +46,7 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -55,7 +57,7 @@ require (
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/tools v0.26.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
34 changes: 30 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,26 @@ github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaC
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
Expand All @@ -82,6 +96,10 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matoous/go-nanoid v1.5.0 h1:VRorl6uCngneC4oUQqOYtO3S0H5QKFtKuKycFG3euek=
github.com/matoous/go-nanoid v1.5.0/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/microsoft/go-mssqldb v1.7.2 h1:CHkFJiObW7ItKTJfHo1QX7QBBD1iV+mn1eOyRP3b/PA=
github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
Expand Down Expand Up @@ -122,8 +140,8 @@ golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -140,8 +158,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand All @@ -154,8 +172,16 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/datatypes v1.2.5 h1:9UogU3jkydFVW1bIVVeoYsTpLRgwDVW3rHfJG6/Ek9I=
gorm.io/datatypes v1.2.5/go.mod h1:I5FUdlKpLb5PMqeMQhm30CQ6jXP8Rj89xkTeCSAaAD4=
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/postgres v1.5.0 h1:u2FXTy14l45qc3UeCJ7QaAXZmZfDDv0YrthvmRq1l0U=
gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A=
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
gorm.io/driver/sqlserver v1.5.4 h1:xA+Y1KDNspv79q43bPyjDMUgHoYHLhXYmdFcYPobg8g=
gorm.io/driver/sqlserver v1.5.4/go.mod h1:+frZ/qYmuna11zHPlh5oc2O6ZA/lS88Keb0XSH1Zh/g=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
91 changes: 91 additions & 0 deletions internal/training/ots.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package training

type Rating string

const (
Empty Rating = ""
Satisfactory Rating = "Satisfactory"
Unsatisfactory Rating = "Unsatisfactory"
)

// KPI - Key Performance Indicator
type KPI struct {
Order uint `json:"order"`
Title string `json:"title"`
Description string `json:"description"`
Required bool `json:"required"`
Rating `json:"rating"`
}

// KPA - Key Performance Area
type KPA struct {
Order uint `json:"order"`
Title string `json:"title"`
Description string `json:"description"`
Indicators []KPI `json:"indicators"`
}

// KPC - Key performance Category
type KPC struct {
Order uint `json:"order"`
Title string `json:"title"`
Areas []KPA `json:"areas"`
}
type OTS struct {
Title string `json:"title"`
Categories []KPC `json:"categories"`
}

var S2OTS = OTS{
Title: "S2 (Tower) Rating Form",
Categories: []KPC{
{
Order: 1,
Title: "Theory",
Areas: []KPA{
{
Order: 1,
Title: "Clearance Delivery + Ground Control",
Description: "Demonstrates knowledge of Delivery and Ground Controller duties and responsibilities",
Indicators: []KPI{
{
Order: 1,
Title: "Defines all parts of a clearance",
Description: "...",
Required: true,
Rating: Empty,
},
{
Order: 2,
Title: "Explains all types of SIDs",
Description: "...",
Required: true,
Rating: Empty,
},
},
},
{
Order: 2,
Title: "Local Control",
Description: "Demonstrates knowledge of Local Controller duties and responsibilities",
Indicators: []KPI{
{
Order: 1,
Title: "Identifies difference between movement and non-movement areas",
Description: "...",
Required: true,
Rating: Empty,
},
{
Order: 2,
Title: "Defines all parts of VFR traffic pattern",
Description: "...",
Required: true,
Rating: Empty,
},
},
},
},
},
},
}
20 changes: 20 additions & 0 deletions pkg/constants/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,26 @@ func (r RoleID) IsValidRole() bool {
return ok
}

func (r RoleID) IsFacilityStaff() bool {
switch r {
case AirTrafficManagerRole, DeputyAirTrafficManagerRole, TrainingAdministratorRole:
return true
case EventCoordinatorRole, FacilityEngineerRole, WebMasterRole:
return true
}

return false
}

func (r RoleID) IsAssistant() bool {
switch r {
case AssistantEventCoordinator, AssistantFacilityEngineer, AssistantWebMasterRole:
return true
}

return false
}

func (r RoleID) DisplayName() string {
return Roles[r].Name
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/database/models/rating_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ func GetAllRatingChanges() ([]RatingChange, error) {
return ratingChanges, database.DB.Find(&ratingChanges).Error
}

func GetAllRatingChangesByCID(cid uint) ([]RatingChange, error) {
func GetFilteredRatingChanges(cid uint, dateAfter time.Time) ([]RatingChange, error) {
var ratingChanges []RatingChange
return ratingChanges, database.DB.Where("cid = ?", cid).Find(&ratingChanges).Error

query := database.DB
if cid != 0 {
query = query.Where("cid = ?", cid)
}
if !dateAfter.IsZero() {
query = query.Where("created_at > ?", dateAfter)
}

return ratingChanges, query.Find(&ratingChanges).Error
}
2 changes: 1 addition & 1 deletion pkg/database/models/roster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Roster struct {
Roles []UserRole `json:"roles" gorm:"foreignKey:RosterID"`
CreatedAt time.Time `json:"created_at" example:"2021-01-01T00:00:00Z"`
UpdatedAt time.Time `json:"updated_at" example:"2021-01-01T00:00:00Z"`
DeletedAt gorm.DeletedAt `json:"deleted_at" example:"2021-01-01T00:00:00Z"` // Soft Deletes for logging
DeletedAt time.Time `json:"deleted_at" example:"2021-01-01T00:00:00Z"`
}

func (r *Roster) BeforeCreate(tx *gorm.DB) error {
Expand Down
85 changes: 84 additions & 1 deletion pkg/database/models/roster_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/VATUSA/primary-api/pkg/constants"
"github.com/VATUSA/primary-api/pkg/database"
"github.com/VATUSA/primary-api/pkg/database/types"
"gorm.io/gorm"
"time"
)

Expand All @@ -18,12 +19,77 @@ type RosterRequest struct {
UpdatedAt time.Time `json:"updated_at" example:"2021-01-01T00:00:00Z"`
}

func (rr *RosterRequest) BeforeUpdate(tx *gorm.DB) error {
oldRR := &RosterRequest{ID: rr.ID}
if err := oldRR.Get(); err != nil {
return err
}
if oldRR.Status == types.Pending && rr.Status == types.Accepted {
roster := &Roster{
CID: rr.CID,
Facility: rr.Facility,
OIs: "",
Home: false,
Visiting: false,
Status: "Active",
}

if rr.RequestType == types.Visiting {
roster.Visiting = true
} else {
roster.Home = true
}

if err := roster.Create(); err != nil {
return err
}

// Transfers:
// On accepting a transfer remove the user from their current facility
if rr.RequestType == types.Transferring {
rosters, err := GetRostersByCID(rr.CID)
if err != nil {
return err
}

for _, r := range rosters {
if r.Facility != rr.Facility && r.Home {
// if the user is an assistant add them to the new facility as a visitor
for _, role := range r.Roles {
if role.RoleID.IsAssistant() {
roster := &Roster{
CID: r.CID,
Facility: r.Facility,
OIs: r.OIs,
Home: false,
Visiting: true,
Status: "Active",
}

if err := roster.Create(); err != nil {
return err
}
break
}
}

if err := r.Delete(); err != nil {
return err
}
}
}
}
}

return nil
}

func (rr *RosterRequest) Create() error {
return database.DB.Create(rr).Error
}

func (rr *RosterRequest) Update() error {
return database.DB.Save(rr).Error
return database.DB.Updates(rr).Error
}

func (rr *RosterRequest) Delete() error {
Expand All @@ -39,6 +105,23 @@ func GetAllRosterRequests() ([]RosterRequest, error) {
return rosterRequests, database.DB.Find(&rosterRequests).Error
}

func GetFilteredRosterRequests(cid uint, reqType types.RequestType, dateAfter time.Time) ([]RosterRequest, error) {
var rosterRequests []RosterRequest

query := database.DB
if cid != 0 {
query = query.Where("cid = ?", cid)
}
if reqType != "" {
query = query.Where("request_type = ?", reqType)
}
if !dateAfter.IsZero() {
query = query.Where("created_at > ?", dateAfter)
}

return rosterRequests, query.Find(&rosterRequests).Error
}

func GetAllRosterRequestsByCID(cid uint) ([]RosterRequest, error) {
var rosterRequests []RosterRequest
return rosterRequests, database.DB.Where("cid = ?", cid).Find(&rosterRequests).Error
Expand Down
6 changes: 6 additions & 0 deletions pkg/database/models/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func AutoMigrate() {
&UserNotification{},
&UserFlag{},
&UserRole{},
&OTSTemplate{},
&RatingExamRecord{},
&TrainingNotes{},
)
if err != nil {
log.Fatal("[Database] Migration Error:", err)
Expand Down Expand Up @@ -57,6 +60,9 @@ func DropTables() {
&UserNotification{},
&UserFlag{},
&UserRole{},
&OTSTemplate{},
&RatingExamRecord{},
&TrainingNotes{},
)
if err != nil {
log.Fatal("[Database] Drop Table Error:", err)
Expand Down
Loading
Loading