-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from SwimResults/develop
registration backend preparation; fix delay not working with random event number order
- Loading branch information
Showing
7 changed files
with
364 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package controller | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/swimresults/start-service/model" | ||
"github.com/swimresults/start-service/service" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
"net/http" | ||
) | ||
|
||
func registrationController() { | ||
router.GET("/registration/:id", getRegistration) | ||
|
||
router.GET("/registration/meet/:meet_id", getRegistrationsByMeeting) | ||
router.GET("/registration/meet/:meet_id/me", getRegistrationsByMeetingForMe) | ||
|
||
router.POST("/registration", addRegistration) | ||
|
||
router.PUT("/registration", updateRegistration) | ||
router.DELETE("/registration/:id", removeRegistration) | ||
} | ||
|
||
func getRegistration(c *gin.Context) { | ||
id, convErr := primitive.ObjectIDFromHex(c.Param("id")) | ||
if convErr != nil { | ||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "given id was not of type ObjectID"}) | ||
return | ||
} | ||
|
||
registration, err := service.GetRegistrationById(id) | ||
if err != nil { | ||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": err.Error()}) | ||
return | ||
} | ||
|
||
c.IndentedJSON(http.StatusOK, registration) | ||
} | ||
|
||
func getRegistrationsByMeeting(c *gin.Context) { | ||
meeting := c.Param("meet_id") | ||
|
||
if meeting == "" { | ||
c.String(http.StatusBadRequest, "no meeting id given") | ||
return | ||
} | ||
|
||
registrations, err := service.GetRegistrationsByMeeting(meeting) | ||
if err != nil { | ||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": err.Error()}) | ||
return | ||
} | ||
|
||
c.IndentedJSON(http.StatusOK, registrations) | ||
} | ||
|
||
func getRegistrationsByMeetingForMe(c *gin.Context) { | ||
meeting := c.Param("meet_id") | ||
|
||
if meeting == "" { | ||
c.String(http.StatusBadRequest, "no meeting id given") | ||
return | ||
} | ||
|
||
id, convErr := primitive.ObjectIDFromHex(c.Query("user_id")) | ||
if convErr != nil { | ||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "given id was not of type ObjectID"}) | ||
return | ||
} | ||
|
||
registrations, err := service.GetRegistrationByMeetingAndUser(meeting, id) | ||
if err != nil { | ||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": err.Error()}) | ||
return | ||
} | ||
|
||
c.IndentedJSON(http.StatusOK, registrations) | ||
} | ||
|
||
func removeRegistration(c *gin.Context) { | ||
id, convErr := primitive.ObjectIDFromHex(c.Param("id")) | ||
if convErr != nil { | ||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "given id was not of type ObjectID"}) | ||
return | ||
} | ||
|
||
err := service.RemoveRegistrationById(id) | ||
if err != nil { | ||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": err.Error()}) | ||
return | ||
} | ||
|
||
c.IndentedJSON(http.StatusNoContent, "") | ||
} | ||
|
||
func addRegistration(c *gin.Context) { | ||
var registration model.Registration | ||
if err := c.BindJSON(®istration); err != nil { | ||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": err.Error()}) | ||
return | ||
} | ||
|
||
r, err := service.AddRegistration(registration) | ||
if err != nil { | ||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": err.Error()}) | ||
return | ||
} | ||
|
||
c.IndentedJSON(http.StatusOK, r) | ||
} | ||
|
||
func updateRegistration(c *gin.Context) { | ||
var registration model.Registration | ||
if err := c.BindJSON(®istration); err != nil { | ||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": err.Error()}) | ||
return | ||
} | ||
|
||
r, err := service.UpdateRegistration(registration) | ||
if err != nil { | ||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": err.Error()}) | ||
return | ||
} | ||
|
||
c.IndentedJSON(http.StatusOK, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/swimresults/athlete-service/model" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
"time" | ||
) | ||
|
||
type Registration struct { | ||
Identifier primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"` | ||
Meeting string `json:"meeting" bson:"meeting"` | ||
CreatorUserId primitive.ObjectID `json:"creator_user_id,omitempty" bson:"creator_user_id,omitempty"` | ||
Address model.Address `json:"address,omitempty" bson:"address,omitempty"` | ||
Contact model.Contact `json:"contact,omitempty" bson:"contact,omitempty"` | ||
AthleteRegistrations []AthleteRegistration `json:"athlete_registrations" bson:"athlete_registrations"` | ||
AddedAt time.Time `json:"added_at,omitempty" bson:"added_at,omitempty"` | ||
UpdatedAt time.Time `json:"updated_at,omitempty" bson:"updated_at,omitempty"` | ||
} | ||
|
||
type AthleteRegistration struct { | ||
AthleteId primitive.ObjectID `json:"athlete_id,omitempty" bson:"athlete_id,omitempty"` | ||
AthleteFirstName string `json:"athlete_first_name,omitempty" bson:"athlete_first_name,omitempty"` | ||
AthleteLastName string `json:"athlete_last_name,omitempty" bson:"athlete_last_name,omitempty"` | ||
AthleteYear int `json:"athlete_year,omitempty" bson:"athlete_year,omitempty"` | ||
StartRegistrations []StartRegistration `json:"start_registrations" bson:"start_registrations"` | ||
} | ||
|
||
type StartRegistration struct { | ||
Event int `json:"event" bson:"event"` | ||
RegistrationTime time.Duration `json:"registration_time" bson:"registration_time"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.