Skip to content

Commit

Permalink
feat: soil settings
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Sep 29, 2023
1 parent 98bcf54 commit 83c09df
Show file tree
Hide file tree
Showing 14 changed files with 914 additions and 69 deletions.
14 changes: 14 additions & 0 deletions terraso_backend/apps/graphql/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

from apps.soil_id.graphql.soil_data import (
DepthDependentSoilDataUpdateMutation,
ProjectSoilSettingsDeleteDepthIntervalMutation,
ProjectSoilSettingsUpdateDepthIntervalMutation,
ProjectSoilSettingsUpdateMutation,
SoilDataDeleteDepthIntervalMutation,
SoilDataUpdateDepthIntervalMutation,
SoilDataUpdateMutation,
)

Expand Down Expand Up @@ -172,6 +177,15 @@ class Mutations(graphene.ObjectType):
mark_project_seen = ProjectMarkSeenMutation.Field()
update_soil_data = SoilDataUpdateMutation.Field()
update_depth_dependent_soil_data = DepthDependentSoilDataUpdateMutation.Field()
update_soil_data_depth_interval = SoilDataUpdateDepthIntervalMutation.Field()
delete_soil_data_depth_interval = SoilDataDeleteDepthIntervalMutation.Field()
update_project_soil_settings = ProjectSoilSettingsUpdateMutation.Field()
update_project_soil_settings_depth_interval = (
ProjectSoilSettingsUpdateDepthIntervalMutation.Field()
)
delete_project_soil_settings_depth_interval = (
ProjectSoilSettingsDeleteDepthIntervalMutation.Field()
)


schema = graphene.Schema(query=Query, mutation=Mutations)
24 changes: 18 additions & 6 deletions terraso_backend/apps/graphql/schema/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def mutate(cls, root, info, input):
)
return cls(errors=[{"message": str(error)}])

@classmethod
def not_found(cls, model=None, field=None, msg=None):
raise GraphQLNotFoundException(msg, field=field, model_name=model.__name__)

@classmethod
def get_or_throw(cls, model, field_name, id_):
try:
Expand Down Expand Up @@ -161,6 +165,11 @@ def not_allowed(cls, mutation_type=None, msg=None, extra=None):
def not_allowed_create(cls, model, msg=None, extra=None):
raise cls.not_allowed(MutationTypes.CREATE, msg, extra)

@classmethod
def not_found(cls, model=None, field=None, msg=None):
model = model or cls.model_class
raise GraphQLNotFoundException(msg, field=field, model_name=model.__name__)


class BaseWriteMutation(BaseAuthenticatedMutation):
logger: Optional[audit_log_api.AuditLog] = None
Expand Down Expand Up @@ -244,13 +253,16 @@ def get_logger(cls):
class BaseDeleteMutation(BaseAuthenticatedMutation):
@classmethod
def mutate_and_get_payload(cls, root, info, **kwargs):
_id = kwargs.pop("id", None)

if not _id:
model_instance = None
if "model_instance" in kwargs:
model_instance = kwargs.pop("model_instance")
else:
model_instance = cls.model_class.objects.get(pk=_id)
model_instance.delete()
_id = kwargs.pop("id", None)

if not _id:
model_instance = None
else:
model_instance = cls.model_class.objects.get(pk=_id)
model_instance.delete()

result_kwargs = {from_camel_to_snake_case(cls.model_class.__name__): model_instance}
return cls(**result_kwargs)
17 changes: 16 additions & 1 deletion terraso_backend/apps/graphql/schema/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from apps.audit_logs import api as log_api
from apps.project_management.models import Project
from apps.project_management.models.sites import Site
from apps.soil_id.models.project_soil_settings import ProjectSoilSettings

from .commons import (
BaseAuthenticatedMutation,
Expand All @@ -46,12 +47,26 @@ class Meta:
class ProjectNode(DjangoObjectType):
id = graphene.ID(source="pk", required=True)
seen = graphene.Boolean(required=True)
soil_settings = graphene.Field(
"apps.soil_id.graphql.soil_data.ProjectSoilSettingsNode",
required=True,
default_value=ProjectSoilSettings(),
)

class Meta:
model = Project

filterset_class = ProjectFilterSet
fields = ("name", "privacy", "description", "updated_at", "group", "site_set", "archived")
fields = (
"name",
"privacy",
"description",
"updated_at",
"group",
"site_set",
"archived",
"soil_settings",
)

interfaces = (relay.Node,)
connection_class = TerrasoConnection
Expand Down
191 changes: 178 additions & 13 deletions terraso_backend/apps/graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ type ProjectNode implements Node {
"""Ordering"""
orderBy: String
): SiteNodeConnection!
soilSettings: ProjectSoilSettingsNode!
id: ID!
seen: Boolean!
}
Expand Down Expand Up @@ -694,9 +695,9 @@ type SiteNode implements Node {
privacy: ProjectManagementSitePrivacyChoices!
project: ProjectNode
archived: Boolean!
soilData: SoilDataNode
id: ID!
seen: Boolean!
soilData: SoilDataNode!
}

"""An enumeration."""
Expand All @@ -709,6 +710,7 @@ enum ProjectManagementSitePrivacyChoices {
}

type SoilDataNode {
site: SiteNode!
downSlope: SoilIdSoilDataDownSlopeChoices
crossSlope: SoilIdSoilDataCrossSlopeChoices
bedrock: Int
Expand All @@ -717,7 +719,7 @@ type SoilDataNode {
slopeSteepnessSelect: SoilIdSoilDataSlopeSteepnessSelectChoices
slopeSteepnessPercent: Int
slopeSteepnessDegree: Int
depthIntervals: [DepthInterval!]!
depthIntervals: [SoilDataDepthIntervalNode!]!
depthDependentData: [DepthDependentSoilDataNode!]!
}

Expand Down Expand Up @@ -814,14 +816,30 @@ enum SoilIdSoilDataSlopeSteepnessSelectChoices {
STEEPEST
}

type SoilDataDepthIntervalNode {
label: String!
slopeEnabled: Boolean!
soilTextureEnabled: Boolean!
soilColorEnabled: Boolean!
verticalCrackingEnabled: Boolean!
carbonatesEnabled: Boolean!
phEnabled: Boolean!
soilOrganicCarbonMatterEnabled: Boolean!
electricalConductivityEnabled: Boolean!
sodiumAdsorptionRatioEnabled: Boolean!
soilStructureEnabled: Boolean!
landUseLandCoverEnabled: Boolean!
soilLimitationsEnabled: Boolean!
site: SiteNode!
depthInterval: DepthInterval!
}

type DepthInterval {
start: Int!
end: Int!
}

type DepthDependentSoilDataNode {
depthStart: Int!
depthEnd: Int!
texture: SoilIdDepthDependentSoilDataTextureChoices
rockFragmentVolume: SoilIdDepthDependentSoilDataRockFragmentVolumeChoices
colorHueSubstep: SoilIdDepthDependentSoilDataColorHueSubstepChoices
Expand All @@ -841,6 +859,8 @@ type DepthDependentSoilDataNode {
soilOrganicMatterTesting: SoilIdDepthDependentSoilDataSoilOrganicMatterTestingChoices
sodiumAbsorptionRatio: Decimal
carbonates: SoilIdDepthDependentSoilDataCarbonatesChoices
site: SiteNode!
depthInterval: DepthInterval!
}

"""An enumeration."""
Expand Down Expand Up @@ -1188,6 +1208,58 @@ enum SoilIdDepthDependentSoilDataCarbonatesChoices {
VIOLENTLY_EFFERVESCENT
}

type ProjectSoilSettingsNode {
project: ProjectNode!
measurementUnits: SoilIdProjectSoilSettingsMeasurementUnitsChoices
depthIntervalPreset: SoilIdProjectSoilSettingsDepthIntervalPresetChoices!
soilPitRequired: Boolean!
slopeRequired: Boolean!
soilTextureRequired: Boolean!
soilColorRequired: Boolean!
verticalCrackingRequired: Boolean!
carbonatesRequired: Boolean!
phRequired: Boolean!
soilOrganicCarbonMatterRequired: Boolean!
electricalConductivityRequired: Boolean!
sodiumAdsorptionRatioRequired: Boolean!
soilStructureRequired: Boolean!
landUseLandCoverRequired: Boolean!
soilLimitationsRequired: Boolean!
photosRequired: Boolean!
notesRequired: Boolean!
depthIntervals: [ProjectDepthIntervalNode!]!
}

"""An enumeration."""
enum SoilIdProjectSoilSettingsMeasurementUnitsChoices {
"""Imperial"""
IMPERIAL

"""Metric"""
METRIC
}

"""An enumeration."""
enum SoilIdProjectSoilSettingsDepthIntervalPresetChoices {
"""Landpks"""
LANDPKS

"""Nrcs"""
NRCS

"""None"""
NONE

"""Custom"""
CUSTOM
}

type ProjectDepthIntervalNode {
project: ProjectNode!
label: String!
depthInterval: DepthInterval!
}

type ProjectNodeConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!
Expand Down Expand Up @@ -1306,6 +1378,11 @@ type Mutations {
markProjectSeen(input: ProjectMarkSeenMutationInput!): ProjectMarkSeenMutationPayload!
updateSoilData(input: SoilDataUpdateMutationInput!): SoilDataUpdateMutationPayload!
updateDepthDependentSoilData(input: DepthDependentSoilDataUpdateMutationInput!): DepthDependentSoilDataUpdateMutationPayload!
updateSoilDataDepthInterval(input: SoilDataUpdateDepthIntervalMutationInput!): SoilDataUpdateDepthIntervalMutationPayload!
deleteSoilDataDepthInterval(input: SoilDataDeleteDepthIntervalMutationInput!): SoilDataDeleteDepthIntervalMutationPayload!
updateProjectSoilSettings(input: ProjectSoilSettingsUpdateMutationInput!): ProjectSoilSettingsUpdateMutationPayload!
updateProjectSoilSettingsDepthInterval(input: ProjectSoilSettingsUpdateDepthIntervalMutationInput!): ProjectSoilSettingsUpdateDepthIntervalMutationPayload!
deleteProjectSoilSettingsDepthInterval(input: ProjectSoilSettingsDeleteDepthIntervalMutationInput!): ProjectSoilSettingsDeleteDepthIntervalMutationPayload!
}

type GroupAddMutationPayload {
Expand Down Expand Up @@ -1841,25 +1918,18 @@ input SoilDataUpdateMutationInput {
slopeSteepnessSelect: SoilIdSoilDataSlopeSteepnessSelectChoices
slopeSteepnessPercent: Int
slopeSteepnessDegree: Int
depthIntervals: [DepthIntervalInput!]
clientMutationId: String
}

input DepthIntervalInput {
start: Int!
end: Int!
}

type DepthDependentSoilDataUpdateMutationPayload {
errors: GenericScalar
depthDependentSoilData: DepthDependentSoilDataNode
soilData: SoilDataNode
clientMutationId: String
}

input DepthDependentSoilDataUpdateMutationInput {
siteId: ID!
depthStart: Int!
depthEnd: Int!
depthInterval: DepthIntervalInput!
texture: SoilIdDepthDependentSoilDataTextureChoices
rockFragmentVolume: SoilIdDepthDependentSoilDataRockFragmentVolumeChoices
colorHueSubstep: SoilIdDepthDependentSoilDataColorHueSubstepChoices
Expand All @@ -1881,3 +1951,98 @@ input DepthDependentSoilDataUpdateMutationInput {
carbonates: SoilIdDepthDependentSoilDataCarbonatesChoices
clientMutationId: String
}

input DepthIntervalInput {
start: Int!
end: Int!
}

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

input SoilDataUpdateDepthIntervalMutationInput {
siteId: ID!
label: String
depthInterval: DepthIntervalInput!
slopeEnabled: Boolean
soilTextureEnabled: Boolean
soilColorEnabled: Boolean
verticalCrackingEnabled: Boolean
carbonatesEnabled: Boolean
phEnabled: Boolean
soilOrganicCarbonMatterEnabled: Boolean
electricalConductivityEnabled: Boolean
sodiumAdsorptionRatioEnabled: Boolean
soilStructureEnabled: Boolean
landUseLandCoverEnabled: Boolean
soilLimitationsEnabled: Boolean
clientMutationId: String
}

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

input SoilDataDeleteDepthIntervalMutationInput {
siteId: ID!
depthInterval: DepthIntervalInput!
clientMutationId: String
}

type ProjectSoilSettingsUpdateMutationPayload {
errors: GenericScalar
soilSettings: ProjectSoilSettingsNode
clientMutationId: String
}

input ProjectSoilSettingsUpdateMutationInput {
projectId: ID!
measurementUnits: SoilIdProjectSoilSettingsMeasurementUnitsChoices
depthIntervalPreset: SoilIdProjectSoilSettingsDepthIntervalPresetChoices
soilPitRequired: Boolean
slopeRequired: Boolean
soilTextureRequired: Boolean
soilColorRequired: Boolean
verticalCrackingRequired: Boolean
carbonatesRequired: Boolean
phRequired: Boolean
soilOrganicCarbonMatterRequired: Boolean
electricalConductivityRequired: Boolean
sodiumAdsorptionRatioRequired: Boolean
soilStructureRequired: Boolean
landUseLandCoverRequired: Boolean
soilLimitationsRequired: Boolean
photosRequired: Boolean
notesRequired: Boolean
clientMutationId: String
}

type ProjectSoilSettingsUpdateDepthIntervalMutationPayload {
errors: GenericScalar
soilSettings: ProjectSoilSettingsNode
clientMutationId: String
}

input ProjectSoilSettingsUpdateDepthIntervalMutationInput {
projectId: ID!
label: String
depthInterval: DepthIntervalInput!
clientMutationId: String
}

type ProjectSoilSettingsDeleteDepthIntervalMutationPayload {
errors: GenericScalar
soilSettings: ProjectSoilSettingsNode
clientMutationId: String
}

input ProjectSoilSettingsDeleteDepthIntervalMutationInput {
projectId: ID!
depthInterval: DepthIntervalInput!
clientMutationId: String
}
Loading

0 comments on commit 83c09df

Please sign in to comment.