convert.go 1.77 KB
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
package handler

import (
	"google.golang.org/protobuf/types/known/timestamppb"
	"hilo/api/service/user"
	"hilo/app/service/user/internal/model"
)

func ProtoToUser(src *user.MUser) *model.User {
	return &model.User{
		Avatar:        src.Avatar,
		Birthday:      src.Birthday,
		Code:          src.Code,
		Country:       src.Country,
		CountryIcon:   src.CountryIcon,
		DefaultAvatar: int(src.DefaultAvatar),
		Description:   src.Description,
		DeviceType:    src.DeviceType,
		ExternalId:    src.ExternalId,
		IsPush:        int(src.IsPush),
		IsShowAge:     int(src.IsShowAge),
		Language:      src.Language,
		LogoutTime:    src.LogoutTime,
		Nick:          src.Nick,
		OriginCode:    src.OriginCode,
		Sex:           int(src.Sex),
		Status:        int8(src.Status),
	}
}

func UserToProto(src *model.User) *user.MUser {
	return &user.MUser{
		Avatar:        src.Avatar,
		Birthday:      src.Birthday,
		Code:          src.Code,
		Country:       src.Country,
		CountryIcon:   src.CountryIcon,
		DefaultAvatar: int32(src.DefaultAvatar),
		Description:   src.Description,
		DeviceType:    src.DeviceType,
		ExternalId:    src.ExternalId,
		IsPush:        int32(src.IsPush),
		IsShowAge:     int32(src.IsShowAge),
		Language:      src.Language,
		LogoutTime:    src.LogoutTime,
		Nick:          src.Nick,
		OriginCode:    src.OriginCode,
		Sex:           user.ESex(src.Sex),
		Status:        int32(src.Status),
	}
}

func UserOAuthToProto(src *model.UserOauth) *user.MUserOauth {
	return &user.MUserOauth{
		Id:              src.Id,
		UserId:          src.UserId,
		ThirdPartyId:    src.ThirdPartyId,
		ThirdPartyType:  user.EThirdPartyType(src.ThirdPartyType),
		ThirdPartyToken: src.ThirdPartyToken,
		CreatedTime:     timestamppb.New(src.CreatedTime),
		UpdatedTime:     timestamppb.New(src.UpdatedTime),
	}
}