Skip to content

Commit

Permalink
feat: more API tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Oct 15, 2024
1 parent 2142d4e commit 8b90f3b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 57 deletions.
42 changes: 20 additions & 22 deletions terraso_backend/apps/graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ type Mutations {
markProjectSeen(input: ProjectMarkSeenMutationInput!): ProjectMarkSeenMutationPayload!
updateSoilData(input: SoilDataUpdateMutationInput!): SoilDataUpdateMutationPayload!
updateDepthDependentSoilData(input: DepthDependentSoilDataUpdateMutationInput!): DepthDependentSoilDataUpdateMutationPayload!
bulkUpdateSoilData(input: SoilDataBulkUpdateInput!): SoilDataBulkUpdatePayload!
pushSoilData(input: SoilDataPushInput!): SoilDataPushPayload!
updateSoilDataDepthInterval(input: SoilDataUpdateDepthIntervalMutationInput!): SoilDataUpdateDepthIntervalMutationPayload!
deleteSoilDataDepthInterval(input: SoilDataDeleteDepthIntervalMutationInput!): SoilDataDeleteDepthIntervalMutationPayload!
updateProjectSoilSettings(input: ProjectSoilSettingsUpdateMutationInput!): ProjectSoilSettingsUpdateMutationPayload!
Expand Down Expand Up @@ -2338,40 +2338,39 @@ input DepthDependentSoilDataUpdateMutationInput {
clientMutationId: String
}

type SoilDataBulkUpdatePayload {
type SoilDataPushPayload {
errors: GenericScalar
results: [SoilDataBulkUpdateResultEntry!]!
results: [SoilDataPushResultEntry!]!
clientMutationId: String
}

type SoilDataBulkUpdateResultEntry {
type SoilDataPushResultEntry {
siteId: ID!
result: SoilDataBulkUpdateResult!
result: SoilDataPushResult!
}

union SoilDataBulkUpdateResult = SoilDataBulkUpdateSuccess | SoilDataBulkUpdateFailure
union SoilDataPushResult = SoilDataPushSuccess | SoilDataPushFailure

type SoilDataBulkUpdateSuccess {
type SoilDataPushSuccess {
site: SiteNode!
}

type SoilDataBulkUpdateFailure {
site: SiteNode
reason: SoilDataBulkUpdateFailureReason!
type SoilDataPushFailure {
reason: SoilDataPushFailureReason!
}

enum SoilDataBulkUpdateFailureReason {
enum SoilDataPushFailureReason {
DOES_NOT_EXIST
NOT_ALLOWED
INTEGRITY_ERROR
}

input SoilDataBulkUpdateInput {
soilData: [SoilDataBulkUpdateEntry!]!
input SoilDataPushInput {
soilData: [SoilDataPushEntry!]!
clientMutationId: String
}

input SoilDataBulkUpdateEntry {
input SoilDataPushEntry {
downSlope: SoilIdSoilDataDownSlopeChoices
crossSlope: SoilIdSoilDataCrossSlopeChoices
bedrock: Int
Expand All @@ -2390,13 +2389,10 @@ input SoilDataBulkUpdateEntry {
landCoverSelect: SoilIdSoilDataLandCoverSelectChoices
grazingSelect: SoilIdSoilDataGrazingSelectChoices
siteId: ID!
soilData: SoilDataBulkUpdateSoilData!
depthDependentData: [SoilDataBulkUpdateDepthDependentEntry!]!
depthIntervals: [SoilDataBulkUpdateDepthIntervalEntry!]!
deletedDepthIntervals: [DepthIntervalInput!]!
soilData: SoilDataPushSoilData!
}

input SoilDataBulkUpdateSoilData {
input SoilDataPushSoilData {
downSlope: SoilIdSoilDataDownSlopeChoices
crossSlope: SoilIdSoilDataCrossSlopeChoices
bedrock: Int
Expand All @@ -2414,9 +2410,12 @@ input SoilDataBulkUpdateSoilData {
soilDepthSelect: SoilIdSoilDataSoilDepthSelectChoices
landCoverSelect: SoilIdSoilDataLandCoverSelectChoices
grazingSelect: SoilIdSoilDataGrazingSelectChoices
depthDependentData: [SoilDataPushDepthDependentEntry!]!
depthIntervals: [SoilDataPushDepthIntervalEntry!]!
deletedDepthIntervals: [DepthIntervalInput!]!
}

input SoilDataBulkUpdateDepthDependentEntry {
input SoilDataPushDepthDependentEntry {
depthInterval: DepthIntervalInput!
texture: SoilIdDepthDependentSoilDataTextureChoices
clayPercent: Int
Expand All @@ -2442,7 +2441,7 @@ input SoilDataBulkUpdateDepthDependentEntry {
carbonates: SoilIdDepthDependentSoilDataCarbonatesChoices
}

input SoilDataBulkUpdateDepthIntervalEntry {
input SoilDataPushDepthIntervalEntry {
label: String
depthInterval: DepthIntervalInput!
soilTextureEnabled: Boolean
Expand All @@ -2453,7 +2452,6 @@ input SoilDataBulkUpdateDepthIntervalEntry {
electricalConductivityEnabled: Boolean
sodiumAdsorptionRatioEnabled: Boolean
soilStructureEnabled: Boolean
deleted: Boolean!
}

type SoilDataUpdateDepthIntervalMutationPayload {
Expand Down
4 changes: 2 additions & 2 deletions terraso_backend/apps/graphql/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
SoilDataUpdateMutation,
)
from apps.soil_id.graphql.soil_id.endpoints import soil_id
from apps.soil_id.graphql.soil_id.soil_data.types import SoilDataBulkUpdate
from apps.soil_id.graphql.soil_id.soil_data.types import SoilDataPush

from .audit_logs import AuditLogNode
from .commons import TerrasoRelayNode
Expand Down Expand Up @@ -192,7 +192,7 @@ class Mutations(graphene.ObjectType):
mark_project_seen = ProjectMarkSeenMutation.Field()
update_soil_data = SoilDataUpdateMutation.Field()
update_depth_dependent_soil_data = DepthDependentSoilDataUpdateMutation.Field()
bulk_update_soil_data = SoilDataBulkUpdate.Field()
push_soil_data = SoilDataPush.Field()
update_soil_data_depth_interval = SoilDataUpdateDepthIntervalMutation.Field()
delete_soil_data_depth_interval = SoilDataDeleteDepthIntervalMutation.Field()
update_project_soil_settings = ProjectSoilSettingsUpdateMutation.Field()
Expand Down
61 changes: 29 additions & 32 deletions terraso_backend/apps/soil_id/graphql/soil_id/soil_data/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,67 +21,64 @@
logger = structlog.get_logger(__name__)


class SoilDataBulkUpdateSuccess(graphene.ObjectType):
class SoilDataPushSuccess(graphene.ObjectType):
site = graphene.Field(SiteNode, required=True)


# TODO: just a generic "can't access" result?
class SoilDataBulkUpdateFailureReason(graphene.Enum):
class SoilDataPushFailureReason(graphene.Enum):
DOES_NOT_EXIST = "DOES_NOT_EXIST"
NOT_ALLOWED = "NOT_ALLOWED"
INTEGRITY_ERROR = "INTEGRITY_ERROR"


class SoilDataBulkUpdateFailure(graphene.ObjectType):
site = graphene.Field(SiteNode, required=False)
reason = graphene.Field(SoilDataBulkUpdateFailureReason, required=True)
class SoilDataPushFailure(graphene.ObjectType):
reason = graphene.Field(SoilDataPushFailureReason, required=True)


class SoilDataBulkUpdateResult(graphene.Union):
class SoilDataPushResult(graphene.Union):
class Meta:
types = (SoilDataBulkUpdateSuccess, SoilDataBulkUpdateFailure)
types = (SoilDataPushSuccess, SoilDataPushFailure)


class SoilDataBulkUpdateResultEntry(graphene.ObjectType):
class SoilDataPushResultEntry(graphene.ObjectType):
site_id = graphene.ID(required=True)
result = graphene.Field(SoilDataBulkUpdateResult, required=True)
result = graphene.Field(SoilDataPushResult, required=True)


class SoilDataBulkUpdateDepthDependentEntry(SoilDataDepthDependentInputs, graphene.InputObjectType):
class SoilDataPushDepthDependentEntry(SoilDataDepthDependentInputs, graphene.InputObjectType):
pass


class SoilDataBulkUpdateSoilData(SoilDataInputs, graphene.InputObjectType):
class SoilDataPushDepthIntervalEntry(SoilDataDepthIntervalFields, graphene.InputObjectType):
pass


class SoilDataBulkUpdateDepthIntervalEntry(SoilDataDepthIntervalFields, graphene.InputObjectType):
deleted = graphene.Boolean(required=True)
pass


class SoilDataBulkUpdateEntry(SoilDataInputs, graphene.InputObjectType):
site_id = graphene.ID(required=True)
soil_data = graphene.Field(graphene.NonNull(SoilDataBulkUpdateSoilData))
class SoilDataPushSoilData(SoilDataInputs, graphene.InputObjectType):
depth_dependent_data = graphene.Field(
graphene.List(graphene.NonNull(SoilDataBulkUpdateDepthDependentEntry)), required=True
graphene.List(graphene.NonNull(SoilDataPushDepthDependentEntry)), required=True
)
depth_intervals = graphene.Field(
graphene.List(graphene.NonNull(SoilDataBulkUpdateDepthIntervalEntry)), required=True
graphene.List(graphene.NonNull(SoilDataPushDepthIntervalEntry)), required=True
)
deleted_depth_intervals = graphene.Field(
graphene.List(graphene.NonNull(DepthIntervalInput)), required=True
)


class SoilDataBulkUpdate(BaseWriteMutation):
class SoilDataPushEntry(SoilDataInputs, graphene.InputObjectType):
site_id = graphene.ID(required=True)
soil_data = graphene.Field(graphene.NonNull(SoilDataPushSoilData))


class SoilDataPush(BaseWriteMutation):
results = graphene.Field(
graphene.List(graphene.NonNull(SoilDataBulkUpdateResultEntry)), required=True
graphene.List(graphene.NonNull(SoilDataPushResultEntry)), required=True
)

class Input:
soil_data = graphene.Field(
graphene.List(graphene.NonNull(SoilDataBulkUpdateEntry)), required=True
graphene.List(graphene.NonNull(SoilDataPushEntry)), required=True
)

@classmethod
Expand All @@ -98,10 +95,10 @@ def mutate_and_get_payload(cls, root, info, soil_data):

if site is None:
results.append(
SoilDataBulkUpdateResultEntry(
SoilDataPushResultEntry(
site_id=site_id,
result=SoilDataBulkUpdateFailure(
reason=SoilDataBulkUpdateFailureReason.DOES_NOT_EXIST
result=SoilDataPushFailure(
reason=SoilDataPushFailureReason.DOES_NOT_EXIST
),
)
)
Expand All @@ -110,10 +107,10 @@ def mutate_and_get_payload(cls, root, info, soil_data):
user = info.context.user
if not check_site_permission(user, SiteAction.ENTER_DATA, Context(site=site)):
results.append(
SoilDataBulkUpdateResultEntry(
SoilDataPushResultEntry(
site_id=site_id,
result=SoilDataBulkUpdateFailure(
site=site, reason=SoilDataBulkUpdateFailureReason.NOT_ALLOWED
result=SoilDataPushFailure(
site=site, reason=SoilDataPushFailureReason.NOT_ALLOWED
),
)
)
Expand Down Expand Up @@ -146,9 +143,9 @@ def mutate_and_get_payload(cls, root, info, soil_data):
depth_interval.save()

results.append(
SoilDataBulkUpdateResultEntry(
SoilDataPushResultEntry(
site_id=site_id,
result=SoilDataBulkUpdateSuccess(site=site),
result=SoilDataPushSuccess(site=site),
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class Migration(migrations.Migration):

dependencies = [
("project_management", "0029_alter_projectsettings_options"),
("project_management", "0028_site_elevation"),
("soil_id", "0018_alter_projectsoilsettings_options_and_more"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
Expand Down

0 comments on commit 8b90f3b

Please sign in to comment.