diff --git a/.env.example b/.env.example index e7a9de3..2e1e552 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,6 @@ export DB_NAME=knoldus # Example: sRqXKbHFdQ8Wka6NWvk3ZaZhY3JD3CnUw7H5B42gETZS8feYUFUJ8k2jRvnNQrLwEyPWnwfuGN9XG3GQaPxC6HdtNNYmbZW6MEN32BfSpsDzdVtQJXuNHfmUPsRw4LDdyRxs4PVFHAmGfnF3BWPZgJpnMst28QCDbKpWfbM8G8vmPQD9fRh6KxsZqsGz3QpCmwekHPnuX3n9n9KHp8emReeLq7EKnSsmhCcVeQNB2psgSUkVYpgeaXBDHZ8TVjmq export SECRET_KEY='your-256-bit-secret' -export PORT=8081 +export PORT=8082 export BASE_URL=localhost export ENV=local \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f8eb480..db936fa 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.22 - name: Build run: go build -v ./... @@ -30,7 +30,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.22 - name: Test and Coverage run: go test ./... -coverprofile=coverage.txt -covermode=atomic diff --git a/api/handlers/api.go b/api/handlers/api.go index 509694f..8a83ac8 100644 --- a/api/handlers/api.go +++ b/api/handlers/api.go @@ -25,6 +25,10 @@ type App struct { // New creates a new mux router and all the routes func (a *App) New() *mux.Router { + // setup go-guardian for middleware + m := api.MiddlewareDB{DB: databases.NewUserDatabase(a.dbHelper)} + m.SetupGoGuardian() + r := mux.NewRouter() u := User{DB: databases.NewUserDatabase(a.dbHelper)} @@ -37,17 +41,26 @@ func (a *App) New() *mux.Router { ev := EmsVehicle{DB: databases.NewEmsVehicleDatabase(a.dbHelper)} w := Warrant{DB: databases.NewWarrantDatabase(a.dbHelper)} call := Call{DB: databases.NewCallDatabase(a.dbHelper)} + s := Spotlight{DB: databases.NewSpotlightDatabase(a.dbHelper)} // healthchex r.HandleFunc("/health", healthCheckHandler) apiCreate := r.PathPrefix("/api/v1").Subrouter() + apiCreate.Handle("/auth/token", api.Middleware(http.HandlerFunc(api.CreateToken))).Methods("POST") + apiCreate.Handle("/auth/logout", api.Middleware(http.HandlerFunc(api.RevokeToken))).Methods("DELETE") + apiCreate.Handle("/community/{community_id}", api.Middleware(http.HandlerFunc(c.CommunityHandler))).Methods("GET") apiCreate.Handle("/community/{community_id}/{owner_id}", api.Middleware(http.HandlerFunc(c.CommunityByCommunityAndOwnerIDHandler))).Methods("GET") apiCreate.Handle("/communities/{owner_id}", api.Middleware(http.HandlerFunc(c.CommunitiesByOwnerIDHandler))).Methods("GET") + apiCreate.Handle("/user/{user_id}", api.Middleware(http.HandlerFunc(u.UserHandler))).Methods("GET") + apiCreate.Handle("/user/create-user", http.HandlerFunc(u.UserCreateHandler)).Methods("POST") + apiCreate.Handle("/user/check-user", http.HandlerFunc(u.UserCheckEmailHandler)).Methods("POST") + apiCreate.Handle("/users/discover-people", api.Middleware(http.HandlerFunc(u.UsersDiscoverPeopleHandler))).Methods("GET") apiCreate.Handle("/users/{active_community_id}", api.Middleware(http.HandlerFunc(u.UsersFindAllHandler))).Methods("GET") + apiCreate.Handle("/civilian/{civilian_id}", api.Middleware(http.HandlerFunc(civ.CivilianByIDHandler))).Methods("GET") apiCreate.Handle("/civilians", api.Middleware(http.HandlerFunc(civ.CivilianHandler))).Methods("GET") apiCreate.Handle("/civilians/user/{user_id}", api.Middleware(http.HandlerFunc(civ.CiviliansByUserIDHandler))).Methods("GET") @@ -80,6 +93,9 @@ func (a *App) New() *mux.Router { apiCreate.Handle("/calls", api.Middleware(http.HandlerFunc(call.CallHandler))).Methods("GET") apiCreate.Handle("/calls/community/{community_id}", api.Middleware(http.HandlerFunc(call.CallsByCommunityIDHandler))).Methods("GET") + apiCreate.Handle("/spotlight", api.Middleware(http.HandlerFunc(s.SpotlightHandler))).Methods("GET") + apiCreate.Handle("/spotlight", api.Middleware(http.HandlerFunc(s.SpotlightCreateHandler))).Methods("POST") + // swagger docs hosted at "/" r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("./docs/")))) return r diff --git a/api/handlers/api_test.go b/api/handlers/api_test.go index 15957d2..bc3b013 100644 --- a/api/handlers/api_test.go +++ b/api/handlers/api_test.go @@ -70,12 +70,12 @@ func TestApp_CommunityHandlerInvalidToken(t *testing.T) { req.Header.Add("Authorization", "Bearer asdfasdf") response := executeRequest(req) - checkResponseCode(t, http.StatusInternalServerError, response.Code) + checkResponseCode(t, http.StatusUnauthorized, response.Code) var m map[string]string json.Unmarshal(response.Body.Bytes(), &m) - if m["error"] != "failed to parse token, token contains an invalid number of segments" { - t.Errorf("Expected the 'error' key of the reponse to be set to 'failed to parse token, token contains an invalid number of segments'. Got '%s'", m["error"]) + if m["error"] != "unauthorized" { + t.Errorf("Expected the 'error' key of the reponse to be set to 'unauthorized'. Got '%s'", m["error"]) } } diff --git a/api/handlers/spotlight.go b/api/handlers/spotlight.go new file mode 100644 index 0000000..504f5a2 --- /dev/null +++ b/api/handlers/spotlight.go @@ -0,0 +1,100 @@ +package handlers + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "strconv" + + "github.com/gorilla/mux" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo/options" + "go.uber.org/zap" + + "github.com/linesmerrill/police-cad-api/config" + "github.com/linesmerrill/police-cad-api/databases" + "github.com/linesmerrill/police-cad-api/models" +) + +// Spotlight exported for testing purposes +type Spotlight struct { + DB databases.SpotlightDatabase +} + +// SpotlightHandler returns all spotlights +func (s Spotlight) SpotlightHandler(w http.ResponseWriter, r *http.Request) { + Limit, err := strconv.Atoi(r.URL.Query().Get("limit")) + if err != nil { + zap.S().Warnf(fmt.Sprintf("limit not set, using default of %v, err: %v", Limit|10, err)) + } + limit64 := int64(Limit) + Page = getPage(Page, r) + skip64 := int64(Page * Limit) + dbResp, err := s.DB.Find(context.TODO(), bson.D{}, &options.FindOptions{Limit: &limit64, Skip: &skip64}) + if err != nil { + config.ErrorStatus("failed to get spotlight", http.StatusNotFound, w, err) + return + } + // Because the frontend requires that the data elements inside models.Spotlight exist, if + // len == 0 then we will just return an empty data object + if len(dbResp) == 0 { + dbResp = []models.Spotlight{} + } + b, err := json.Marshal(dbResp) + if err != nil { + config.ErrorStatus("failed to marshal response", http.StatusInternalServerError, w, err) + return + } + w.WriteHeader(http.StatusOK) + w.Write(b) +} + +// SpotlightByIDHandler returns a spotlight by ID +func (s Spotlight) SpotlightByIDHandler(w http.ResponseWriter, r *http.Request) { + spotlightID := mux.Vars(r)["spotlight_id"] + + zap.S().Debugf("spotlight_id: %v", spotlightID) + + cID, err := primitive.ObjectIDFromHex(spotlightID) + if err != nil { + config.ErrorStatus("failed to get objectID from Hex", http.StatusBadRequest, w, err) + return + } + + dbResp, err := s.DB.FindOne(context.Background(), bson.M{"_id": cID}) + if err != nil { + config.ErrorStatus("failed to get spotlight by ID", http.StatusNotFound, w, err) + return + } + + b, err := json.Marshal(dbResp) + if err != nil { + config.ErrorStatus("failed to marshal response", http.StatusInternalServerError, w, err) + return + } + w.WriteHeader(http.StatusOK) + w.Write(b) +} + +// SpotlightCreateHandler creates a spotlight +func (s Spotlight) SpotlightCreateHandler(w http.ResponseWriter, r *http.Request) { + var spotlightDetails models.SpotlightDetails + err := json.NewDecoder(r.Body).Decode(&spotlightDetails) + if err != nil { + config.ErrorStatus("failed to decode request", http.StatusBadRequest, w, err) + return + } + + h := s.DB.InsertOne(context.Background(), spotlightDetails) + zap.S().Debugf("inserted spotlight: %v", h) + + b, err := json.Marshal(spotlightDetails) + if err != nil { + config.ErrorStatus("failed to marshal response", http.StatusInternalServerError, w, err) + return + } + w.WriteHeader(http.StatusCreated) + w.Write(b) +} diff --git a/api/handlers/spotlight_test.go b/api/handlers/spotlight_test.go new file mode 100644 index 0000000..5ac8282 --- /dev/null +++ b/api/handlers/spotlight_test.go @@ -0,0 +1 @@ +package handlers diff --git a/api/handlers/user.go b/api/handlers/user.go index 7bccd01..a7d0c60 100644 --- a/api/handlers/user.go +++ b/api/handlers/user.go @@ -2,19 +2,23 @@ package handlers import ( "context" + "crypto/sha256" + "crypto/subtle" "encoding/json" + "fmt" "net/http" "github.com/gorilla/mux" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.uber.org/zap" - "github.com/linesmerrill/police-cad-api/config" "github.com/linesmerrill/police-cad-api/databases" "github.com/linesmerrill/police-cad-api/models" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.uber.org/zap" + "golang.org/x/crypto/bcrypt" ) +// User exported for testing purposes type User struct { DB databases.UserDatabase } @@ -70,3 +74,129 @@ func (u User) UsersFindAllHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write(b) } + +// UserLoginHandler returns a session token for a user +func (u User) UserLoginHandler(w http.ResponseWriter, r *http.Request) { + email, password, ok := r.BasicAuth() + if ok { + usernameHash := sha256.Sum256([]byte(email)) + + // fetch email & pass from db + dbEmailResp, err := u.DB.Find(context.Background(), bson.M{"user.email": email}) + if err != nil { + config.ErrorStatus("failed to get user by ID", http.StatusNotFound, w, err) + return + } + if len(dbEmailResp) == 0 { + config.ErrorStatus("no matching email found", http.StatusUnauthorized, w, fmt.Errorf("no matching email found")) + return + } + + expectedUsernameHash := sha256.Sum256([]byte(dbEmailResp[0].Details.Email)) + usernameMatch := subtle.ConstantTimeCompare(usernameHash[:], expectedUsernameHash[:]) == 1 + + err = bcrypt.CompareHashAndPassword([]byte(dbEmailResp[0].Details.Password), []byte(password)) + if err != nil { + config.ErrorStatus("failed to compare password", http.StatusUnauthorized, w, err) + return + } + + if usernameMatch { + w.WriteHeader(http.StatusOK) + return + } + } + + w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`) + http.Error(w, "Unauthorized", http.StatusUnauthorized) + +} + +// UserCreateHandler creates a user +func (u User) UserCreateHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + var user models.UserDetails + err := json.NewDecoder(r.Body).Decode(&user) + if err != nil { + config.ErrorStatus("failed to decode request", http.StatusBadRequest, w, err) + return + } + + // check if the user already exists + existingUser, _ := u.DB.FindOne(context.Background(), bson.M{"email": user.Email}) + if existingUser != nil { + config.ErrorStatus("email already exists", http.StatusConflict, w, fmt.Errorf("duplicate email")) + return + } + + // hash the password + hashedPassword, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost) + if err != nil { + config.ErrorStatus("failed to hash password", http.StatusInternalServerError, w, err) + return + } + user.Password = string(hashedPassword) + + // insert the user + _ = u.DB.InsertOne(context.Background(), user) + if err != nil { + config.ErrorStatus("failed to insert user", http.StatusInternalServerError, w, err) + return + } + + w.WriteHeader(http.StatusCreated) + +} + +// UserCheckEmailHandler checks if an email exists using POST +func (u User) UserCheckEmailHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + var user models.UserDetails + err := json.NewDecoder(r.Body).Decode(&user) + if err != nil { + config.ErrorStatus("failed to decode request", http.StatusBadRequest, w, err) + return + } + + // check if the user already exists + existingUser, _ := u.DB.FindOne(context.Background(), bson.M{"email": user.Email}) + if existingUser != nil { + config.ErrorStatus("email already exists", http.StatusConflict, w, fmt.Errorf("duplicate email")) + return + } + + w.WriteHeader(http.StatusOK) +} + +// UsersDiscoverPeopleHandler returns a list of users that we suggest to the user to follow +func (u User) UsersDiscoverPeopleHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + email := r.URL.Query().Get("email") + if email == "" { + config.ErrorStatus("query param email is required", http.StatusBadRequest, w, fmt.Errorf("query param email is required")) + return + } + + pipeline := []bson.M{ + {"$match": bson.M{"user.email": bson.M{"$ne": email}}}, + {"$sample": bson.M{"size": 4}}, + } + + dbResp, err := u.DB.Aggregate(context.Background(), pipeline) + if err != nil { + config.ErrorStatus("failed to get discover people recommendations", http.StatusInternalServerError, w, err) + return + } + // Because the frontend requires that the data elements inside models.User exist, if + // len == 0 then we will just return an empty data object + if len(dbResp) == 0 { + dbResp = []models.User{} + } + b, err := json.Marshal(dbResp) + if err != nil { + config.ErrorStatus("failed to marshal response", http.StatusInternalServerError, w, err) + return + } + w.WriteHeader(http.StatusOK) + w.Write(b) +} diff --git a/api/middleware.go b/api/middleware.go index 3ea5898..10bc055 100644 --- a/api/middleware.go +++ b/api/middleware.go @@ -2,70 +2,113 @@ package api import ( "context" + "crypto/sha256" + "crypto/subtle" "fmt" "net/http" - "net/http/httputil" - "os" "strings" - "github.com/form3tech-oss/jwt-go" + "time" + + "github.com/google/uuid" + "github.com/linesmerrill/police-cad-api/databases" + "github.com/shaj13/go-guardian/auth" + "github.com/shaj13/go-guardian/auth/strategies/bearer" + + "github.com/shaj13/go-guardian/auth/strategies/basic" + "github.com/shaj13/go-guardian/store" + "go.mongodb.org/mongo-driver/bson" "go.uber.org/zap" + "golang.org/x/crypto/bcrypt" ) -type key int +// MiddlewareDB is a struct that holds the database +type MiddlewareDB struct { + DB databases.UserDatabase +} -const ( - keyPrincipalID key = iota -) +var authenticator auth.Authenticator +var cache store.Cache // Middleware adds some basic header authentication around accessing the routes func Middleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - authHeader := strings.Split(r.Header.Get("Authorization"), "Bearer ") - // we don't really care about the error here, if it fails then oh well :shrug: - dump, _ := httputil.DumpRequest(r, true) - zap.S().Debugw("incoming request", - "request body", string(dump)) - if len(authHeader) != 2 { - zap.S().Errorw("malformed token", - "url", r.URL, - "auth header", r.Header.Get("Authorization"), - ) - w.WriteHeader(http.StatusUnauthorized) - w.Write([]byte(`{"error": "malformed authorization token, see https://github.com/Linesmerrill/police-cad-api#requirements for help"}`)) - return - } - jwtToken := authHeader[1] - token, err := jwt.Parse(jwtToken, func(token *jwt.Token) (interface{}, error) { - if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { - return nil, fmt.Errorf(`{"error": "unexpected signing method, %v"}`, token.Header["alg"]) - } - return []byte(os.Getenv("SECRET_KEY")), nil - }) + user, err := authenticator.Authenticate(r) if err != nil { - zap.S().With("error", err).Errorw("failed to parse token", - "url", r.URL, - "token", jwtToken, - ) - w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf(`{"error": "failed to parse token, %v"}`, err))) - return - } - - if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid { - ctx := context.WithValue(r.Context(), keyPrincipalID, claims) - // Access context values in handlers like this - // props, _ := r.Context().Value("props").(jwt.MapClaims) - next.ServeHTTP(w, r.WithContext(ctx)) - } else { zap.S().Errorw("unauthorized", - "url", r.URL, - "token", jwtToken, - ) + "url", r.URL) w.WriteHeader(http.StatusUnauthorized) - w.Write([]byte(`{"error": "unauthorized"}"`)) + w.Write([]byte(`{"error": "unauthorized"}`)) return } + zap.S().Debugf("User %s Authenticated\n", user.UserName()) + next.ServeHTTP(w, r) }) } + +// CreateToken returns a token +func CreateToken(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + email, _, ok := r.BasicAuth() + if !ok { + http.Error(w, "basic auth failed", http.StatusUnauthorized) + return + } + token := uuid.New().String() + user := auth.NewDefaultUser(email, "1", nil, nil) + tokenStrategy := authenticator.Strategy(bearer.CachedStrategyKey) + auth.Append(tokenStrategy, token, user, r) + body := fmt.Sprintf(`{"token": "%s"}`, token) + w.Write([]byte(body)) +} + +// SetupGoGuardian sets up the go-guardian middleware +func (m MiddlewareDB) SetupGoGuardian() { + authenticator = auth.New() + cache = store.NewFIFO(context.Background(), time.Hour*26280) // 3 years ttl + basicStrategy := basic.New(m.ValidateUser, cache) + tokenStrategy := bearer.New(bearer.NoOpAuthenticate, cache) + + authenticator.EnableStrategy(basic.StrategyKey, basicStrategy) + authenticator.EnableStrategy(bearer.CachedStrategyKey, tokenStrategy) +} + +// ValidateUser validates a user +func (m MiddlewareDB) ValidateUser(ctx context.Context, r *http.Request, email, password string) (auth.Info, error) { + usernameHash := sha256.Sum256([]byte(email)) + + // fetch email & pass from db + dbEmailResp, err := m.DB.Find(context.Background(), bson.M{"user.email": email}) + if err != nil { + return nil, fmt.Errorf("failed to get user by ID") + } + if len(dbEmailResp) == 0 { + return nil, fmt.Errorf("no matching email found") + } + + expectedUsernameHash := sha256.Sum256([]byte(dbEmailResp[0].Details.Email)) + usernameMatch := subtle.ConstantTimeCompare(usernameHash[:], expectedUsernameHash[:]) == 1 + + err = bcrypt.CompareHashAndPassword([]byte(dbEmailResp[0].Details.Password), []byte(password)) + if err != nil { + return nil, fmt.Errorf("failed to compare password") + } + + if usernameMatch { + return auth.NewDefaultUser(email, "1", nil, nil), nil + } + return nil, fmt.Errorf("invalid credentials") +} + +// RevokeToken revokes a token +func RevokeToken(w http.ResponseWriter, r *http.Request) { + reqToken := r.Header.Get("Authorization") + splitToken := strings.Split(reqToken, "Bearer ") + reqToken = splitToken[1] + + tokenStrategy := authenticator.Strategy(bearer.CachedStrategyKey) + auth.Revoke(tokenStrategy, reqToken, r) + body := fmt.Sprintf(`{"revoked token": "%s"}`, reqToken) + w.Write([]byte(body)) +} diff --git a/databases/database.go b/databases/database.go index 14fbd9f..bf84243 100644 --- a/databases/database.go +++ b/databases/database.go @@ -20,6 +20,8 @@ type DatabaseHelper interface { type CollectionHelper interface { FindOne(context.Context, interface{}, ...*options.FindOneOptions) SingleResultHelper Find(context.Context, interface{}, ...*options.FindOptions) CursorHelper + InsertOne(context.Context, interface{}, ...*options.InsertOneOptions) InsertOneResultHelper + Aggregate(context.Context, interface{}, ...*options.AggregateOptions) (CursorHelper, error) } // SingleResultHelper contains a single method to decode the result @@ -27,6 +29,11 @@ type SingleResultHelper interface { Decode(v interface{}) error } +// InsertOneResultHelper contains a single method to decode the result +type InsertOneResultHelper interface { + Decode() interface{} +} + // CursorHelper contains a method to decode the cursor type CursorHelper interface { Decode(v interface{}) error @@ -55,6 +62,10 @@ type mongoSingleResult struct { sr *mongo.SingleResult } +type mongoInsertOneResult struct { + ior *mongo.InsertOneResult +} + type mongoCursor struct { cr *mongo.Cursor } @@ -104,6 +115,14 @@ func (mc *mongoCollection) FindOne(ctx context.Context, filter interface{}, opts return &mongoSingleResult{sr: singleResult} } +func (mc *mongoCollection) InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) InsertOneResultHelper { + insertOneResult, err := mc.coll.InsertOne(ctx, document, opts...) + if err != nil { + println(err) + } + return &mongoInsertOneResult{ior: insertOneResult} +} + func (mc *mongoCollection) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) CursorHelper { cursor, err := mc.coll.Find(ctx, filter, opts...) if err != nil { @@ -112,10 +131,22 @@ func (mc *mongoCollection) Find(ctx context.Context, filter interface{}, opts .. return &mongoCursor{cr: cursor} } +func (mc *mongoCollection) Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (CursorHelper, error) { + cursor, err := mc.coll.Aggregate(ctx, pipeline, opts...) + if err != nil { + println(err) + } + return &mongoCursor{cr: cursor}, err +} + func (sr *mongoSingleResult) Decode(v interface{}) error { return sr.sr.Decode(v) } +func (ior *mongoInsertOneResult) Decode() interface{} { + return ior.ior.InsertedID +} + func (cr *mongoCursor) Decode(v interface{}) error { return cr.All(context.Background(), v) } diff --git a/databases/mocks/CallDatabase.go b/databases/mocks/CallDatabase.go index 14b1bcc..190997c 100644 --- a/databases/mocks/CallDatabase.go +++ b/databases/mocks/CallDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -28,7 +28,15 @@ func (_m *CallDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*optio _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.Call + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.Call, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.Call); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -37,7 +45,6 @@ func (_m *CallDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*optio } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -58,7 +65,15 @@ func (_m *CallDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ...*op _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.Call + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.Call, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.Call); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -67,7 +82,6 @@ func (_m *CallDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ...*op } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -76,3 +90,17 @@ func (_m *CallDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ...*op return r0, r1 } + +// NewCallDatabase creates a new instance of CallDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCallDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *CallDatabase { + mock := &CallDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/CivilianDatabase.go b/databases/mocks/CivilianDatabase.go index 20e67fb..f93871f 100644 --- a/databases/mocks/CivilianDatabase.go +++ b/databases/mocks/CivilianDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -28,7 +28,15 @@ func (_m *CivilianDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*o _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.Civilian + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.Civilian, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.Civilian); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -37,7 +45,6 @@ func (_m *CivilianDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*o } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -58,7 +65,15 @@ func (_m *CivilianDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 .. _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.Civilian + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.Civilian, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.Civilian); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -67,7 +82,6 @@ func (_m *CivilianDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 .. } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -76,3 +90,17 @@ func (_m *CivilianDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 .. return r0, r1 } + +// NewCivilianDatabase creates a new instance of CivilianDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCivilianDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *CivilianDatabase { + mock := &CivilianDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/ClientHelper.go b/databases/mocks/ClientHelper.go index 65ab687..543c628 100644 --- a/databases/mocks/ClientHelper.go +++ b/databases/mocks/ClientHelper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type ClientHelper struct { func (_m *ClientHelper) Connect() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for Connect") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -32,6 +36,10 @@ func (_m *ClientHelper) Connect() error { func (_m *ClientHelper) Database(_a0 string) databases.DatabaseHelper { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for Database") + } + var r0 databases.DatabaseHelper if rf, ok := ret.Get(0).(func(string) databases.DatabaseHelper); ok { r0 = rf(_a0) @@ -48,7 +56,15 @@ func (_m *ClientHelper) Database(_a0 string) databases.DatabaseHelper { func (_m *ClientHelper) StartSession() (mongo.Session, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for StartSession") + } + var r0 mongo.Session + var r1 error + if rf, ok := ret.Get(0).(func() (mongo.Session, error)); ok { + return rf() + } if rf, ok := ret.Get(0).(func() mongo.Session); ok { r0 = rf() } else { @@ -57,7 +73,6 @@ func (_m *ClientHelper) StartSession() (mongo.Session, error) { } } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -66,3 +81,17 @@ func (_m *ClientHelper) StartSession() (mongo.Session, error) { return r0, r1 } + +// NewClientHelper creates a new instance of ClientHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewClientHelper(t interface { + mock.TestingT + Cleanup(func()) +}) *ClientHelper { + mock := &ClientHelper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/CollectionHelper.go b/databases/mocks/CollectionHelper.go index 1685ab6..e8a9006 100644 --- a/databases/mocks/CollectionHelper.go +++ b/databases/mocks/CollectionHelper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -16,6 +16,43 @@ type CollectionHelper struct { mock.Mock } +// Aggregate provides a mock function with given fields: _a0, _a1, _a2 +func (_m *CollectionHelper) Aggregate(_a0 context.Context, _a1 interface{}, _a2 ...*options.AggregateOptions) (databases.CursorHelper, error) { + _va := make([]interface{}, len(_a2)) + for _i := range _a2 { + _va[_i] = _a2[_i] + } + var _ca []interface{} + _ca = append(_ca, _a0, _a1) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Aggregate") + } + + var r0 databases.CursorHelper + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.AggregateOptions) (databases.CursorHelper, error)); ok { + return rf(_a0, _a1, _a2...) + } + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.AggregateOptions) databases.CursorHelper); ok { + r0 = rf(_a0, _a1, _a2...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(databases.CursorHelper) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.AggregateOptions) error); ok { + r1 = rf(_a0, _a1, _a2...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // Find provides a mock function with given fields: _a0, _a1, _a2 func (_m *CollectionHelper) Find(_a0 context.Context, _a1 interface{}, _a2 ...*options.FindOptions) databases.CursorHelper { _va := make([]interface{}, len(_a2)) @@ -27,6 +64,10 @@ func (_m *CollectionHelper) Find(_a0 context.Context, _a1 interface{}, _a2 ...*o _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 databases.CursorHelper if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) databases.CursorHelper); ok { r0 = rf(_a0, _a1, _a2...) @@ -50,6 +91,10 @@ func (_m *CollectionHelper) FindOne(_a0 context.Context, _a1 interface{}, _a2 .. _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 databases.SingleResultHelper if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) databases.SingleResultHelper); ok { r0 = rf(_a0, _a1, _a2...) @@ -61,3 +106,44 @@ func (_m *CollectionHelper) FindOne(_a0 context.Context, _a1 interface{}, _a2 .. return r0 } + +// InsertOne provides a mock function with given fields: _a0, _a1, _a2 +func (_m *CollectionHelper) InsertOne(_a0 context.Context, _a1 interface{}, _a2 ...*options.InsertOneOptions) databases.InsertOneResultHelper { + _va := make([]interface{}, len(_a2)) + for _i := range _a2 { + _va[_i] = _a2[_i] + } + var _ca []interface{} + _ca = append(_ca, _a0, _a1) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for InsertOne") + } + + var r0 databases.InsertOneResultHelper + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.InsertOneOptions) databases.InsertOneResultHelper); ok { + r0 = rf(_a0, _a1, _a2...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(databases.InsertOneResultHelper) + } + } + + return r0 +} + +// NewCollectionHelper creates a new instance of CollectionHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCollectionHelper(t interface { + mock.TestingT + Cleanup(func()) +}) *CollectionHelper { + mock := &CollectionHelper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/CommunityDatabase.go b/databases/mocks/CommunityDatabase.go index 307c003..a30d651 100644 --- a/databases/mocks/CommunityDatabase.go +++ b/databases/mocks/CommunityDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -19,7 +19,15 @@ type CommunityDatabase struct { func (_m *CommunityDatabase) Find(ctx context.Context, filter interface{}) ([]models.Community, error) { ret := _m.Called(ctx, filter) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.Community + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) ([]models.Community, error)); ok { + return rf(ctx, filter) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}) []models.Community); ok { r0 = rf(ctx, filter) } else { @@ -28,7 +36,6 @@ func (_m *CommunityDatabase) Find(ctx context.Context, filter interface{}) ([]mo } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}) error); ok { r1 = rf(ctx, filter) } else { @@ -42,7 +49,15 @@ func (_m *CommunityDatabase) Find(ctx context.Context, filter interface{}) ([]mo func (_m *CommunityDatabase) FindOne(ctx context.Context, filter interface{}) (*models.Community, error) { ret := _m.Called(ctx, filter) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.Community + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) (*models.Community, error)); ok { + return rf(ctx, filter) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}) *models.Community); ok { r0 = rf(ctx, filter) } else { @@ -51,7 +66,6 @@ func (_m *CommunityDatabase) FindOne(ctx context.Context, filter interface{}) (* } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}) error); ok { r1 = rf(ctx, filter) } else { @@ -60,3 +74,17 @@ func (_m *CommunityDatabase) FindOne(ctx context.Context, filter interface{}) (* return r0, r1 } + +// NewCommunityDatabase creates a new instance of CommunityDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCommunityDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *CommunityDatabase { + mock := &CommunityDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/CursorHelper.go b/databases/mocks/CursorHelper.go index a9a033b..a1e6ef2 100644 --- a/databases/mocks/CursorHelper.go +++ b/databases/mocks/CursorHelper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -13,6 +13,10 @@ type CursorHelper struct { func (_m *CursorHelper) Decode(v interface{}) error { ret := _m.Called(v) + if len(ret) == 0 { + panic("no return value specified for Decode") + } + var r0 error if rf, ok := ret.Get(0).(func(interface{}) error); ok { r0 = rf(v) @@ -22,3 +26,17 @@ func (_m *CursorHelper) Decode(v interface{}) error { return r0 } + +// NewCursorHelper creates a new instance of CursorHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCursorHelper(t interface { + mock.TestingT + Cleanup(func()) +}) *CursorHelper { + mock := &CursorHelper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/DatabaseHelper.go b/databases/mocks/DatabaseHelper.go index ca13c8d..421d0fb 100644 --- a/databases/mocks/DatabaseHelper.go +++ b/databases/mocks/DatabaseHelper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -16,6 +16,10 @@ type DatabaseHelper struct { func (_m *DatabaseHelper) Client() databases.ClientHelper { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for Client") + } + var r0 databases.ClientHelper if rf, ok := ret.Get(0).(func() databases.ClientHelper); ok { r0 = rf() @@ -32,6 +36,10 @@ func (_m *DatabaseHelper) Client() databases.ClientHelper { func (_m *DatabaseHelper) Collection(name string) databases.CollectionHelper { ret := _m.Called(name) + if len(ret) == 0 { + panic("no return value specified for Collection") + } + var r0 databases.CollectionHelper if rf, ok := ret.Get(0).(func(string) databases.CollectionHelper); ok { r0 = rf(name) @@ -43,3 +51,17 @@ func (_m *DatabaseHelper) Collection(name string) databases.CollectionHelper { return r0 } + +// NewDatabaseHelper creates a new instance of DatabaseHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDatabaseHelper(t interface { + mock.TestingT + Cleanup(func()) +}) *DatabaseHelper { + mock := &DatabaseHelper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/EmsDatabase.go b/databases/mocks/EmsDatabase.go index dbad106..a0fb4e0 100644 --- a/databases/mocks/EmsDatabase.go +++ b/databases/mocks/EmsDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -28,7 +28,15 @@ func (_m *EmsDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*option _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.Ems + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.Ems, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.Ems); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -37,7 +45,6 @@ func (_m *EmsDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*option } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -58,7 +65,15 @@ func (_m *EmsDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ...*opt _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.Ems + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.Ems, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.Ems); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -67,7 +82,6 @@ func (_m *EmsDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ...*opt } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -76,3 +90,17 @@ func (_m *EmsDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ...*opt return r0, r1 } + +// NewEmsDatabase creates a new instance of EmsDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewEmsDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *EmsDatabase { + mock := &EmsDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/EmsVehicleDatabase.go b/databases/mocks/EmsVehicleDatabase.go index 1af2c8e..1960566 100644 --- a/databases/mocks/EmsVehicleDatabase.go +++ b/databases/mocks/EmsVehicleDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -28,7 +28,15 @@ func (_m *EmsVehicleDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ... _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.EmsVehicle + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.EmsVehicle, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.EmsVehicle); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -37,7 +45,6 @@ func (_m *EmsVehicleDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ... } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -58,7 +65,15 @@ func (_m *EmsVehicleDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.EmsVehicle + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.EmsVehicle, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.EmsVehicle); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -67,7 +82,6 @@ func (_m *EmsVehicleDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -76,3 +90,17 @@ func (_m *EmsVehicleDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 return r0, r1 } + +// NewEmsVehicleDatabase creates a new instance of EmsVehicleDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewEmsVehicleDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *EmsVehicleDatabase { + mock := &EmsVehicleDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/FirearmDatabase.go b/databases/mocks/FirearmDatabase.go index 9c0536e..e1405c9 100644 --- a/databases/mocks/FirearmDatabase.go +++ b/databases/mocks/FirearmDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -28,7 +28,15 @@ func (_m *FirearmDatabase) Find(ctx context.Context, filter interface{}, opts .. _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.Firearm + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.Firearm, error)); ok { + return rf(ctx, filter, opts...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.Firearm); ok { r0 = rf(ctx, filter, opts...) } else { @@ -37,7 +45,6 @@ func (_m *FirearmDatabase) Find(ctx context.Context, filter interface{}, opts .. } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { r1 = rf(ctx, filter, opts...) } else { @@ -58,7 +65,15 @@ func (_m *FirearmDatabase) FindOne(ctx context.Context, filter interface{}, opts _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.Firearm + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.Firearm, error)); ok { + return rf(ctx, filter, opts...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.Firearm); ok { r0 = rf(ctx, filter, opts...) } else { @@ -67,7 +82,6 @@ func (_m *FirearmDatabase) FindOne(ctx context.Context, filter interface{}, opts } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { r1 = rf(ctx, filter, opts...) } else { @@ -76,3 +90,17 @@ func (_m *FirearmDatabase) FindOne(ctx context.Context, filter interface{}, opts return r0, r1 } + +// NewFirearmDatabase creates a new instance of FirearmDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewFirearmDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *FirearmDatabase { + mock := &FirearmDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/InsertOneResultHelper.go b/databases/mocks/InsertOneResultHelper.go new file mode 100644 index 0000000..5d9ca88 --- /dev/null +++ b/databases/mocks/InsertOneResultHelper.go @@ -0,0 +1,44 @@ +// Code generated by mockery v2.43.2. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// InsertOneResultHelper is an autogenerated mock type for the InsertOneResultHelper type +type InsertOneResultHelper struct { + mock.Mock +} + +// Decode provides a mock function with given fields: +func (_m *InsertOneResultHelper) Decode() interface{} { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Decode") + } + + var r0 interface{} + if rf, ok := ret.Get(0).(func() interface{}); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(interface{}) + } + } + + return r0 +} + +// NewInsertOneResultHelper creates a new instance of InsertOneResultHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewInsertOneResultHelper(t interface { + mock.TestingT + Cleanup(func()) +}) *InsertOneResultHelper { + mock := &InsertOneResultHelper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/LicenseDatabase.go b/databases/mocks/LicenseDatabase.go index a55ac9a..e08b18a 100644 --- a/databases/mocks/LicenseDatabase.go +++ b/databases/mocks/LicenseDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -28,7 +28,15 @@ func (_m *LicenseDatabase) Find(ctx context.Context, filter interface{}, opts .. _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.License + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.License, error)); ok { + return rf(ctx, filter, opts...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.License); ok { r0 = rf(ctx, filter, opts...) } else { @@ -37,7 +45,6 @@ func (_m *LicenseDatabase) Find(ctx context.Context, filter interface{}, opts .. } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { r1 = rf(ctx, filter, opts...) } else { @@ -58,7 +65,15 @@ func (_m *LicenseDatabase) FindOne(ctx context.Context, filter interface{}, opts _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.License + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.License, error)); ok { + return rf(ctx, filter, opts...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.License); ok { r0 = rf(ctx, filter, opts...) } else { @@ -67,7 +82,6 @@ func (_m *LicenseDatabase) FindOne(ctx context.Context, filter interface{}, opts } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { r1 = rf(ctx, filter, opts...) } else { @@ -76,3 +90,17 @@ func (_m *LicenseDatabase) FindOne(ctx context.Context, filter interface{}, opts return r0, r1 } + +// NewLicenseDatabase creates a new instance of LicenseDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLicenseDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *LicenseDatabase { + mock := &LicenseDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/SingleResultHelper.go b/databases/mocks/SingleResultHelper.go index 5fd18b2..b8748f6 100644 --- a/databases/mocks/SingleResultHelper.go +++ b/databases/mocks/SingleResultHelper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -13,6 +13,10 @@ type SingleResultHelper struct { func (_m *SingleResultHelper) Decode(v interface{}) error { ret := _m.Called(v) + if len(ret) == 0 { + panic("no return value specified for Decode") + } + var r0 error if rf, ok := ret.Get(0).(func(interface{}) error); ok { r0 = rf(v) @@ -22,3 +26,17 @@ func (_m *SingleResultHelper) Decode(v interface{}) error { return r0 } + +// NewSingleResultHelper creates a new instance of SingleResultHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewSingleResultHelper(t interface { + mock.TestingT + Cleanup(func()) +}) *SingleResultHelper { + mock := &SingleResultHelper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/SpotlightDatabase.go b/databases/mocks/SpotlightDatabase.go new file mode 100644 index 0000000..4ef3ddb --- /dev/null +++ b/databases/mocks/SpotlightDatabase.go @@ -0,0 +1,126 @@ +// Code generated by mockery v2.43.2. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + models "github.com/linesmerrill/police-cad-api/models" + + options "go.mongodb.org/mongo-driver/mongo/options" +) + +// SpotlightDatabase is an autogenerated mock type for the SpotlightDatabase type +type SpotlightDatabase struct { + mock.Mock +} + +// Find provides a mock function with given fields: _a0, _a1, _a2 +func (_m *SpotlightDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*options.FindOptions) ([]models.Spotlight, error) { + _va := make([]interface{}, len(_a2)) + for _i := range _a2 { + _va[_i] = _a2[_i] + } + var _ca []interface{} + _ca = append(_ca, _a0, _a1) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Find") + } + + var r0 []models.Spotlight + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.Spotlight, error)); ok { + return rf(_a0, _a1, _a2...) + } + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.Spotlight); ok { + r0 = rf(_a0, _a1, _a2...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]models.Spotlight) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { + r1 = rf(_a0, _a1, _a2...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FindOne provides a mock function with given fields: _a0, _a1, _a2 +func (_m *SpotlightDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ...*options.FindOneOptions) (*models.Spotlight, error) { + _va := make([]interface{}, len(_a2)) + for _i := range _a2 { + _va[_i] = _a2[_i] + } + var _ca []interface{} + _ca = append(_ca, _a0, _a1) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + + var r0 *models.Spotlight + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.Spotlight, error)); ok { + return rf(_a0, _a1, _a2...) + } + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.Spotlight); ok { + r0 = rf(_a0, _a1, _a2...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.Spotlight) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { + r1 = rf(_a0, _a1, _a2...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// InsertOne provides a mock function with given fields: _a0, _a1 +func (_m *SpotlightDatabase) InsertOne(_a0 context.Context, _a1 models.SpotlightDetails) interface{} { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for InsertOne") + } + + var r0 interface{} + if rf, ok := ret.Get(0).(func(context.Context, models.SpotlightDetails) interface{}); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(interface{}) + } + } + + return r0 +} + +// NewSpotlightDatabase creates a new instance of SpotlightDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewSpotlightDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *SpotlightDatabase { + mock := &SpotlightDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/UserDatabase.go b/databases/mocks/UserDatabase.go index bcde6df..4c36688 100644 --- a/databases/mocks/UserDatabase.go +++ b/databases/mocks/UserDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -15,11 +15,49 @@ type UserDatabase struct { mock.Mock } +// Aggregate provides a mock function with given fields: ctx, pipeline +func (_m *UserDatabase) Aggregate(ctx context.Context, pipeline interface{}) ([]models.User, error) { + ret := _m.Called(ctx, pipeline) + + if len(ret) == 0 { + panic("no return value specified for Aggregate") + } + + var r0 []models.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) ([]models.User, error)); ok { + return rf(ctx, pipeline) + } + if rf, ok := ret.Get(0).(func(context.Context, interface{}) []models.User); ok { + r0 = rf(ctx, pipeline) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]models.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, interface{}) error); ok { + r1 = rf(ctx, pipeline) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // Find provides a mock function with given fields: ctx, filter func (_m *UserDatabase) Find(ctx context.Context, filter interface{}) ([]models.User, error) { ret := _m.Called(ctx, filter) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) ([]models.User, error)); ok { + return rf(ctx, filter) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}) []models.User); ok { r0 = rf(ctx, filter) } else { @@ -28,7 +66,6 @@ func (_m *UserDatabase) Find(ctx context.Context, filter interface{}) ([]models. } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}) error); ok { r1 = rf(ctx, filter) } else { @@ -42,7 +79,15 @@ func (_m *UserDatabase) Find(ctx context.Context, filter interface{}) ([]models. func (_m *UserDatabase) FindOne(ctx context.Context, filter interface{}) (*models.User, error) { ret := _m.Called(ctx, filter) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) (*models.User, error)); ok { + return rf(ctx, filter) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}) *models.User); ok { r0 = rf(ctx, filter) } else { @@ -51,7 +96,6 @@ func (_m *UserDatabase) FindOne(ctx context.Context, filter interface{}) (*model } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}) error); ok { r1 = rf(ctx, filter) } else { @@ -60,3 +104,37 @@ func (_m *UserDatabase) FindOne(ctx context.Context, filter interface{}) (*model return r0, r1 } + +// InsertOne provides a mock function with given fields: ctx, userDetails +func (_m *UserDatabase) InsertOne(ctx context.Context, userDetails models.UserDetails) interface{} { + ret := _m.Called(ctx, userDetails) + + if len(ret) == 0 { + panic("no return value specified for InsertOne") + } + + var r0 interface{} + if rf, ok := ret.Get(0).(func(context.Context, models.UserDetails) interface{}); ok { + r0 = rf(ctx, userDetails) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(interface{}) + } + } + + return r0 +} + +// NewUserDatabase creates a new instance of UserDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewUserDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *UserDatabase { + mock := &UserDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/VehicleDatabase.go b/databases/mocks/VehicleDatabase.go index 2a30372..463a0eb 100644 --- a/databases/mocks/VehicleDatabase.go +++ b/databases/mocks/VehicleDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -28,7 +28,15 @@ func (_m *VehicleDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*op _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.Vehicle + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.Vehicle, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.Vehicle); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -37,7 +45,6 @@ func (_m *VehicleDatabase) Find(_a0 context.Context, _a1 interface{}, _a2 ...*op } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -58,7 +65,15 @@ func (_m *VehicleDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ... _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.Vehicle + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.Vehicle, error)); ok { + return rf(_a0, _a1, _a2...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.Vehicle); ok { r0 = rf(_a0, _a1, _a2...) } else { @@ -67,7 +82,6 @@ func (_m *VehicleDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ... } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { r1 = rf(_a0, _a1, _a2...) } else { @@ -76,3 +90,17 @@ func (_m *VehicleDatabase) FindOne(_a0 context.Context, _a1 interface{}, _a2 ... return r0, r1 } + +// NewVehicleDatabase creates a new instance of VehicleDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewVehicleDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *VehicleDatabase { + mock := &VehicleDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/mocks/WarrantDatabase.go b/databases/mocks/WarrantDatabase.go index 2cf092f..c39af16 100644 --- a/databases/mocks/WarrantDatabase.go +++ b/databases/mocks/WarrantDatabase.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks @@ -28,7 +28,15 @@ func (_m *WarrantDatabase) Find(ctx context.Context, filter interface{}, opts .. _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for Find") + } + var r0 []models.Warrant + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) ([]models.Warrant, error)); ok { + return rf(ctx, filter, opts...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOptions) []models.Warrant); ok { r0 = rf(ctx, filter, opts...) } else { @@ -37,7 +45,6 @@ func (_m *WarrantDatabase) Find(ctx context.Context, filter interface{}, opts .. } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOptions) error); ok { r1 = rf(ctx, filter, opts...) } else { @@ -58,7 +65,15 @@ func (_m *WarrantDatabase) FindOne(ctx context.Context, filter interface{}, opts _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *models.Warrant + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) (*models.Warrant, error)); ok { + return rf(ctx, filter, opts...) + } if rf, ok := ret.Get(0).(func(context.Context, interface{}, ...*options.FindOneOptions) *models.Warrant); ok { r0 = rf(ctx, filter, opts...) } else { @@ -67,7 +82,6 @@ func (_m *WarrantDatabase) FindOne(ctx context.Context, filter interface{}, opts } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interface{}, ...*options.FindOneOptions) error); ok { r1 = rf(ctx, filter, opts...) } else { @@ -76,3 +90,17 @@ func (_m *WarrantDatabase) FindOne(ctx context.Context, filter interface{}, opts return r0, r1 } + +// NewWarrantDatabase creates a new instance of WarrantDatabase. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewWarrantDatabase(t interface { + mock.TestingT + Cleanup(func()) +}) *WarrantDatabase { + mock := &WarrantDatabase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/databases/spotlight.go b/databases/spotlight.go new file mode 100644 index 0000000..65d47fa --- /dev/null +++ b/databases/spotlight.go @@ -0,0 +1,57 @@ +package databases + +// go generate: mockery --name SpotlightDatabase + +import ( + "context" + + "github.com/linesmerrill/police-cad-api/models" + "go.mongodb.org/mongo-driver/mongo/options" +) + +const spotlightName = "spotlight" + +// SpotlightDatabase contains the methods to use with the spotlight database +type SpotlightDatabase interface { + FindOne(context.Context, interface{}, ...*options.FindOneOptions) (*models.Spotlight, error) + Find(context.Context, interface{}, ...*options.FindOptions) ([]models.Spotlight, error) + InsertOne(context.Context, models.SpotlightDetails) interface{} +} + +type spotlightDatabase struct { + db DatabaseHelper +} + +// NewSpotlightDatabase initializes a new instance of user database with the provided db connection +func NewSpotlightDatabase(db DatabaseHelper) SpotlightDatabase { + return &spotlightDatabase{ + db: db, + } +} + +func (s *spotlightDatabase) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (*models.Spotlight, error) { + spotlight := &models.Spotlight{} + err := s.db.Collection(spotlightName).FindOne(ctx, filter, opts...).Decode(&spotlight) + if err != nil { + return nil, err + } + return spotlight, nil +} + +func (s *spotlightDatabase) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) ([]models.Spotlight, error) { + var spotlight []models.Spotlight + err := s.db.Collection(spotlightName).Find(ctx, filter, opts...).Decode(&spotlight) + if err != nil { + return nil, err + } + return spotlight, nil +} + +func (s *spotlightDatabase) InsertOne(ctx context.Context, spotlightDetails models.SpotlightDetails) interface{} { + type spot struct { + Spotlight models.SpotlightDetails `bson:"spotlight"` + } + spots := spot{Spotlight: spotlightDetails} + res := s.db.Collection(spotlightName).InsertOne(ctx, spots) + return res +} diff --git a/databases/spotlight_test.go b/databases/spotlight_test.go new file mode 100644 index 0000000..18cbec7 --- /dev/null +++ b/databases/spotlight_test.go @@ -0,0 +1 @@ +package databases diff --git a/databases/user.go b/databases/user.go index 63fe436..5c6aabc 100644 --- a/databases/user.go +++ b/databases/user.go @@ -14,6 +14,8 @@ const userName = "users" type UserDatabase interface { FindOne(ctx context.Context, filter interface{}) (*models.User, error) Find(ctx context.Context, filter interface{}) ([]models.User, error) + InsertOne(ctx context.Context, userDetails models.UserDetails) interface{} + Aggregate(ctx context.Context, pipeline interface{}) ([]models.User, error) } type userDatabase struct { @@ -44,3 +46,24 @@ func (u *userDatabase) Find(ctx context.Context, filter interface{}) ([]models.U } return users, nil } + +func (u *userDatabase) InsertOne(ctx context.Context, userDetails models.UserDetails) interface{} { + type user struct { + User models.UserDetails `bson:"user"` + } + users := user{User: userDetails} + res := u.db.Collection(userName).InsertOne(ctx, users) + return res +} + +func (u *userDatabase) Aggregate(ctx context.Context, pipeline interface{}) ([]models.User, error) { + var users []models.User + cursor, err := u.db.Collection(userName).Aggregate(ctx, pipeline) + if err != nil { + return nil, err + } + if err = cursor.Decode(&users); err != nil { + return nil, err + } + return users, nil +} diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0f76ab8..223b04a 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -498,6 +498,9 @@ definitions: password: type: string x-go-name: Password + profilePicture: + type: string + x-go-name: ProfilePicture resetPasswordExpires: type: object x-go-name: ResetPasswordExpires diff --git a/go.mod b/go.mod index 6fcb34c..ef517d6 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,15 @@ module github.com/linesmerrill/police-cad-api -go 1.17 +go 1.22 require ( - github.com/form3tech-oss/jwt-go v3.2.5+incompatible + github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.0 + github.com/shaj13/go-guardian v1.5.11 github.com/stretchr/testify v1.7.1 go.mongodb.org/mongo-driver v1.8.4 go.uber.org/zap v1.21.0 + golang.org/x/crypto v0.23.0 ) require ( @@ -24,9 +26,8 @@ require ( github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect - golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/text v0.3.5 // indirect + golang.org/x/text v0.15.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 7fe70b3..6e0b5c0 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,50 @@ +github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= +github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/form3tech-oss/jwt-go v3.2.5+incompatible h1:/l4kBbb4/vGSsdtB5nUe8L7B9mImVMaBPw9L/0TBHU8= -github.com/form3tech-oss/jwt-go v3.2.5+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= +github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= +github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= +github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= +github.com/evanphx/json-patch v0.0.0-20200808040245-162e5629780b/go.mod h1:NAJj0yf/KaRKURN6nyi7A9IZydMivZEm9oQLWNjfKDc= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= +github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= +github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= +github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= +github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= +github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -20,15 +52,33 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/shaj13/go-guardian v1.5.11 h1:GRoMBgh5stRh86iAkEOj7UqcodIs6E7pZ+LtOnxTUGk= +github.com/shaj13/go-guardian v1.5.11/go.mod h1:Y4LLKzIAVAZlpr4tZCRvk+pkyZUwgsjZL86PZIzAH8g= +github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= @@ -56,31 +106,44 @@ go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f h1:aZp0e2vLN4MToVqnjNEYEtrEA8RH8U8FN1CU7JgqsPU= golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -90,11 +153,28 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/ldap.v3 v3.1.0/go.mod h1:dQjCc0R0kfyFjIlWNMH1DORwUASZyDxo2Ry1B51dXaQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +k8s.io/api v0.18.8/go.mod h1:d/CXqwWv+Z2XEG1LgceeDmHQwpUJhROPx16SlxJgERY= +k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig= +k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= +k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= +k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E= +sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw= +sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= +sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/models/spotlight.go b/models/spotlight.go new file mode 100644 index 0000000..6086a4b --- /dev/null +++ b/models/spotlight.go @@ -0,0 +1,17 @@ +package models + +// Spotlight holds the structure for the spotlight collection in mongo +type Spotlight struct { + ID string `json:"_id" bson:"_id"` + Details SpotlightDetails `json:"spotlight" bson:"spotlight"` + Version int32 `json:"__v" bson:"__v"` +} + +// SpotlightDetails holds the structure for the inner spotlight structure as defined in the spotlight collection in mongo +type SpotlightDetails struct { + Image string `json:"image" bson:"image"` + Title string `json:"title" bson:"title"` + Time string `json:"time" bson:"time"` + CreatedAt interface{} `json:"createdAt" bson:"createdAt"` + UpdatedAt interface{} `json:"updatedAt" bson:"updatedAt"` +} diff --git a/models/user.go b/models/user.go index a860f50..6f85b8a 100644 --- a/models/user.go +++ b/models/user.go @@ -18,6 +18,7 @@ type UserDetails struct { Name string `json:"name" bson:"name"` Username string `json:"username" bson:"username"` Password string `json:"password" bson:"password"` + ProfilePicture string `json:"profilePicture" bson:"profilePicture"` ResetPasswordToken string `json:"resetPasswordToken" bson:"resetPasswordToken"` ResetPasswordExpires interface{} `json:"resetPasswordExpires" bson:"resetPasswordExpires"` CreatedAt interface{} `json:"createdAt" bson:"createdAt"`