Upstream sync
This commit is contained in:
62
application/applicationservice/passwordresetservice.go
Normal file
62
application/applicationservice/passwordresetservice.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package applicationservice
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/entitymapping"
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/service"
|
||||
)
|
||||
|
||||
// zipcodeService holds methods to participating zipcode application service
|
||||
type passwordResetService struct {
|
||||
svc *service.Service
|
||||
mapEntity *entitymapping.Mapper
|
||||
}
|
||||
|
||||
// newZipcodeService returns a zipcodeService instance
|
||||
func newPasswordResetService(svc *service.Service, mapper *entitymapping.Mapper) *passwordResetService {
|
||||
return &passwordResetService{
|
||||
svc: svc,
|
||||
mapEntity: mapper,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *passwordResetService) GetAll() ([]viewmodel.PasswordReset, error) {
|
||||
result, err := s.svc.PasswordReset.GetAll()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.mapEntity.PasswordReset.ToPasswordResetModelSlice(result), nil
|
||||
}
|
||||
|
||||
func (s *passwordResetService) CreatePasswordResetEntry(passwordResetEntry viewmodel.PasswordReset) (viewmodel.PasswordReset, error) {
|
||||
passwordResetEntity := s.mapEntity.PasswordReset.ToPasswordResetEntity(passwordResetEntry)
|
||||
result, err := s.svc.PasswordReset.CreatePasswordResetEntry(passwordResetEntity)
|
||||
if err != nil {
|
||||
return viewmodel.PasswordReset{}, err
|
||||
}
|
||||
return s.mapEntity.PasswordReset.ToPasswordResetModel(result), nil
|
||||
}
|
||||
|
||||
func (s *passwordResetService) GetByID(ID int64) (viewmodel.PasswordReset, error) {
|
||||
result, err := s.svc.PasswordReset.GetByID(ID)
|
||||
if err != nil {
|
||||
return viewmodel.PasswordReset{}, err
|
||||
}
|
||||
return s.mapEntity.PasswordReset.ToPasswordResetModel(result), nil
|
||||
}
|
||||
|
||||
func (s *passwordResetService) GetByToken(token string) (viewmodel.PasswordReset, error) {
|
||||
result, err := s.svc.PasswordReset.GetByToken(token)
|
||||
if err != nil {
|
||||
return viewmodel.PasswordReset{}, err
|
||||
}
|
||||
return s.mapEntity.PasswordReset.ToPasswordResetModel(result), nil
|
||||
}
|
||||
|
||||
func (s *passwordResetService) SetTokenOpened(token string) error {
|
||||
return s.svc.PasswordReset.SetTokenOpened(token)
|
||||
}
|
||||
|
||||
func (s *passwordResetService) SetTokenUsed(token string) error {
|
||||
return s.svc.PasswordReset.SetTokenUsed(token)
|
||||
}
|
||||
59
application/entitymapping/passwordreset.go
Normal file
59
application/entitymapping/passwordreset.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package entitymapping
|
||||
|
||||
import (
|
||||
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
|
||||
"bitbucket.org/nemt/nemt-portal-api/domain/entity"
|
||||
)
|
||||
|
||||
// zipcodeMapping has method to map zipcode entities to view models
|
||||
type passwordResetMapping struct {
|
||||
mapper *Mapper
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *passwordResetMapping) ToPasswordResetEntitySlice(list []viewmodel.PasswordReset) (retVal []entity.PasswordReset) {
|
||||
retVal = make([]entity.PasswordReset, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToPasswordResetEntity(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *passwordResetMapping) ToPasswordResetEntity(model viewmodel.PasswordReset) entity.PasswordReset {
|
||||
return entity.PasswordReset{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
User: mapping.mapper.User.ToUserEntity(model.User),
|
||||
Token: model.Token,
|
||||
Created: model.Created,
|
||||
Expires: model.Expires,
|
||||
Used: model.Used,
|
||||
Opened: model.Opened,
|
||||
}
|
||||
}
|
||||
|
||||
// ToUserEntitySlice maps a User entity slice to User view model slice
|
||||
func (mapping *passwordResetMapping) ToPasswordResetModelSlice(list []entity.PasswordReset) (retVal []viewmodel.PasswordReset) {
|
||||
retVal = make([]viewmodel.PasswordReset, 0)
|
||||
|
||||
for _, item := range list {
|
||||
retVal = append(retVal, mapping.ToPasswordResetModel(item))
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (mapping *passwordResetMapping) ToPasswordResetModel(model entity.PasswordReset) viewmodel.PasswordReset {
|
||||
return viewmodel.PasswordReset{
|
||||
ID: model.ID,
|
||||
UUID: model.UUID,
|
||||
User: mapping.mapper.User.ToUserModel(model.User),
|
||||
Token: model.Token,
|
||||
Created: model.Created,
|
||||
Expires: model.Expires,
|
||||
Used: model.Used,
|
||||
Opened: model.Opened,
|
||||
}
|
||||
}
|
||||
14
application/viewmodel/passwordreset.go
Normal file
14
application/viewmodel/passwordreset.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package viewmodel
|
||||
|
||||
import "time"
|
||||
|
||||
type PasswordReset struct {
|
||||
ID int64 `json:"-"`
|
||||
UUID string `json:"uuid"`
|
||||
User User `json:"user"`
|
||||
Token string `json:"token"`
|
||||
Created time.Time `json:"create_date"`
|
||||
Expires time.Time `json:"expire_date"`
|
||||
Used bool `json:"used"`
|
||||
Opened bool `json:"opened"`
|
||||
}
|
||||
Reference in New Issue
Block a user