Created
August 28, 2020 02:48
-
-
Save jhidajat/8a7f32ef88b769ba832a8a64a43176c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *ContentServiceComponent) UpdateSourceRep(req respondAPI.UpdateSourceRepRequest, authSpec AuthenticationSpec) (*respondAPI.UpdateSourceRepResponse, error) { | |
GeneralLogger.Printf("Request Payload for /UpdateSourceRep:\n"+ | |
"{\n"+ | |
"\tSourceId: %v,\n"+ | |
"\tReputation: %v,\n"+ | |
"}", | |
req.SourceId, req.Reputation) | |
now := time.Now().UnixNano() | |
upsertStakeSpec := make([]pb.UpsertStakeSpec, 0) | |
upsertStakeSpec = append(upsertStakeSpec, pb.UpsertStakeSpec{ | |
SourceId: string(NewPGMEntityId(PGMEntityType_Actor, string(authSpec.UserId), PGMEntityAttributeType_Accuracy)), | |
TargetId: string(NewPGMEntityId(PGMEntityType_SourceModeration, string(req.SourceId), PGMEntityAttributeType_Accuracy)), | |
V: &pb.UpsertStakeSpecValue{ | |
T: now, | |
P: int32(StakePolarity_Support), | |
W: 1.0, | |
TargetValue: &pb.PGMStakeTargetValue{ | |
TargetV: float64(req.Reputation), | |
T: now, | |
}, | |
}, | |
}) | |
_ = c.PGMService.UpsertStake(upsertStakeSpec) | |
upsertEntityResolutionSpec := make([]pb.UpsertEntityResolutionSpec, 0) | |
upsertEntityResolutionSpec = append(upsertEntityResolutionSpec, pb.UpsertEntityResolutionSpec{ | |
Id: string(NewPGMEntityId(PGMEntityType_SourceModeration, string(req.SourceId), PGMEntityAttributeType_Accuracy)), | |
RV: float64(req.Reputation), | |
RW: 1.0, | |
Version: PgmPhysicalMutationIdGen.NextId(), | |
}) | |
_ = c.PGMService.UpsertEntityResolution(upsertEntityResolutionSpec) | |
updateSourceRepSpec := UpdateSourceRepSpec{ | |
Id: SourceId(req.SourceId), | |
Reputation: req.Reputation, | |
} | |
err := c.SourceDataService.UpdateSourceRep(updateSourceRepSpec) | |
if err != nil { | |
return &respondAPI.UpdateSourceRepResponse{ | |
Status: http.StatusInternalServerError, | |
}, err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment