Skip to content

Commit

Permalink
dont remember
Browse files Browse the repository at this point in the history
  • Loading branch information
Raajheer1 committed Aug 13, 2024
1 parent 1a999fb commit c45555b
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 38 deletions.
3 changes: 2 additions & 1 deletion external/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func Router(r chi.Router, cfg *config.Config) {
v3.Router(r, cfg)

r.Get("/swagger/*", httpSwagger.Handler(
httpSwagger.URL("https://api.vatusa.dev/v3/swagger/doc.json"),
//httpSwagger.URL("https://api.vatusa.dev/swagger/doc.json"),
httpSwagger.URL("http://localhost:3000/swagger/swagger.json"),
))

}
2 changes: 1 addition & 1 deletion external/v3/disciplinary-log/disciplinary_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type Request struct {
Entry string `json:"entry" example:"Changed Preferred OIs to RP" validate:"required"`
Entry string `json:"entry" example:"Misconduct in discord" validate:"required"`
VATUSAOnly bool `json:"vatusa_only" example:"true"`
}

Expand Down
39 changes: 3 additions & 36 deletions external/v3/user/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/VATUSA/primary-api/pkg/database/models"
"github.com/VATUSA/primary-api/pkg/oauth"
"github.com/VATUSA/primary-api/pkg/utils"
vatsim_api "github.com/VATUSA/primary-api/pkg/vatsim/api"
gonanoid "github.com/matoous/go-nanoid"
"golang.org/x/oauth2"
"io"
Expand All @@ -20,40 +21,6 @@ import (
"time"
)

type VATSIMUser struct {
CID string `json:"cid"`
Personal struct {
FirstName string `json:"name_first"`
LastName string `json:"name_last"`
FullName string `json:"name_full"`
Email string `json:"email"`
} `json:"personal"`
VATSIM struct {
ControllerRating struct {
ID int `json:"id"`
Short string `json:"short"`
Long string `json:"long"`
} `json:"rating"`
PilotRating struct {
ID int `json:"id"`
Short string `json:"short"`
Long string `json:"long"`
} `json:"pilotrating"`
Region struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"region"`
Division struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"division"`
Subdivision struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"subdivision"`
}
}

func GetLogin(w http.ResponseWriter, r *http.Request) {
state, err := gonanoid.Generate("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 64)
if err != nil {
Expand Down Expand Up @@ -119,7 +86,7 @@ func GetLoginCallback(w http.ResponseWriter, r *http.Request) {
res, err := http.NewRequest("GET", fmt.Sprintf("%s%s", config.Cfg.OAuth.BaseURL, config.Cfg.OAuth.UserInfoURL), nil)
res.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token.AccessToken))
res.Header.Add("Accept", "application/json")
res.Header.Add("User-Agent", "usa-primary-api")
res.Header.Add("User-Agent", "vatusa-primary-api")
if err != nil {
utils.Render(w, r, utils.ErrInternalServerWithErr(err))
return
Expand Down Expand Up @@ -149,7 +116,7 @@ func GetLoginCallback(w http.ResponseWriter, r *http.Request) {
return
}

user := &VATSIMUser{}
user := &vatsim_api.User{}
if err := json.Unmarshal(body, user); err != nil {
utils.Render(w, r, utils.ErrInternalServerWithErr(err))
return
Expand Down
63 changes: 63 additions & 0 deletions pkg/constants/facility_tiers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package constants

var (
FacilityTierOne = map[FacilityID][]FacilityID{
AlbuquerqueFacility: {
LosAngelesFacility,
DenverFacility,
KansasCityFacility,
FortWorthFacility,
HoustonFacility,
},
LosAngelesFacility: {
OaklandFacility,
SaltLakeFacility,
DenverFacility,
AlbuquerqueFacility,
HonoluluFacility,
},
OaklandFacility: {
SeattleFacility,
SaltLakeFacility,
LosAngelesFacility,
HonoluluFacility,
},
SeattleFacility: {
AnchorageFacility,
SaltLakeFacility,
OaklandFacility,
HonoluluFacility,
},
HonoluluFacility: {
AnchorageFacility,
SeattleFacility,
OaklandFacility,
LosAngelesFacility,
},
DenverFacility: {
SaltLakeFacility,
MinneapolisFacility,
KansasCityFacility,
AlbuquerqueFacility,
LosAngelesFacility,
},
HoustonFacility: {
AlbuquerqueFacility,
FortWorthFacility,
MemphisFacility,
JacksonvilleFacility,
},

//TODO - finish me
}
)

func (a FacilityID) IsTierOne(b FacilityID) bool {
for _, fac := range FacilityTierOne[a] {
if fac == b {
return true
}
}

return false
}
35 changes: 35 additions & 0 deletions pkg/vatsim/api/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package vatsim_api

type User struct {
CID string `json:"cid"`
Personal struct {
FirstName string `json:"name_first"`
LastName string `json:"name_last"`
FullName string `json:"name_full"`
Email string `json:"email"`
} `json:"personal"`
VATSIM struct {
ControllerRating struct {
ID int `json:"id"`
Short string `json:"short"`
Long string `json:"long"`
} `json:"rating"`
PilotRating struct {
ID int `json:"id"`
Short string `json:"short"`
Long string `json:"long"`
} `json:"pilotrating"`
Region struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"region"`
Division struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"division"`
Subdivision struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"subdivision"`
}
}
63 changes: 63 additions & 0 deletions pkg/vatsim/webhooks/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package vatsim_webhooks

import (
"encoding/json"
"time"
)

type Message struct {
CID uint `json:"resource"`
Actions []Action `json:"actions"`
}

type WebhookActionType string

const (
UserCreation WebhookActionType = "member_created_action"
UserChanged WebhookActionType = "member_changed_action"
)

type Action struct {
Type WebhookActionType `json:"action"`
Authority string `json:"authority"`
Comment string `json:"comment"`
Deltas []Delta `json:"deltas"`
Timestamp time.Time `json:"timestamp"`
}

type Delta struct {
Field string `json:"field"`
Before string `json:"before"`
After string `json:"after"`
}

// TODO - does user creation webhook only send to VATUSA if they select division_id = USA?
// TODO - Rating changes? if VATUSA is the authority its not gonna send the webhook back to VATUSA correct? or it will?
func ConsumeMessage(rawMessage string) error {
msg := Message{}
if err := json.Unmarshal([]byte(rawMessage), &msg); err != nil {
return err
}

for _, action := range msg.Actions {
switch action.Type {
case UserCreation:
//
case UserChanged:
//
default:
// TODO - log unknown actionType

}
}

return nil
}

func HandleUserCreation(action Action) error {
return nil
}

func HandleUserChange(action Action) error {
return nil
}

0 comments on commit c45555b

Please sign in to comment.