Skip to content

Commit

Permalink
Merge pull request #16 from SwimResults/develop
Browse files Browse the repository at this point in the history
athlete page event ordering by heat time
  • Loading branch information
konrad2002 authored Jun 9, 2024
2 parents 3609436 + 0aa2065 commit e80a07d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions model/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Start struct {
AthleteTeam primitive.ObjectID `json:"athlete_team,omitempty" bson:"athlete_team,omitempty"` // PDF + DSV (+ Livetiming)
AthleteTeamName string `json:"athlete_team_name,omitempty" bson:"athlete_team_name,omitempty"` // PDF + DSV
Rank int `json:"rank,omitempty" bson:"rank,omitempty"` // PDF + DSV (update on import)
Points int `json:"points,omitempty" bson:"points,omitempty"` // PDF + DSV (update on import)
Certified bool `json:"certified,omitempty" bson:"certified,omitempty"` // PDF + DSV (update on import)
Results []Result `json:"results,omitempty" bson:"results,omitempty"` // PDF + DSV + Livetiming
DisqualificationId primitive.ObjectID `json:"-" bson:"disqualification_id,omitempty"` // automatically
Expand Down
21 changes: 19 additions & 2 deletions service/start_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"sort"
"time"
)

Expand Down Expand Up @@ -116,7 +117,15 @@ func GetStartsByMeeting(meeting string) ([]model.Start, error) {
}

func GetStartsByMeetingAndAthlete(meeting string, athlete primitive.ObjectID) ([]model.Start, error) {
return getStartsByBsonDocument(bson.D{{"meeting", meeting}, {"athlete", athlete}})
starts, err := getStartsByBsonDocument(bson.D{{"meeting", meeting}, {"athlete", athlete}})
if err != nil {
return []model.Start{}, err
}

sort.Slice(starts, func(i, j int) bool {
return starts[i].Heat.StartEstimation.Before(starts[j].Heat.StartEstimation)
})
return starts, nil
}

func GetStartsByMeetingAndEvent(meeting string, event int) ([]model.Start, error) {
Expand Down Expand Up @@ -175,7 +184,15 @@ func GetStartByMeetingAndEventAndAthleteId(meeting string, event int, athleteId
}

func GetStartsByAthlete(athlete primitive.ObjectID) ([]model.Start, error) {
return getStartsByBsonDocument(bson.D{{"athlete", athlete}})
starts, err := getStartsByBsonDocument(bson.D{{"athlete", athlete}})
if err != nil {
return []model.Start{}, err
}

sort.Slice(starts, func(i, j int) bool {
return starts[i].Heat.StartEstimation.Before(starts[j].Heat.StartEstimation)
})
return starts, nil
}

func GetStartsByMeetingAndEventAsResults(meeting string, event int) ([]dto.EventStartResultRequestDto, error) {
Expand Down

0 comments on commit e80a07d

Please sign in to comment.