Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

69 fix api services + drawio schema #95

Merged
merged 1 commit into from
Nov 19, 2024
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
Binary file modified docs/dbSchema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
160 changes: 160 additions & 0 deletions docs/db_storage_schema.drawio

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public Contour findById(UUID contourId) {
}

public UUID save(UUID fieldId, Contour contour) {
var field = getOrThrow(fieldId, fieldsRepository::findById);
FieldV2 field = getOrThrow(fieldId, fieldsRepository::findById);
checkArchived(fieldId, field);
contour.setField(field);
return contoursRepository.save(contour).getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CropRotationServiceV2 extends DefaultService {

public CropRotationV2 save(UUID contourId, CropRotationV2 cropRotation) {
Contour contour = getOrThrow(contourId, contoursRepository::findById);
checkArchived(contourId, contour);
cropRotation.setContour(contour);
return cropRotationRepository.save(cropRotation);
}
Expand All @@ -32,11 +33,13 @@ public void update(UUID cropRotationId, CropRotationV2 updateCropRotation) {

public void archive(UUID cropRotationId) {
CropRotationV2 cropRotation = getOrThrow(cropRotationId, cropRotationRepository::findById);
cropRotation.setArchived(true);
cropRotation.archive();
cropRotationRepository.save(cropRotation);
}

public List<CropRotationV2> getAllByContourId(UUID contourId) {
Contour contour = getOrThrow(contourId, contoursRepository::findById);
checkArchived(contourId, contour);
return cropRotationRepository.getAllByContourIdAndArchivedIsFalse(contourId);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agroscience.fields.v2.services;

import agroscience.fields.v2.entities.FieldV2;
import agroscience.fields.v2.entities.Season;
import agroscience.fields.v2.repositories.FieldsRepository;
import agroscience.fields.v2.repositories.SeasonsRepository;
import jakarta.persistence.EntityNotFoundException;
Expand All @@ -17,14 +18,16 @@ public class FieldsService extends DefaultService {
private final SeasonsRepository seasonsRepository;

public FieldV2 save(UUID seasonId, FieldV2 field) {
var season = getOrThrow(seasonId, seasonsRepository::findById);
Season season = getOrThrow(seasonId, seasonsRepository::findById);
checkArchived(seasonId, season);
field.setSeason(season);
field.getContours().forEach(c -> c.setField(field));
return fieldsRepository.save(field);
}

public void update(UUID fieldId, FieldV2 updateField) {
FieldV2 field = getOrThrow(fieldId, fieldsRepository::findById);
checkArchived(fieldId, field);
field.setName(updateField.getName());
field.setDescription(updateField.getDescription());
fieldsRepository.save(field);
Expand All @@ -35,6 +38,8 @@ public FieldV2 findById(UUID id) {
}

public List<FieldV2> findAll(UUID seasonId) {
Season season = getOrThrow(seasonId, seasonsRepository::findById);
checkArchived(seasonId, season);
return fieldsRepository.findAllBySeason_Id(seasonId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ public class SoilCompositionsService extends DefaultService {
private final ContoursRepository contoursRepository;

public SoilComposition save(UUID contourId, SoilComposition soilComposition) {
var contour = getOrThrow(contourId, contoursRepository::findById);
Contour contour = getOrThrow(contourId, contoursRepository::findById);
checkArchived(contourId, contour);
soilComposition.setContour(contour);
return soilCompositionsRepository.save(soilComposition);
}

public void archive(UUID soilCompositionId) {
SoilComposition soilComposition = getOrThrow(soilCompositionId, soilCompositionsRepository::findById);
soilComposition.setArchived(true);
soilComposition.archive();
soilCompositionsRepository.save(soilComposition);
}

Expand All @@ -38,6 +39,7 @@ public void updateSoilComposition(UUID soilCompositionId, SoilComposition update

public List<SoilComposition> getAllSoilCompositions(UUID contourId) {
Contour contour = getOrThrow(contourId, contoursRepository::findById);
checkArchived(contourId, contour);
return soilCompositionsRepository.findAllByContourAndArchivedIsFalse(contour);
}

Expand Down
Loading