added comments
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// ChangePassword handles changing a user's password by decoding a request, validating input, hashing the password, and updating the database.
|
||||
func (s Service) ChangePassword(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
var req Password
|
||||
|
@ -4,16 +4,19 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Service Represents a service with a database connection.
|
||||
type Service struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// Service - Creates a new Service instance, initializing it with a GORM database connection.
|
||||
func New(db *gorm.DB) *Service {
|
||||
return &Service{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
// Password struct represents a user's password with a JSON tag.
|
||||
type Password struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// GetUsers retrieves all users from the database and returns them as a JSON response.
|
||||
func (s *Service) GetUsers(w http.ResponseWriter, r *http.Request) {
|
||||
var users []model.User
|
||||
|
||||
@ -32,6 +33,7 @@ func (s *Service) GetUsers(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(res)
|
||||
}
|
||||
|
||||
// SetUserRole handles updating a user's role based on a UUID from the request.
|
||||
func (s *Service) SetUserRole(w http.ResponseWriter, r *http.Request) {
|
||||
var role model.Role
|
||||
userUUIDstr, ok := mux.Vars(r)["userUUID"]
|
||||
@ -63,6 +65,7 @@ func (s *Service) SetUserRole(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// DeleteUser handles the deletion of a user from the database, enforcing authorization checks.
|
||||
func (s *Service) DeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
claims, ok := auth.ExtractClaims(r.Context())
|
||||
if !ok {
|
||||
|
Reference in New Issue
Block a user