product descriptions crud
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package pl.com.bottega.factory.product.management;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Value
|
||||
public class ProductDescription {
|
||||
String refNo;
|
||||
String matNum;
|
||||
List<String> names;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package pl.com.bottega.factory.product.management;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductDescriptionDao extends JpaRepository<ProductDescriptionEntity, Long> {
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package pl.com.bottega.factory.product.management;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import pl.com.bottega.tools.JsonConverter;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity(name = "ProductDescription")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(of = "id")
|
||||
public class ProductDescriptionEntity {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
@Convert(converter = DescriptionAsJson.class)
|
||||
ProductDescription description;
|
||||
|
||||
public ProductDescriptionEntity(ProductDescription description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static class DescriptionAsJson extends JsonConverter<ProductDescription> {
|
||||
public DescriptionAsJson() {
|
||||
super(ProductDescription.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package pl.com.bottega.factory.product.management;
|
||||
|
||||
import org.springframework.data.rest.core.annotation.HandleAfterSave;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RepositoryEventHandler
|
||||
public class ProductDescriptionEventsMapping {
|
||||
|
||||
@HandleAfterSave
|
||||
public void handle(ProductDescriptionEntity entity) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package pl.com.bottega.factory.product.management;
|
||||
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
|
||||
@RepositoryRestResource
|
||||
public interface ProductDescriptionResource extends PagingAndSortingRepository<ProductDescriptionEntity, Long> {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package pl.com.bottega.factory.product.management
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import spock.lang.Specification
|
||||
|
||||
import static java.util.Collections.singletonList
|
||||
|
||||
@SpringBootTest
|
||||
class ProductDescriptionPersistenceTest extends Specification {
|
||||
|
||||
@Autowired
|
||||
ProductDescriptionDao dao
|
||||
|
||||
void setup() {
|
||||
dao.deleteAllInBatch()
|
||||
}
|
||||
|
||||
def "verify access to ProductDescription data"() {
|
||||
given:
|
||||
dao.save(new ProductDescriptionEntity(
|
||||
new ProductDescription("3009000", "461952398951", singletonList("PROWAD.POJ.NA JARZ.ESSENT"))))
|
||||
|
||||
when:
|
||||
def entities = dao.findAll()
|
||||
|
||||
then:
|
||||
entities.size() == 1
|
||||
entities.get(0).description ==
|
||||
new ProductDescription("3009000", "461952398951", singletonList("PROWAD.POJ.NA JARZ.ESSENT"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user