Skip to content

Commit

Permalink
53 Fix incorrect blank lines (#54)
Browse files Browse the repository at this point in the history
* 53 Fix incorrect blank lines

* 53 Fix sql requests
  • Loading branch information
asavershin authored Oct 3, 2024
1 parent 70a226f commit c756e2a
Show file tree
Hide file tree
Showing 68 changed files with 140 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/main/java/agroscience/fields/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/agroscience/fields/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Configuration
public class Config {

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@Data
@ConfigurationProperties(prefix = "meteo")
public class MeteoProperties {

private String host;
private String port;

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
@RequiredArgsConstructor
@RequestMapping(path = "api/v1/admin")
public class AdminController {

private final AdminService cropsService;
private final CropMapper cropMapper;
private final AuthoriseService auth;

@PostMapping
@Operation(description = "Создание культуры")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@RequiredArgsConstructor
@RequestMapping(path = "api/v1/fields/crop-rotations")
public class CropRotationsController {

private final CropRotationsService crService;
private final CropRotationMapper crMapper;
private final AuthoriseService auth;
Expand Down Expand Up @@ -121,5 +122,4 @@ public ResponseEntity<Void> deleteCR(@Valid @Min(1) Long id, HttpServletRequest
return ResponseEntity.noContent().build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@RequiredArgsConstructor
@RequestMapping(path = "api/v1/fields")
public class CropsController {

private final CropsService cropsService;
private final CropMapper cropMapper;
private final AuthoriseService auth;
Expand All @@ -29,4 +30,5 @@ public List<ResponseCrop> getCrops(RequestGetCrops request, HttpServletRequest h
return cropsService.getCrop(request.getName(), request.getPage(), request.getSize())
.stream().map(cropMapper::cropToResponseCrop).toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ public List<ResponseFieldPreview> getFieldsPreview(@Valid Page page, HttpServlet
public List<CoordinatesWithFieldId> getAllCoordinates() {
return fieldService.getAllCoordinates();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@RequiredArgsConstructor
@RequestMapping(path = "api/v1/fields/soil")
public class SoilController {

private final SoilService soilService;
private final SoilMapper soilMapper;
private final AuthoriseService auth;
Expand Down Expand Up @@ -77,4 +78,5 @@ public ResponseEntity<Void> deleteSoil(@Valid @Min(1) Long soilId, HttpServletRe
soilService.deleteSoilById(soilId, auth.doFilter(request, new Role.Builder().worker().organization().build()));
return ResponseEntity.noContent().build();
}

}
1 change: 1 addition & 0 deletions src/main/java/agroscience/fields/dao/entities/Crop.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ public class Crop {
@ToString.Exclude
@EqualsAndHashCode.Exclude
private List<CropRotation> cropRotations = new ArrayList<>();

}
1 change: 1 addition & 0 deletions src/main/java/agroscience/fields/dao/entities/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ public class Field {
@ToString.Exclude
@EqualsAndHashCode.Exclude
private List<Soil> soils = new ArrayList<>();

}
2 changes: 2 additions & 0 deletions src/main/java/agroscience/fields/dao/entities/Soil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@AllArgsConstructor
@Builder
public class Soil {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "soil_soil_id_seq")
@SequenceGenerator(name = "soil_soil_id_seq", sequenceName = "soil_soil_id_seq", allocationSize = 1)
Expand Down Expand Up @@ -82,4 +83,5 @@ public class Soil {

@Column(name = "soil_zn")
private String soilZn;

}
2 changes: 2 additions & 0 deletions src/main/java/agroscience/fields/dao/models/FandCRandC.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import agroscience.fields.dao.entities.Field;

public interface FandCRandC {

Field getField();

CropRotation getCropRotation();

Crop getCrop();

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
@Data
@AllArgsConstructor
public class FandCRandCImpl implements FandCRandC {

private final Field field;
private final CropRotation cropRotation;
private final Crop crop;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@


public interface FieldAndCurrentCrop {

Field getField();

CropRotation getCropRotation();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@Data
@AllArgsConstructor
public class FieldAndCurrentCropImpl implements FieldAndCurrentCrop {

private final Field field;
private final CropRotation cropRotation;

}
2 changes: 2 additions & 0 deletions src/main/java/agroscience/fields/dao/models/FieldCRsSoil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import agroscience.fields.dao.entities.Soil;

public interface FieldCRsSoil {

Field getField();

CropRotation getCropRotation();

Soil getSoil();

Crop getCrop();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
@Data
@AllArgsConstructor
public class FieldCRsSoilImpl implements FieldCRsSoil {

private final Field field;
private final CropRotation cropRotation;
private final Soil soil;
private final Crop crop;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,26 @@ public interface CropRotationRepository extends JpaRepository<CropRotation, Long
AND cr.cropRotationStartDate = (
SELECT MAX(cr2.cropRotationStartDate) FROM CropRotation cr2 WHERE cr2.field.fieldId = :fieldId
)
"""
)
""")
CropRotation findLatestCR(Long fieldId);

@Query(
"""
@Query("""
SELECT f as field, cr as cropRotation, c as crop
FROM CropRotation cr
LEFT JOIN cr.field f
LEFT JOIN cr.crop c
WHERE cr.cropRotationId = :id
"""
)
""")
FandCRandC findCropRotationById(Long id);

@Query(
"""
@Query("""
SELECT f as field, cr as cropRotation, c as crop
FROM CropRotation cr
LEFT JOIN cr.field f
LEFT JOIN cr.crop c
WHERE f.fieldOrganizationId = :orgId
ORDER BY cr.cropRotationStartDate DESC
"""
)
""")
Slice<FandCRandC> findAllByOrgId(Long orgId, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface CropsRepository extends JpaRepository<Crop, Long> {

Crop findCropByCropId(Long cropId);

boolean existsByCropName(String name);

List<Crop> findAllByCropNameIgnoreCaseStartingWith(String cropName, PageRequest of);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.springframework.data.repository.query.Param;

public interface FieldRepository extends JpaRepository<Field, Long> {
@Query(
"""

@Query("""
SELECT f as field, cr as cropRotation
FROM Field f
LEFT JOIN FETCH f.cropRotations cr
Expand All @@ -20,12 +20,10 @@ public interface FieldRepository extends JpaRepository<Field, Long> {
WHERE cr2.field = f)
OR cr.cropRotationStartDate IS NULL)
AND f.fieldOrganizationId = :orgId
"""
)
""")
Slice<FieldAndCurrentCrop> fieldsWithLatestCrops(@Param("orgId") Long orgId, Pageable pageable);

@Query(
"""
@Query("""
SELECT f as field, cr as cropRotation
FROM Field f
LEFT JOIN FETCH f.cropRotations cr
Expand All @@ -34,12 +32,10 @@ public interface FieldRepository extends JpaRepository<Field, Long> {
WHERE cr2.field = f)
OR cr.cropRotationStartDate IS NULL)
AND f.fieldId = :fieldId
"""
)
""")
FieldAndCurrentCrop fieldWithLatestCrop(@Param("fieldId") Long fieldId);

@Query(
"""
@Query("""
SELECT f as field, cr as cropRotation, s as soil, c as crop
FROM Field f
LEFT JOIN FETCH f.cropRotations cr
Expand All @@ -48,9 +44,9 @@ public interface FieldRepository extends JpaRepository<Field, Long> {
WHERE f.fieldId = :fieldId
ORDER BY cr.cropRotationStartDate DESC, s.soilSampleDate DESC
LIMIT 1
"""
)
""")
FieldCRsSoil getFullField(@Param("fieldId") Long fieldId);

boolean existsByFieldName(String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
@RequiredArgsConstructor
public class JbdcDao {

private final JdbcTemplate jdbcTemplate;
private static final String GET_ORG_ID_BY_FIELD_ID = """
SELECT f.field_organization_id as orgId
FROM field f
WHERE f.field_id = ?
""";

private static final String GET_ALL_COORDINATES = """
SELECT
field_id,
ST_X(ST_Centroid(field_geom)) as longitude,
ST_Y(ST_Centroid(field_geom)) as latitude
FROM field
""";
private final JdbcTemplate jdbcTemplate;

public List<CoordinatesWithFieldId> getAllCoordinates() {

Expand All @@ -42,4 +41,5 @@ public Long getOrgIdByFieldId(Long fieldId) {
fieldId
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface SoilRepository extends JpaRepository<Soil, Long> {

boolean existsBySoilSampleDate(LocalDate date);

}
2 changes: 2 additions & 0 deletions src/main/java/agroscience/fields/dto/ResponseMeteo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
@Builder
@NoArgsConstructor
public class ResponseMeteo {

private LocalDate day;
private Long fieldId;
private Double temperature;
private Double humidity;
private Double pressure;

}
2 changes: 2 additions & 0 deletions src/main/java/agroscience/fields/dto/TimeDTO.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package agroscience.fields.dto;

public interface TimeDTO {

String start();

String end();

}
2 changes: 2 additions & 0 deletions src/main/java/agroscience/fields/dto/crop/RequestCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

@Data
public class RequestCrop {

@NotBlank
@Size(max = 50)
@JsonAlias("name")
private String cropName;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
@Getter
@Setter
public class RequestGetCrops extends Page {

@Size(max = 50)
@JsonProperty("name")
private String name;

}
2 changes: 2 additions & 0 deletions src/main/java/agroscience/fields/dto/crop/ResponseCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
@Data
@AllArgsConstructor
public class ResponseCrop {

@JsonProperty("id")
private Long cropId;
@JsonProperty("name")
private String cropName;

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ public String start() {
public String end() {
return cropRotationEndDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Data
public class ResponseCRForF {

@JsonProperty("id")
private Long cropRotationId;
private ResponseCrop crop;
Expand All @@ -15,4 +16,5 @@ public class ResponseCRForF {
private String cropRotationStartDate;
@JsonProperty("endDate")
private String cropRotationEndDate;

}
Loading

0 comments on commit c756e2a

Please sign in to comment.