Skip to content

Commit

Permalink
feat: add depth intervals, tweak API
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Oct 15, 2024
1 parent 79c281f commit 2142d4e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
20 changes: 19 additions & 1 deletion terraso_backend/apps/graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2356,12 +2356,14 @@ type SoilDataBulkUpdateSuccess {
}

type SoilDataBulkUpdateFailure {
site: SiteNode
reason: SoilDataBulkUpdateFailureReason!
}

enum SoilDataBulkUpdateFailureReason {
DOES_NOT_EXIST
NOT_ALLOWED
INTEGRITY_ERROR
}

input SoilDataBulkUpdateInput {
Expand Down Expand Up @@ -2390,6 +2392,8 @@ input SoilDataBulkUpdateEntry {
siteId: ID!
soilData: SoilDataBulkUpdateSoilData!
depthDependentData: [SoilDataBulkUpdateDepthDependentEntry!]!
depthIntervals: [SoilDataBulkUpdateDepthIntervalEntry!]!
deletedDepthIntervals: [DepthIntervalInput!]!
}

input SoilDataBulkUpdateSoilData {
Expand Down Expand Up @@ -2438,14 +2442,27 @@ input SoilDataBulkUpdateDepthDependentEntry {
carbonates: SoilIdDepthDependentSoilDataCarbonatesChoices
}

input SoilDataBulkUpdateDepthIntervalEntry {
label: String
depthInterval: DepthIntervalInput!
soilTextureEnabled: Boolean
soilColorEnabled: Boolean
carbonatesEnabled: Boolean
phEnabled: Boolean
soilOrganicCarbonMatterEnabled: Boolean
electricalConductivityEnabled: Boolean
sodiumAdsorptionRatioEnabled: Boolean
soilStructureEnabled: Boolean
deleted: Boolean!
}

type SoilDataUpdateDepthIntervalMutationPayload {
errors: GenericScalar
soilData: SoilDataNode
clientMutationId: String
}

input SoilDataUpdateDepthIntervalMutationInput {
siteId: ID!
label: String
depthInterval: DepthIntervalInput!
soilTextureEnabled: Boolean
Expand All @@ -2456,6 +2473,7 @@ input SoilDataUpdateDepthIntervalMutationInput {
electricalConductivityEnabled: Boolean
sodiumAdsorptionRatioEnabled: Boolean
soilStructureEnabled: Boolean
siteId: ID!
applyToIntervals: [DepthIntervalInput!] = null
clientMutationId: String
}
Expand Down
25 changes: 14 additions & 11 deletions terraso_backend/apps/soil_id/graphql/soil_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,26 @@ class DepthIntervalInput(graphene.InputObjectType):
end = graphene.Int(required=True)


class SoilDataDepthIntervalFields:
label = graphene.String()
depth_interval = graphene.Field(DepthIntervalInput, required=True)
soil_texture_enabled = graphene.Boolean()
soil_color_enabled = graphene.Boolean()
carbonates_enabled = graphene.Boolean()
ph_enabled = graphene.Boolean()
soil_organic_carbon_matter_enabled = graphene.Boolean()
electrical_conductivity_enabled = graphene.Boolean()
sodium_adsorption_ratio_enabled = graphene.Boolean()
soil_structure_enabled = graphene.Boolean()


class SoilDataUpdateDepthIntervalMutation(BaseWriteMutation):
soil_data = graphene.Field(SoilDataNode)
model_class = SoilDataDepthIntervalNode
result_class = SoilData

class Input:
class Input(SoilDataDepthIntervalFields):
site_id = graphene.ID(required=True)
label = graphene.String()
depth_interval = graphene.Field(DepthIntervalInput, required=True)
soil_texture_enabled = graphene.Boolean()
soil_color_enabled = graphene.Boolean()
carbonates_enabled = graphene.Boolean()
ph_enabled = graphene.Boolean()
soil_organic_carbon_matter_enabled = graphene.Boolean()
electrical_conductivity_enabled = graphene.Boolean()
sodium_adsorption_ratio_enabled = graphene.Boolean()
soil_structure_enabled = graphene.Boolean()
apply_to_intervals = graphene.Field(graphene.List(graphene.NonNull(DepthIntervalInput)))

@classmethod
Expand Down
22 changes: 20 additions & 2 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 @@ -9,7 +9,12 @@
from apps.project_management.models.sites import Site
from apps.project_management.permission_rules import Context
from apps.project_management.permission_table import SiteAction, check_site_permission
from apps.soil_id.graphql.soil_data import SoilDataDepthDependentInputs, SoilDataInputs
from apps.soil_id.graphql.soil_data import (
DepthIntervalInput,
SoilDataDepthDependentInputs,
SoilDataDepthIntervalFields,
SoilDataInputs,
)
from apps.soil_id.models.soil_data import SoilData
from apps.soil_id.models.soil_data_history import SoilDataHistory

Expand All @@ -24,9 +29,11 @@ class SoilDataBulkUpdateSuccess(graphene.ObjectType):
class SoilDataBulkUpdateFailureReason(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)


Expand All @@ -48,12 +55,23 @@ class SoilDataBulkUpdateSoilData(SoilDataInputs, 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))
depth_dependent_data = graphene.Field(
graphene.List(graphene.NonNull(SoilDataBulkUpdateDepthDependentEntry)), required=True
)
depth_intervals = graphene.Field(
graphene.List(graphene.NonNull(SoilDataBulkUpdateDepthIntervalEntry)), required=True
)
deleted_depth_intervals = graphene.Field(
graphene.List(graphene.NonNull(DepthIntervalInput)), required=True
)


class SoilDataBulkUpdate(BaseWriteMutation):
Expand Down Expand Up @@ -95,7 +113,7 @@ def mutate_and_get_payload(cls, root, info, soil_data):
SoilDataBulkUpdateResultEntry(
site_id=site_id,
result=SoilDataBulkUpdateFailure(
reason=SoilDataBulkUpdateFailureReason.NOT_ALLOWED
site=site, reason=SoilDataBulkUpdateFailureReason.NOT_ALLOWED
),
)
)
Expand Down

0 comments on commit 2142d4e

Please sign in to comment.