Skip to content

Instantly share code, notes, and snippets.

@jhidajat
Created August 28, 2020 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhidajat/8a7f32ef88b769ba832a8a64a43176c5 to your computer and use it in GitHub Desktop.
Save jhidajat/8a7f32ef88b769ba832a8a64a43176c5 to your computer and use it in GitHub Desktop.
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