zitadel/internal/api/grpc/object/converter.go
Fabi 6b1f7ba333
fix: some backend bugs (#1438)
* fix: fix setup

* fix oidc app change

* fix: fix migration and proto

* fix: fix granted projects

* setup1 apis instead of apps

* fix: add object detail with creation date

* fix user phone change

* add localizer to AddOIDCAppResponse

* fix test

* fix domain test

* fix: converter

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2021-03-19 18:46:26 +01:00

108 lines
3.0 KiB
Go

package object
import (
"time"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/pkg/grpc/object"
object_pb "github.com/caos/zitadel/pkg/grpc/object"
)
func DomainToChangeDetailsPb(objectDetail *domain.ObjectDetails) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
Sequence: objectDetail.Sequence,
ChangeDate: timestamppb.New(objectDetail.EventDate),
ResourceOwner: objectDetail.ResourceOwner,
}
}
func DomainToAddDetailsPb(objectDetail *domain.ObjectDetails) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
Sequence: objectDetail.Sequence,
CreationDate: timestamppb.New(objectDetail.EventDate),
ResourceOwner: objectDetail.ResourceOwner,
}
}
func ToViewDetailsPb(
sequence uint64,
creationDate,
changeDate time.Time,
resourceOwner string,
) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
Sequence: sequence,
CreationDate: timestamppb.New(creationDate),
ChangeDate: timestamppb.New(changeDate),
ResourceOwner: resourceOwner,
}
}
func ChangeToDetailsPb(
sequence uint64,
changeDate time.Time,
resourceOwner string,
) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
Sequence: sequence,
ChangeDate: timestamppb.New(changeDate),
ResourceOwner: resourceOwner,
}
}
func AddToDetailsPb(
sequence uint64,
creationDate time.Time,
resourceOwner string,
) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
Sequence: sequence,
CreationDate: timestamppb.New(creationDate),
ResourceOwner: resourceOwner,
}
}
func ToListDetails(
totalResult,
processedSequence uint64,
viewTimestamp time.Time,
) *object.ListDetails {
return &object_pb.ListDetails{
TotalResult: totalResult,
ProcessedSequence: processedSequence,
ViewTimestamp: timestamppb.New(viewTimestamp),
}
}
func TextMethodToModel(method object_pb.TextQueryMethod) domain.SearchMethod {
switch method {
case object.TextQueryMethod_TEXT_QUERY_METHOD_EQUALS:
return domain.SearchMethodEquals
case object.TextQueryMethod_TEXT_QUERY_METHOD_EQUALS_IGNORE_CASE:
return domain.SearchMethodEqualsIgnoreCase
case object.TextQueryMethod_TEXT_QUERY_METHOD_STARTS_WITH:
return domain.SearchMethodStartsWith
case object.TextQueryMethod_TEXT_QUERY_METHOD_STARTS_WITH_IGNORE_CASE:
return domain.SearchMethodStartsWithIgnoreCase
case object.TextQueryMethod_TEXT_QUERY_METHOD_CONTAINS:
return domain.SearchMethodContains
case object.TextQueryMethod_TEXT_QUERY_METHOD_CONTAINS_IGNORE_CASE:
return domain.SearchMethodContainsIgnoreCase
case object.TextQueryMethod_TEXT_QUERY_METHOD_ENDS_WITH:
return domain.SearchMethodEndsWith
case object.TextQueryMethod_TEXT_QUERY_METHOD_ENDS_WITH_IGNORE_CASE:
return domain.SearchMethodEndsWithIgnoreCase
default:
return -1
}
}
func ListQueryToModel(query *object_pb.ListQuery) (offset, limit uint64, asc bool) {
if query == nil {
return
}
return query.Offset, uint64(query.Limit), query.Asc
}