<repo_name>linelect/uaapi<file_sep>/src/main/java/com/linelect/uaapi/model/House.java
package com.linelect.uaapi.model;

import javax.persistence.*;

@Entity
@Table(name = "house", indexes = {@Index(name = "house_number_idx", columnList = "house_number")})
public class House {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "house_number", nullable = false, length = 50)
    private String houseNumber;

    @Column(name = "post_index")
    private int postIndex;

    @ManyToOne
    private Street street;

    public House() {
    }

    public House(String houseNumber, int postIndex, Street street) {
        this.houseNumber = houseNumber;
        this.postIndex = postIndex;
        this.street = street;
    }

    public House(Long id, String houseNumbers, int postIndex, Street street) {
        this(houseNumbers, postIndex, street);
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getHouseNumber() {
        return houseNumber;
    }

    public void setHouseNumber(String houseNumber) {
        this.houseNumber = houseNumber;
    }

    public Street getStreet() {
        return street;
    }

    public void setStreet(Street street) {
        this.street = street;
    }

    public int getPostIndex() {
        return postIndex;
    }

    public void setPostIndex(int postIndex) {
        this.postIndex = postIndex;
    }
}
<file_sep>/src/main/java/com/linelect/uaapi/repository/RegionRepository.java
package com.linelect.uaapi.repository;

import com.linelect.uaapi.model.Region;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface RegionRepository extends JpaRepository<Region, Long> {
    List<Region> findByName(String name);
}
<file_sep>/src/main/java/com/linelect/uaapi/controller/SettlementController.java
package com.linelect.uaapi.controller;

import com.linelect.uaapi.model.Settlement;
import com.linelect.uaapi.repository.SettlementRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/settlement")
public class SettlementController {
    private SettlementRepository settlementRepository;

    @Autowired
    public SettlementController(SettlementRepository settlementRepository) {
        this.settlementRepository = settlementRepository;
    }

    @GetMapping
    public List<Settlement> getAll() {
        return settlementRepository.findAll();
    }

    @GetMapping("/{id}")
    public Settlement getById(Long id) {
        return settlementRepository.findById(id).get();
    }
}
<file_sep>/src/main/java/com/linelect/uaapi/repository/SettlementRepository.java
package com.linelect.uaapi.repository;

import com.linelect.uaapi.model.Area;
import com.linelect.uaapi.model.Settlement;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface SettlementRepository extends JpaRepository<Settlement, Long> {
    List<Settlement> findByNameAndArea(String name, Area area);
}
<file_sep>/src/main/java/com/linelect/uaapi/model/Street.java
package com.linelect.uaapi.model;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import javax.persistence.*;

@Entity
@Table(name = "street", indexes = {@Index(name = "street_name_idx", columnList = "name")})
public class Street {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne
    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
    private Settlement settlement;

    @Column(name = "name", nullable = false, length = 50)
    private String name;

    public Street() {
    }

    public Street(Long id) {
        this.id = id;
    }

    public Street(Settlement settlement, String name) {
        this.settlement = settlement;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Settlement getSettlement() {
        return settlement;
    }

    public void setSettlement(Settlement settlement) {
        this.settlement = settlement;
    }
}
<file_sep>/src/main/java/com/linelect/uaapi/repository/StreetRepository.java
package com.linelect.uaapi.repository;

import com.linelect.uaapi.model.Settlement;
import com.linelect.uaapi.model.Street;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface StreetRepository extends JpaRepository<Street, Long> {
    List<Street> findByNameAndSettlement(String name, Settlement settlement);
}
