Skip to content

Commit

Permalink
feat: hopefully final API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Oct 15, 2024
1 parent 8b90f3b commit c6353af
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
28 changes: 14 additions & 14 deletions terraso_backend/apps/graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2340,22 +2340,22 @@ input DepthDependentSoilDataUpdateMutationInput {

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

type SoilDataPushResultEntry {
type SoilDataPushEntry {
siteId: ID!
result: SoilDataPushResult!
result: SoilDataPushEntryResult!
}

union SoilDataPushResult = SoilDataPushSuccess | SoilDataPushFailure
union SoilDataPushEntryResult = SoilDataPushEntrySuccess | SoilDataPushEntryFailure

type SoilDataPushSuccess {
type SoilDataPushEntrySuccess {
site: SiteNode!
}

type SoilDataPushFailure {
type SoilDataPushEntryFailure {
reason: SoilDataPushFailureReason!
}

Expand All @@ -2366,11 +2366,11 @@ enum SoilDataPushFailureReason {
}

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

input SoilDataPushEntry {
input SoilDataPushInputEntry {
downSlope: SoilIdSoilDataDownSlopeChoices
crossSlope: SoilIdSoilDataCrossSlopeChoices
bedrock: Int
Expand All @@ -2389,10 +2389,10 @@ input SoilDataPushEntry {
landCoverSelect: SoilIdSoilDataLandCoverSelectChoices
grazingSelect: SoilIdSoilDataGrazingSelectChoices
siteId: ID!
soilData: SoilDataPushSoilData!
soilData: SoilDataPushInputSoilData!
}

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

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

input SoilDataPushDepthIntervalEntry {
input SoilDataPushInputDepthInterval {
label: String
depthInterval: DepthIntervalInput!
soilTextureEnabled: Boolean
Expand Down
44 changes: 21 additions & 23 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,7 +21,7 @@
logger = structlog.get_logger(__name__)


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


Expand All @@ -32,53 +32,51 @@ class SoilDataPushFailureReason(graphene.Enum):
INTEGRITY_ERROR = "INTEGRITY_ERROR"


class SoilDataPushFailure(graphene.ObjectType):
class SoilDataPushEntryFailure(graphene.ObjectType):
reason = graphene.Field(SoilDataPushFailureReason, required=True)


class SoilDataPushResult(graphene.Union):
class SoilDataPushEntryResult(graphene.Union):
class Meta:
types = (SoilDataPushSuccess, SoilDataPushFailure)
types = (SoilDataPushEntrySuccess, SoilDataPushEntryFailure)


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


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


class SoilDataPushDepthIntervalEntry(SoilDataDepthIntervalFields, graphene.InputObjectType):
class SoilDataPushInputDepthInterval(SoilDataDepthIntervalFields, graphene.InputObjectType):
pass


class SoilDataPushSoilData(SoilDataInputs, graphene.InputObjectType):
class SoilDataPushInputSoilData(SoilDataInputs, graphene.InputObjectType):
depth_dependent_data = graphene.Field(
graphene.List(graphene.NonNull(SoilDataPushDepthDependentEntry)), required=True
graphene.List(graphene.NonNull(SoilDataPushInputDepthDependentData)), required=True
)
depth_intervals = graphene.Field(
graphene.List(graphene.NonNull(SoilDataPushDepthIntervalEntry)), required=True
graphene.List(graphene.NonNull(SoilDataPushInputDepthInterval)), required=True
)
deleted_depth_intervals = graphene.Field(
graphene.List(graphene.NonNull(DepthIntervalInput)), required=True
)


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


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

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

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

if site is None:
results.append(
SoilDataPushResultEntry(
SoilDataPushEntry(
site_id=site_id,
result=SoilDataPushFailure(
result=SoilDataPushEntryFailure(
reason=SoilDataPushFailureReason.DOES_NOT_EXIST
),
)
Expand All @@ -107,9 +105,9 @@ 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(
SoilDataPushResultEntry(
SoilDataPushEntry(
site_id=site_id,
result=SoilDataPushFailure(
result=SoilDataPushEntryFailure(
site=site, reason=SoilDataPushFailureReason.NOT_ALLOWED
),
)
Expand Down Expand Up @@ -143,9 +141,9 @@ def mutate_and_get_payload(cls, root, info, soil_data):
depth_interval.save()

results.append(
SoilDataPushResultEntry(
SoilDataPushEntry(
site_id=site_id,
result=SoilDataPushSuccess(site=site),
result=SoilDataPushEntrySuccess(site=site),
)
)

Expand Down

0 comments on commit c6353af

Please sign in to comment.