Skip to content

Commit

Permalink
Add GetUserViaDiscordID endpoint
Browse files Browse the repository at this point in the history
also change recordId to awardUid and recordUid to be more clear
  • Loading branch information
SyniRon committed Jan 3, 2025
1 parent 67dae94 commit 60904bf
Show file tree
Hide file tree
Showing 8 changed files with 535 additions and 272 deletions.
1 change: 1 addition & 0 deletions datastores/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ type Datastore interface {
FindProfilesByUsername(username string) ([]*proto.Profile, error)
FindRosterByType(rosterType proto.RosterType) (*proto.Roster, error)
FindProfileByKeycloakID(keycloakId string) (*proto.Profile, error)
FindProfileByDiscordID(discordId string) (*proto.Profile, error)
}
26 changes: 24 additions & 2 deletions datastores/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,28 @@ func (ds Mysql) FindProfileByKeycloakID(keycloakId string) (*proto.Profile, erro
return milpac, nil
}

func (ds Mysql) FindProfileByDiscordID(discordId string) (*proto.Profile, error) {
var profile milpacs.Profile

Info.Println("Searching for milpac profiles with discord IDs of: %s", discordId)

query := map[string]interface{}{"xf_user_connected_account.provider_key": discordId, "xf_user_connected_account.provider": "nfDiscord"}

ds.Db.Preload(clause.Associations).
Preload("AwardRecords.Award").
Joins(xenforo.ConnectedAccountJoin).
Where(query).
First(&profile)

milpac, err := ds.generateProtoProfile(profile)

if err != nil {
return nil, fmt.Errorf("error generating profile")
}

return milpac, nil
}

func (ds Mysql) generateProtoProfile(profile milpacs.Profile) (*proto.Profile, error) {
milpac := &proto.Profile{
User: &proto.User{
Expand Down Expand Up @@ -197,7 +219,7 @@ func collectRecords(recordRows []milpacs.Record) []*proto.Record {
RecordDetails: recordRow.Details,
RecordType: proto.RecordType(recordRow.RecordTypeId),
RecordDate: stringToTime(strconv.Itoa(int(recordRow.RecordDate))).Format(layoutISO),
RecordId: recordRow.RecordID,
RecordUid: recordRow.RecordID,
}
records = append(records, record)
}
Expand All @@ -214,7 +236,7 @@ func collectAwards(awardRows []milpacs.AwardRecord) []*proto.Award {
AwardDetails: awardRow.Details,
AwardDate: stringToTime(strconv.Itoa(int(awardRow.AwardDate))).Format(layoutISO),
AwardImageUrl: awardRow.Award.ImageURL(),
RecordId: awardRow.RecordID,
AwardUid: awardRow.RecordID,
}
awards = append(awards, award)
}
Expand Down
Loading

0 comments on commit 60904bf

Please sign in to comment.