56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
|
|
"git.itzana.me/strafesnet/maps-service/api"
|
|
"git.itzana.me/strafesnet/maps-service/internal/controller/submissions"
|
|
"git.itzana.me/strafesnet/maps-service/internal/controller/users"
|
|
"git.itzana.me/strafesnet/maps-service/internal/datastore/gormstore"
|
|
)
|
|
|
|
type apiServer struct {
|
|
submissions *submissions.Submissions
|
|
users *users.Users
|
|
}
|
|
|
|
// GetUserRank implements api.Handler.
|
|
func (m *apiServer) GetSubmission(ctx context.Context, params api.GetSubmissionParams) (*api.Submission, error) {
|
|
return m.submissions.Get(ctx,params)
|
|
}
|
|
|
|
// NewError implements api.Handler.
|
|
func (m *apiServer) NewError(ctx context.Context, err error) *api.ErrorStatusCode {
|
|
return &api.ErrorStatusCode{
|
|
StatusCode: 500,
|
|
Response: api.Error{Message: err.Error()},
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
db, err := gormstore.New(true)
|
|
if err != nil {
|
|
log.WithField("error", err).Fatalln("database startup failed")
|
|
return
|
|
}
|
|
|
|
svc := &apiServer{
|
|
submissions: db.Submissions(),
|
|
users: db.Users(),
|
|
}
|
|
|
|
srv, err := api.NewServer(
|
|
svc,
|
|
api.WithPathPrefix("/v2"),
|
|
)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if err := http.ListenAndServe(":8080", srv); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|