You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need to create a new file, userwithpassword.go, in the pkg/presentation/dto directory. This file will contain the UserWithPassword struct which serves as a Data Transfer Object (DTO) combining user details with password information. This struct will facilitate the handling of user and password data together, particularly useful for processes that involve both user information and authentication details.
Path of the file to be created
pkg/presentation/dto/userwithpassword.go
Code Overview
package presentation
import (
"fmt"
pb "github.com/octoposprime/op-be-shared/pkg/proto/pb/user"
tuuid "github.com/octoposprime/op-be-shared/tool/uuid"
me "github.com/octoposprime/op-be-user/internal/domain/model/entity"
mo "github.com/octoposprime/op-be-user/internal/domain/model/object""google.golang.org/protobuf/types/known/timestamppb"
)
// UserWithPassword is a struct that represents the dto of a user with password values.typeUserWithPasswordstruct {
proto*pb.UserWithPassword
}
// NewUserWithPassword creates a new *UserWithPassword.funcNewUserWithPassword(pb*pb.UserWithPassword) *UserWithPassword {
return&UserWithPassword{
proto: pb,
}
}
// String returns a string representation of the UserWithPassword.func (s*UserWithPassword) String() string {
returnfmt.Sprintf(
"User: %v, "+"Password: %v",
s.proto.User,
"***",
)
}
funcNewUserWithPasswordFromEntity(entity me.User) *UserWithPassword {
return&UserWithPassword{
&pb.UserWithPassword{
User: &pb.User{
Id: entity.Id.String(),
Username: entity.UserName,
Email: entity.Email,
Role: entity.Role,
UserType: pb.UserType(entity.UserType),
UserStatus: pb.UserStatus(entity.UserStatus),
FirstName: entity.FirstName,
LastName: entity.LastName,
CreatedAt: timestamppb.New(entity.CreatedAt), // Not sure if this needs to be convertedUpdatedAt: timestamppb.New(entity.UpdatedAt), // Not sure if this needs to be converted
},
},
}
}
// ToPb returns a protobuf representation of the UserWithPassword.func (s*UserWithPassword) ToPb() *pb.UserWithPassword {
returns.proto
}
// ToEntity returns a entity representation of the UserWithPassword.func (s*UserWithPassword) ToEntity() (*me.User, *me.UserPassword) {
return&me.User{
Id: tuuid.FromString(s.proto.User.Id),
User: mo.User{
UserName: s.proto.User.Username,
Email: s.proto.User.Email,
Role: s.proto.User.Role,
UserType: mo.UserType(s.proto.User.UserType),
UserStatus: mo.UserStatus(s.proto.User.UserStatus),
Tags: s.proto.User.Tags,
FirstName: s.proto.User.FirstName,
LastName: s.proto.User.LastName,
},
CreatedAt: s.proto.User.CreatedAt.AsTime(), // Not sure if this needs to be convertedUpdatedAt: s.proto.User.UpdatedAt.AsTime(), // Not sure if this needs to be converted
}, &me.UserPassword{
Id: tuuid.FromString(s.proto.UserPassword.Id),
UserId: tuuid.FromString(s.proto.UserPassword.UserId),
UserPassword: mo.UserPassword{
Password: s.proto.UserPassword.Password,
PasswordStatus: mo.PasswordStatus(s.proto.UserPassword.PasswordStatus),
},
}
}
typeUserWithPasswords []*UserWithPassword// NewUserWithPasswordsFromEntities creates a new []*UserWithPassword from entities.funcNewUserWithPasswordsFromEntities(entities []me.User) UserWithPasswords {
userWithPasswords:=make([]*UserWithPassword, len(entities))
fori, entity:=rangeentities {
userWithPasswords[i] =NewUserWithPasswordFromEntity(entity)
}
returnuserWithPasswords
}
// NewEmptyUserWithPassword creates a new *UserWithPassword with empty values.funcNewEmptyUserWithPassword() *UserWithPassword {
return&UserWithPassword{
&pb.UserWithPassword{
User: &pb.User{
Id: "",
Username: "",
Email: "",
Role: "",
UserType: pb.UserType_UserTypeNONE,
UserStatus: pb.UserStatus_UserStatusNONE,
Tags: []string{},
FirstName: "",
LastName: "",
CreatedAt: timestamppb.Now(), // Not sure if this needs to be convertedUpdatedAt: timestamppb.Now(), // Not sure if this needs to be converted
},
UserPassword: &pb.UserPassword{
Id: "",
UserId: "",
Password: "",
PasswordStatus: pb.PasswordStatus_PasswordStatusNONE,
},
},
}
}
// ToPbs returns a protobuf representation of the UserWithPasswordsfunc (sUserWithPasswords) ToPbs() []*pb.UserWithPassword {
userWithPasswords:=make([]*pb.UserWithPassword, len(s))
fori, userWithPassword:=ranges {
userWithPasswords[i] =userWithPassword.proto
}
returnuserWithPasswords
}
The changes will be merged into the enhance/team/66/implement-password-validation branch first. Therefore, set the base branch of the pull request as enhance/team/66/implement-password-validation.
The text was updated successfully, but these errors were encountered:
We need to create a new file,
userwithpassword.go
, in thepkg/presentation/dto
directory. This file will contain theUserWithPassword
struct which serves as a Data Transfer Object (DTO) combining user details with password information. This struct will facilitate the handling of user and password data together, particularly useful for processes that involve both user information and authentication details.Path of the file to be created
pkg/presentation/dto/userwithpassword.go
Code Overview
The changes will be merged into the
enhance/team/66/implement-password-validation
branch first. Therefore, set the base branch of the pull request asenhance/team/66/implement-password-validation
.The text was updated successfully, but these errors were encountered: