Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions internal/db/attribute_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func createAttributeValueSql(
return newStatementBuilder().
Insert(AttributeValueTable).
Columns(
tableField(AttributeValueTable, "attribute_id"),
tableField(AttributeValueTable, "value"),
tableField(AttributeValueTable, "members"),
tableField(AttributeValueTable, "metadata"),
"attribute_definition_id",
"value",
"members",
"metadata",
).
Values(
attribute_id,
Expand Down Expand Up @@ -133,7 +133,7 @@ func listAttributeValuesSql(attribute_id string) (string, []interface{}, error)
tableField(AttributeValueTable, "metadata"),
).
From(AttributeValueTable).
Where(sq.Eq{tableField(AttributeValueTable, "attribute_id"): attribute_id}).
Where(sq.Eq{tableField(AttributeValueTable, "attribute_definition_id"): attribute_id}).
ToSql()
}
func (c Client) ListAttributeValues(ctx context.Context, attribute_id string) ([]*attributes.Value, error) {
Expand Down Expand Up @@ -165,15 +165,15 @@ func updateAttributeValueSql(
Update(AttributeValueTable)

if value != "" {
sb = sb.Set(tableField(AttributeValueTable, "value"), value)
sb = sb.Set("value", value)
}
if members != nil {
sb = sb.Set(tableField(AttributeValueTable, "members"), members)
sb = sb.Set("members", members)
}
sb.Set(tableField(AttributeValueTable, "metadata"), metadata)
sb.Set("metadata", metadata)

return sb.
Where(sq.Eq{tableField(AttributeValueTable, "id"): id}).
Where(sq.Eq{"id": id}).
ToSql()
}
func (c Client) UpdateAttributeValue(ctx context.Context, id string, v *attributes.ValueUpdate) (*attributes.Value, error) {
Expand Down
2 changes: 1 addition & 1 deletion migrations/20240118000000_create_new_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS opentdf.attribute_values
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
attribute_definition_id UUID NOT NULL REFERENCES opentdf.attribute_definitions(id),
value VARCHAR NOT NULL,
members UUID[] NOT NULL,
members UUID[],
metadata JSONB,
UNIQUE (attribute_definition_id, value)
);
Expand Down
30 changes: 15 additions & 15 deletions proto/attributes/attributes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,40 @@ message DeleteAttributeResponse {
///
/// Value RPC messages
///
message GetValueRequest {
message GetAttributeValueRequest {
string id = 1 [(buf.validate.field).required = true];
}
message GetValueResponse {
message GetAttributeValueResponse {
Value value = 1;
}

message ListValuesRequest {
message ListAttributeValuesRequest {
string attribute_id = 1 [(buf.validate.field).required = true];
}
message ListValuesResponse {
message ListAttributeValuesResponse {
repeated Value values = 1;
}

message CreateValueRequest {
message CreateAttributeValueRequest {
string attribute_id = 1 [(buf.validate.field).required = true];
ValueCreate value = 2 [(buf.validate.field).required = true];
}
message CreateValueResponse {
message CreateAttributeValueResponse {
Value value = 1;
}

message UpdateValueRequest {
message UpdateAttributeValueRequest {
string id = 1 [(buf.validate.field).required = true];
ValueUpdate value = 2 [(buf.validate.field).required = true];
}
message UpdateValueResponse {
message UpdateAttributeValueResponse {
Value value = 1;
}

message DeleteValueRequest {
message DeleteAttributeValueRequest {
string id = 1 [(buf.validate.field).required = true];
}
message DeleteValueResponse {
message DeleteAttributeValueResponse {
Value value = 1;
}

Expand All @@ -198,7 +198,7 @@ service AttributesService {
Example:
grpcurl -plaintext -d '{"attribute_id": "attribute_id"}' localhost:8080 attributes.AttributesService/ListValues
*/
rpc ListAttributeValues(ListValuesRequest) returns (ListValuesResponse) {}
rpc ListAttributeValues(ListAttributeValuesRequest) returns (ListAttributeValuesResponse) {}

rpc GetAttribute(GetAttributeRequest) returns (GetAttributeResponse) {
option (google.api.http) = {get: "/attributes/{id}"};
Expand Down Expand Up @@ -226,28 +226,28 @@ service AttributesService {
}

/** Attribute Value **/
rpc GetValue(GetValueRequest) returns (GetValueResponse) {
rpc GetAttributeValue(GetAttributeValueRequest) returns (GetAttributeValueResponse) {
option (google.api.http) = {get: "/attributes/_/values/{id}"};
}

// Create Attribute Value
// Example:
// grpcurl -plaintext -d '{"attribute_id": "attribute_id", "value": {"value": "value"}}' localhost:8080 attributes.AttributesService/CreateValue
rpc CreateValue(CreateValueRequest) returns (CreateValueResponse) {
rpc CreateAttributeValue(CreateAttributeValueRequest) returns (CreateAttributeValueResponse) {
option (google.api.http) = {
post: "/attributes/{attribute_id}/values"
body: "value"
};
}

rpc UpdateValue(UpdateValueRequest) returns (UpdateValueResponse) {
rpc UpdateAttributeValue(UpdateAttributeValueRequest) returns (UpdateAttributeValueResponse) {
option (google.api.http) = {
post: "/attributes/_/values/{id}"
body: "value"
};
}

rpc DeleteValue(DeleteValueRequest) returns (DeleteValueResponse) {
rpc DeleteAttributeValue(DeleteAttributeValueRequest) returns (DeleteAttributeValueResponse) {
option (google.api.http) = {delete: "/attributes/_/values/{id}"};
}
}
Loading