Documentation
¶
Overview ¶
Package Name: users File Name: users.go Abstract: Wrapper for exposing to fx all the components of the 'users' context.
Author: Alejandro Modroño <[email protected]> Created: 07/08/2023 Last Updated: 07/24/2023
MIT License ¶
Copyright 2023 Alejandro Modroño Vara ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Package Name: users File Name: users_controller.go Abstract: The user controller for performing operations after a route is called.
Author: Alejandro Modroño <[email protected]> Created: 07/08/2023 Last Updated: 07/24/2023
MIT License ¶
Copyright 2023 Alejandro Modroño Vara ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Package Name: users File Name: users_controller.go Abstract: A representation of a user in the database.
Author: Alejandro Modroño <[email protected]> Created: 07/08/2023 Last Updated: 07/24/2023
MIT License ¶
Copyright 2023 Alejandro Modroño Vara ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Package Name: users File Name: users_repository.go Abstract: Interface for the UsersService used for avoiding import/dependency cycles and allowing to mock these services in tests. Author: Alejandro Modroño <[email protected]> Created: 07/26/2023 Last Updated: 07/26/2023
MIT License ¶
Copyright 2023 Alejandro Modroño Vara ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Package Name: users File Name: users_routes.go Abstract: The file containing all the user routes.
Author: Alejandro Modroño <[email protected]> Created: 07/08/2023 Last Updated: 07/24/2023
MIT License ¶
Copyright 2023 Alejandro Modroño Vara ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Package Name: users File Name: users_service.go Abstract: The user service for performing operations upon users in the database.
Author: Alejandro Modroño <[email protected]> Created: 07/08/2023 Last Updated: 07/24/2023
MIT License ¶
Copyright 2023 Alejandro Modroño Vara ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Variables
- type InternalUser
- type PublicUser
- type UsersController
- type UsersRepository
- type UsersRoutes
- type UsersService
- func (service UsersService) CreateUser(email string, username string, password string) (*int32, error)
- func (service UsersService) GetUserByEmail(email string) (*InternalUser, error)
- func (service UsersService) GetUserById(id int) (*InternalUser, error)
- func (service UsersService) GetUsers() (users []InternalUser, err error)
Constants ¶
This section is empty.
Variables ¶
var Context = fx.Options( fx.Provide(GetUsersController), fx.Provide(GetUsersService), fx.Provide(SetUsersRoutes), )
Module exports services present
Functions ¶
This section is empty.
Types ¶
type InternalUser ¶
type InternalUser struct { ID int32 Username string Email string Password string CreatedAt time.Time }
InternalUser is a struct that represents a user, and it contains its password. As its own name suggests, this type should only be used internally.
func InternalUserFromData ¶
func InternalUserFromData(values []interface{}) InternalUser
Creates a new instance of an internal user from data.
func (InternalUser) ToPublic ¶
func (self InternalUser) ToPublic() PublicUser
Converts an internal user to a public user.
type PublicUser ¶
type PublicUser struct { ID int32 `json:"id"` Username string `json:"username"` Email string `json:"email"` CreatedAt time.Time `json:"created_at"` }
PublicUser is basically a user that will be returned by the api. As its own name says, it should be used for returning user data publicly.
type UsersController ¶
type UsersController struct {
// contains filtered or unexported fields
}
UsersController data type
func GetUsersController ¶
func GetUsersController(logger lib.Logger, service UsersRepository) UsersController
Creates a new user controller and exposes its routes to the router.
func (UsersController) Get ¶
func (controller UsersController) Get(ctx *gin.Context)
func (UsersController) GetAll ¶
func (controller UsersController) GetAll(ctx *gin.Context)
type UsersRepository ¶
type UsersRepository interface { GetUserById(id int) (*InternalUser, error) GetUserByEmail(email string) (*InternalUser, error) GetUsers() (users []InternalUser, err error) CreateUser(email string, username string, password string) (*int32, error) }
The interface for the AuthService.
func GetUsersService ¶
func GetUsersService(logger lib.Logger, db *lib.Database) UsersRepository
GetUsersService returns the user service.
type UsersRoutes ¶
type UsersRoutes struct {
// contains filtered or unexported fields
}
UsersRoutes struct
func SetUsersRoutes ¶
func SetUsersRoutes( logger lib.Logger, router *lib.Router, usersController UsersController, authMiddleware middlewares.AuthMiddleware, ) UsersRoutes
Returns a UserRoutes struct.
type UsersService ¶
type UsersService struct {
// contains filtered or unexported fields
}
UsersService service layer
func (UsersService) CreateUser ¶
func (service UsersService) CreateUser(email string, username string, password string) (*int32, error)
CreateUser inserts a new user in the database
func (UsersService) GetUserByEmail ¶
func (service UsersService) GetUserByEmail(email string) (*InternalUser, error)
GetUserByEmail returns a single user with the specified email.
NOTE: This query returns the user with its hashed password, so make sure to convert its value to a models.PublicUser struct which omits the password.
func (UsersService) GetUserById ¶
func (service UsersService) GetUserById(id int) (*InternalUser, error)
GetUserById returns a single user with the specified id.
NOTE: This query returns the user with its hashed password, so make sure to convert its value to a models.PublicUser struct which omits the password.
func (UsersService) GetUsers ¶
func (service UsersService) GetUsers() (users []InternalUser, err error)
GetUsers returns all the users