This commit is contained in:
Alex Shevchuk
2025-08-18 17:12:04 +03:00
commit d84487d238
157 changed files with 160686 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
package requestmodel
import (
"fmt"
dbtypes "git-molva.ru/Molva/molva-backend/services/api_gateway/internal/database/types"
)
type (
Profile struct {
Id string `json:"id"`
Name string `json:"name"`
PhoneNumber string `json:"phone_number"`
Email string `json:"email"`
}
)
func (p *Profile) From(msg *dbtypes.Profile) *Profile {
if msg == nil {
return nil
}
res := &Profile{
Id: msg.Id,
Name: msg.Name,
PhoneNumber: msg.PhoneNumber,
Email: msg.Email,
}
return res
}
type (
ProfileGetRequest struct {
Id string `json:"id"`
}
ProfileGetResponse struct {
Profile *Profile `json:"profile"`
}
)
func (r *ProfileGetRequest) Validate() error {
if r == nil {
return fmt.Errorf("%w: request is nil", ErrValidation)
}
if r.Id == "" {
return fmt.Errorf("%w: ID is required", ErrValidation)
}
return nil
}
func (r *ProfileGetResponse) From(msg *dbtypes.ProfileGetResponse) *ProfileGetResponse {
if msg == nil {
return nil
}
return &ProfileGetResponse{
Profile: new(Profile).From(msg.Profile),
}
}
type (
ProfileUpdateRequest struct {
Id string
Name *string `json:"name"`
PhoneNumber *string `json:"phone_number"`
Email *string `json:"email"`
}
ProfileUpdateResponse struct{}
)
func (r *ProfileUpdateRequest) Validate() error {
if r == nil {
return fmt.Errorf("%w: request is nil", ErrValidation)
}
if r.Id == "" {
return fmt.Errorf("%w: ID is required", ErrValidation)
}
if r.Name == nil && r.PhoneNumber == nil && r.Email == nil {
return fmt.Errorf("%w: nothing to update", ErrValidation)
}
return nil
}