-
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 #12 from 0x-buidl/fix/find_many_results_with_nil_c…
…ollections fix: find many results comes with nil collection
- Loading branch information
Showing
11 changed files
with
228 additions
and
167 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
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,28 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/0x-buidl/mgs" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
type Author struct { | ||
Name string `json:"name" bson:"name"` | ||
Deleted bool `json:"-" bson:"deleted"` | ||
DeletedAt *time.Time `json:"-" bson:"deletedAt"` | ||
} | ||
|
||
type ( | ||
AuthorModel = mgs.Model[Author, *mgs.DefaultSchema] | ||
AuthorDoc = mgs.Document[Author, *mgs.DefaultSchema] | ||
) | ||
|
||
func NewAuthorModel(coll *mongo.Collection) *AuthorModel { | ||
return mgs.NewModel[Author, *mgs.DefaultSchema](coll) | ||
} | ||
|
||
func (a Author) Validate(ctx context.Context, arg *mgs.HookArg[Author]) error { | ||
return nil | ||
} |
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,28 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/0x-buidl/mgs" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
type Review struct { | ||
// ObjectID or Book object | ||
Book interface{} `bson:"book" json:"book" validate:"required"` | ||
Comment string `bson:"comment" json:"comment" validate:"required"` | ||
Rating int `bson:"rating" json:"rating" validate:"required"` | ||
} | ||
|
||
type ( | ||
ReviewModel = mgs.Model[Review, *mgs.DefaultSchema] | ||
ReviewDoc = mgs.Document[Review, *mgs.DefaultSchema] | ||
) | ||
|
||
func NewReviewModel(coll *mongo.Collection) *ReviewModel { | ||
return mgs.NewModel[Review, *mgs.DefaultSchema](coll) | ||
} | ||
|
||
func (r Review) Validate(ctx context.Context, arg *mgs.HookArg[Review]) error { | ||
return nil | ||
} |
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
Oops, something went wrong.