Add method specification document

This commit is contained in:
sunboyy 2021-02-07 12:51:51 +07:00
parent 8b19829a3c
commit 9b04e89697
4 changed files with 237 additions and 138 deletions
examples/getting-started

View file

@ -18,25 +18,25 @@ type UserModel struct {
// UserRepository is an interface that describes the specification of querying user data in the database
type UserRepository interface {
// InsertOne stores userModel into the database and returns inserted ID if insertion succeeds
// and returns error if insertion fails.
// InsertOne stores userModel into the database and returns inserted ID if insertion
// succeeds and returns error if insertion fails.
InsertOne(ctx context.Context, userModel *UserModel) (interface{}, error)
// FindByUsername queries user by username. If a user with specified username exists, the user will be
// returned. If no user exists or error occurs while querying, error will be returned.
// FindByUsername queries user by username. If a user with specified username exists,
// the user will be returned. Otherwise, error will be returned.
FindByUsername(ctx context.Context, username string) (*UserModel, error)
// UpdateDisplayNameByID updates a user with the specified ID with a new display name. If there is a user
// matches the query, it will return true. Error will be returned only when error occurs while accessing
// the database. This is a ONE mode because the first return type is a boolean.
// UpdateDisplayNameByID updates a user with the specified ID with a new display name.
// If there is a user matches the query, it will return true. Error will be returned
// only when error occurs while accessing the database.
UpdateDisplayNameByID(ctx context.Context, displayName string, id primitive.ObjectID) (bool, error)
// DeleteByCity deletes users that have `city` value match the parameter and returns the match count.
// The error will be returned only when error occurs while accessing the database. This is a MANY mode
// because the first return type is an integer.
// DeleteByCity deletes users that have `city` value match the parameter and returns
// the match count. The error will be returned only when error occurs while accessing
// the database. This is a MANY mode because the first return type is an integer.
DeleteByCity(ctx context.Context, city string) (int, error)
// CountByCity returns the number of rows that match the given city parameter. If an error occurs while
// accessing the database, error value will be returned.
// CountByCity returns the number of rows that match the given city parameter. If an
// error occurs while accessing the database, error value will be returned.
CountByCity(ctx context.Context, city string) (int, error)
}