Commit 4f0ea1e4 authored by Vladimir Trubachoff's avatar Vladimir Trubachoff

Initial commit

parent 50af8069
...@@ -19,10 +19,12 @@ repositories { ...@@ -19,10 +19,12 @@ repositories {
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
developmentOnly 'org.springframework.boot:spring-boot-devtools' developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2' runtimeOnly 'com.h2database:h2'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-core:5.12.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
} }
......
package com.example.testj.domain;
import jakarta.persistence.*;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;
@Entity
@Table(name = "goods")
public class Goods {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
@NotEmpty
@Column(name = "name")
private String name;
@Digits
@NotEmpty
@Column(name = "price")
private Number price;
@OneToMany(mappedBy = "goods")
List<OrderLine> orderLines;
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 Number getPrice() {
return price;
}
public void setPrice(Number price) {
this.price = price;
}
}
package com.example.testj.domain;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.List;
@Entity
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
@NotBlank
@Column(name = "client")
private String client;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
@Column(name = "date")
private String date;
@NotBlank
@Column(name = "address")
private String address;
@OneToMany(mappedBy = "order", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
List<OrderLine> orderLines;
public Order() {
}
public Order(String client, String date, String address) {
this.client = client;
this.address = address;
this.date = date;
}
public List<OrderLine> getOrderLines() {
return orderLines;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getClient() {
return client;
}
public void setClient(String client) {
this.client = client;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
package com.example.testj.domain;
import jakarta.persistence.*;
import org.springframework.format.annotation.NumberFormat;
import java.util.Set;
@Entity
@Table(name = "order_line")
public class OrderLine {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
@ManyToOne
@JoinColumn(name = "order_id", nullable = false)
private Order order;
@ManyToOne
@JoinColumn(name = "goods_id", nullable = false)
private Goods goods;
@Column(name = "count")
@NumberFormat
private int count;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public Goods getGoods() {
return goods;
}
}
package com.example.testj.domain;
public class RestErrorInfo {
public final String detail;
public final String message;
public RestErrorInfo(Exception ex, String detail) {
this.message = ex.getLocalizedMessage();
this.detail = detail;
}
}
package com.example.testj.domain;
\ No newline at end of file
package com.example.testj.dto;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotEmpty;
import java.io.Serializable;
/**
* DTO for {@link com.example.testj.domain.Goods}
*/
public class GoodsDto implements Serializable {
private final Long id;
private final String name;
private final Number price;
public GoodsDto(Long id, String name, Number price) {
this.id = id;
this.name = name;
this.price = price;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public Number getPrice() {
return price;
}
@Override
public String toString() {
return getClass().getSimpleName() + "(" +
"id = " + id + ", " +
"name = " + name + ", " +
"price = " + price + ")";
}
}
\ No newline at end of file
package com.example.testj.dto;
import com.example.testj.domain.Order;
import java.io.Serializable;
public class OrderDTO implements Serializable {
public OrderDTO(Order order) {
this.id = order.getId();
this.client = order.getClient();
this.address = order.getAddress();
this.date = order.getDate();
}
private Long id;
private String client;
private String date;
private String address;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getClient() {
return client;
}
public void setClient(String client) {
this.client = client;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
package com.example.testj.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class BadRequestException extends RuntimeException {
}
package com.example.testj.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
}
package com.example.testj.repository;
import com.example.testj.domain.Goods;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface GoodsRepository extends CrudRepository<Goods, Long> {
}
\ No newline at end of file
package com.example.testj.repository;
import com.example.testj.domain.OrderLine;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface OrderLineRepository extends CrudRepository<OrderLine, Long> {
}
\ No newline at end of file
package com.example.testj.repository;
import com.example.testj.domain.Order;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface OrderRepository extends PagingAndSortingRepository<Order, Long>, CrudRepository<Order, Long> {
}
\ No newline at end of file
package com.example.testj.service;
import com.example.testj.domain.Order;
import com.example.testj.dto.OrderDTO;
import com.example.testj.exception.ResourceNotFoundException;
import com.example.testj.repository.OrderRepository;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PagedModel;
import org.springframework.stereotype.Service;
@Service
public class OrderService {
private final OrderRepository orderRepository;
public OrderService(OrderRepository orderRepository) {
this.orderRepository = orderRepository;
}
public PagedModel<Order> getOrders(Integer page, Integer size, String sortBy, String sortDir) {
return new PagedModel<Order>(orderRepository.findAll(PageRequest.of(page, size, Sort.by(Sort.Direction.fromString(sortDir), sortBy))));
}
public Order getOrder(Long id) throws ResourceNotFoundException {
return orderRepository.findById(id).orElseThrow(ResourceNotFoundException::new);
}
public Order saveOrUpdateOrder(Order order) {
return orderRepository.save(order);
}
public Order patchOrder(Long id, JsonNode patch) throws JsonMappingException {
Order orderData = orderRepository.findById(id).orElseThrow(ResourceNotFoundException::new);
Order patchedOrder = new ObjectMapper().updateValue(orderData, patch);
return orderRepository.save(patchedOrder);
}
public void deleteOrder(Long id) throws ResourceNotFoundException {
orderRepository.findById(id).orElseThrow(ResourceNotFoundException::new);
orderRepository.deleteById(id);
}
}
package com.example.testj.service;
\ No newline at end of file
package com.example.testj.web.rest;
import com.example.testj.domain.Goods;
import com.example.testj.repository.GoodsRepository;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@CrossOrigin(origins = "http://localhost:4200")
public class GoodsController {
private final GoodsRepository goodsRepository;
public GoodsController(GoodsRepository goodsRepository) {
this.goodsRepository = goodsRepository;
}
@GetMapping("/goods")
public List<Goods> goods() {
return (List<Goods>) goodsRepository.findAll();
}
}
package com.example.testj.web.rest;
import com.example.testj.domain.Order;
import com.example.testj.domain.RestErrorInfo;
import com.example.testj.dto.OrderDTO;
import com.example.testj.exception.ResourceNotFoundException;
import com.example.testj.repository.OrderRepository;
import com.example.testj.service.OrderService;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.validation.Valid;
import org.springframework.data.web.PagedModel;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "http://localhost:4200")
public class OrderController {
private final OrderRepository orderRepository;
private final OrderService orderService;
public OrderController(OrderRepository orderRepository, OrderService orderService) {
this.orderRepository = orderRepository;
this.orderService = orderService;
}
@GetMapping("/orders")
public PagedModel<Order> getOrders(@RequestHeader(name = "X-Current-Page", defaultValue = "0") Integer page,
@RequestHeader(name = "X-Page-Size", defaultValue = "10") Integer size,
@RequestHeader(name = "X-Sort-By", defaultValue = "id") String sortBy,
@RequestHeader(name = "X-Sort-Direction", defaultValue = "ASC") String sortDir) {
return orderService.getOrders(page, size, sortBy, sortDir);
}
@GetMapping("/orders/{id}")
public Order getOrder(@PathVariable Long id) {
return this.orderService.getOrder(id);
}
@PostMapping("/orders")
public Order createOrder(@Valid @RequestBody Order order) {
return orderService.saveOrUpdateOrder(order);
}
@PutMapping("/orders/{id}")
public Order updateOrder(@PathVariable Long id, @RequestBody Order order) {
Order updatedOrder = orderService.getOrder(id);
updatedOrder.setClient(order.getClient());
updatedOrder.setAddress(order.getAddress());
updatedOrder.setDate(order.getDate());
return orderService.saveOrUpdateOrder(updatedOrder);
}
@PatchMapping("/orders/{id}")
public Order patchOrder(@PathVariable Long id, @RequestBody JsonNode patch) throws JsonMappingException {
return orderService.patchOrder(id, patch);
}
@DeleteMapping("/orders/{id}")
public ResponseEntity<HttpStatus> deleteOrder(@PathVariable Long id) throws ResourceNotFoundException {
try {
orderService.deleteOrder(id);
return new ResponseEntity<>(HttpStatus.OK);
} catch (ResourceNotFoundException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
}
spring.application.name=testj spring.application.name=testj
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.defer-datasource-initialization=true
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false
logging.level.org.springframework.web=INFO
-- create table orders (
-- id INT,
-- client VARCHAR(50),
-- date DATE,
-- address VARCHAR(50)
-- );
insert into
orders (id, client, date, address)
values
(
1,
'Griz Soppit',
'11/18/2023',
'4 Fieldstone Pass'
),
(2, 'Lorain Kroin', '2/23/2024', '3 Boyd Hill'),
(
3,
'Benedikta Earry',
'12/22/2023',
'9 Ridge Oak Road'
),
(
4,
'Viola Airdrie',
'7/6/2023',
'587 Sloan Drive'
),
(
5,
'Tedmund Yukhin',
'1/29/2024',
'1 Northport Trail'
),
(
6,
'Niki Thibodeaux',
'1/25/2024',
'734 Vera Point'
),
(
7,
'Sheri Habershaw',
'5/25/2024',
'7689 Melrose Center'
),
(
8,
'Coral Dellatorre',
'7/28/2023',
'95 Onsgard Junction'
),
(
9,
'Leisha Barnicott',
'3/15/2024',
'945 Hanover Park'
),
(
10,
'Dukie Yushin',
'4/11/2024',
'9 Tennyson Junction'
),
(
11,
'Toni Lenchenko',
'2/16/2024',
'83 Jenifer Lane'
),
(
12,
'Ynez Moncreiff',
'5/20/2024',
'4182 Sutteridge Parkway'
),
(
13,
'Forrest Schiersch',
'10/10/2023',
'3 Anderson Center'
),
(
14,
'Franky Ply',
'3/16/2024',
'037 Heffernan Drive'
),
(
15,
'Shel Aykroyd',
'6/28/2023',
'53 Del Mar Terrace'
),
(
16,
'Peyter Colegate',
'2/8/2024',
'55889 Haas Point'
),
(
17,
'Garald Blunsden',
'9/30/2023',
'7 Acker Drive'
),
(
18,
'Carree Yakunkin',
'4/19/2024',
'40 Transport Court'
),
(
19,
'Even Axleby',
'9/12/2023',
'087 Bonner Hill'
),
(
20,
'Birch Cobelli',
'9/6/2023',
'74707 Haas Circle'
),
(
21,
'Lu Malshinger',
'3/6/2024',
'667 Tony Junction'
),
(
22,
'Hebert Canfer',
'9/24/2023',
'829 Rusk Trail'
),
(
23,
'Rickard MacQuarrie',
'3/7/2024',
'123 Service Junction'
),
(
24,
'Alyse Triplow',
'12/12/2023',
'51 Jana Junction'
),
(
25,
'Cissiee De Angelis',
'1/28/2024',
'660 Talisman Place'
),
(
26,
'Rurik Killshaw',
'3/14/2024',
'3 Dapin Park'
),
(
27,
'Carmelle Philler',
'4/24/2024',
'355 Morning Road'
),
(
28,
'Sara-ann Pook',
'3/21/2024',
'7967 Welch Plaza'
),
(29, 'Piper Libero', '1/3/2024', '3 Prentice Way'),
(
30,
'Shermy Simonnin',
'11/29/2023',
'44910 Debra Court'
),
(
31,
'Ilene Flores',
'2/8/2024',
'201 Brickson Park Center'
),
(
32,
'Vonnie Packer',
'9/11/2023',
'7 Park Meadow Street'
),
(
33,
'Armstrong Jessard',
'5/13/2024',
'1 Center Park'
),
(
34,
'Binnie Pearde',
'5/30/2024',
'72808 Johnson Place'
),
(
35,
'Rena Gontier',
'6/15/2023',
'277 Anzinger Terrace'
),
(
36,
'Calli Cockshoot',
'11/3/2023',
'23 Glendale Circle'
),
(37, 'Mariana Kift', '9/1/2023', '94 Linden Hill'),
(
38,
'Celestia Grewe',
'4/6/2024',
'0 Forster Way'
),
(
39,
'Westbrook Thomsson',
'5/13/2024',
'097 Mcbride Pass'
),
(
40,
'Charley Westrip',
'11/8/2023',
'30327 Moland Alley'
),
(
41,
'Currie Bartosek',
'1/18/2024',
'34503 Rockefeller Trail'
),
(
42,
'Quincy Breese',
'11/9/2023',
'03 Springs Road'
),
(
43,
'Blaine Giff',
'12/16/2023',
'0718 Amoth Way'
),
(
44,
'Lemmy Stidworthy',
'12/21/2023',
'6258 Cottonwood Crossing'
),
(
45,
'Feliza Erett',
'3/11/2024',
'2588 Brentwood Avenue'
),
(
46,
'Massimiliano Bogays',
'10/24/2023',
'578 Northridge Parkway'
),
(
47,
'Frannie Droogan',
'5/11/2024',
'444 4th Park'
),
(
48,
'Ichabod Goulbourne',
'9/18/2023',
'325 Comanche Park'
),
(
49,
'Rab Marishenko',
'9/26/2023',
'310 Stuart Terrace'
),
(
50,
'Elinore Healings',
'10/22/2023',
'4 Clyde Gallagher Terrace'
),
(
51,
'Dorita Batchelder',
'5/4/2024',
'241 Lien Center'
),
(
52,
'Amandy Ridolfo',
'6/30/2023',
'8 Muir Court'
),
(
53,
'Daveta Mantha',
'8/9/2023',
'0809 Coolidge Place'
),
(
54,
'Adolf Ricoald',
'2/25/2024',
'90865 Lawn Park'
),
(
55,
'Ilene Hardey',
'3/20/2024',
'72 Redwing Hill'
),
(
56,
'Hortense Settle',
'12/4/2023',
'488 Lakeland Alley'
),
(
57,
'Rakel Gunter',
'12/18/2023',
'33 Melvin Street'
),
(
58,
'Marielle Semour',
'3/21/2024',
'804 Ohio Place'
),
(
59,
'Ciro Paulillo',
'9/16/2023',
'637 Spohn Plaza'
),
(
60,
'Danyette Parmenter',
'7/5/2023',
'735 Jenna Terrace'
),
(
61,
'Brooks Licciardi',
'7/28/2023',
'01404 Waxwing Lane'
),
(
62,
'Hunt Trusler',
'6/20/2023',
'172 Hudson Crossing'
),
(
63,
'Euphemia Raywood',
'1/2/2024',
'7 Moland Park'
),
(
64,
'Barn Poyntz',
'10/9/2023',
'610 Lakewood Center'
),
(
65,
'Ethe Croston',
'11/11/2023',
'49 Kennedy Alley'
),
(
66,
'Farr Bruhnicke',
'3/26/2024',
'05 Arrowood Alley'
),
(
67,
'Ruth Blankau',
'2/14/2024',
'8683 Oakridge Pass'
),
(
68,
'Pearline Tubbles',
'11/17/2023',
'01122 Vidon Drive'
),
(
69,
'Des Penddreth',
'5/30/2024',
'87034 Melody Center'
),
(
70,
'Abram Paddeley',
'12/12/2023',
'97 Magdeline Avenue'
),
(
71,
'Corly Mc Meekin',
'10/31/2023',
'0 Forest Drive'
),
(
72,
'Arvie Daen',
'11/30/2023',
'063 Thierer Pass'
),
(
73,
'Karla Waryk',
'3/24/2024',
'072 Lindbergh Circle'
),
(
74,
'Axel Syson',
'9/16/2023',
'9880 Butternut Trail'
),
(
75,
'Elliot Beswick',
'11/13/2023',
'81686 Lakewood Way'
),
(
76,
'Stepha Jan',
'4/14/2024',
'3 Weeping Birch Place'
),
(
77,
'Ignace Rockey',
'11/25/2023',
'82131 Rieder Parkway'
),
(
78,
'Zelig Oughton',
'3/22/2024',
'5 School Avenue'
),
(
79,
'Madeleine Loudiane',
'7/9/2023',
'4 Vahlen Court'
),
(
80,
'Courtney Roke',
'1/6/2024',
'1 Donald Circle'
),
(
81,
'Cyrillus Jordon',
'11/1/2023',
'4229 Longview Court'
),
(
82,
'Matthaeus Batterham',
'11/5/2023',
'928 Kings Drive'
),
(
83,
'Rock Kellington',
'8/2/2023',
'5403 2nd Street'
),
(
84,
'Zolly Screase',
'7/24/2023',
'09057 Bayside Street'
),
(
85,
'Walden Sholl',
'10/30/2023',
'3082 Tomscot Terrace'
),
(
86,
'Julienne Corballis',
'3/4/2024',
'5 Johnson Alley'
),
(
87,
'Flemming Mecco',
'6/22/2023',
'99211 Killdeer Pass'
),
(
88,
'Aarika Garcia',
'2/2/2024',
'001 Kinsman Drive'
),
(
89,
'Marjory Traske',
'7/25/2023',
'37049 Manufacturers Center'
),
(
90,
'Ida Newlands',
'1/29/2024',
'00 Thierer Alley'
),
(
91,
'Letti Merrisson',
'7/27/2023',
'36 Green Plaza'
),
(92, 'Fran Bullene', '7/2/2023', '5 Bowman Plaza'),
(
93,
'Natala Harteley',
'1/22/2024',
'20 High Crossing Junction'
),
(
94,
'Golda Stout',
'1/7/2024',
'7 Bunker Hill Alley'
),
(
95,
'Stinky Le Grove',
'12/13/2023',
'415 Haas Plaza'
),
(
96,
'Nalani Ravenshear',
'3/14/2024',
'56132 Vera Street'
),
(
97,
'Georgia Mungham',
'1/1/2024',
'680 Acker Circle'
),
(
98,
'Elsworth Dearell',
'12/4/2023',
'0875 Springview Circle'
),
(
99,
'Philippe Madelin',
'11/2/2023',
'312 Morningstar Street'
),
(
100,
'Bing Everwin',
'6/22/2023',
'07218 Mitchell Park'
);
alter sequence orders_seq restart with 150;
-- create table goods (
-- id INT,
-- name VARCHAR(50),
-- price DECIMAL(5, 2)
-- );
insert into
goods (id, name, price)
values
(1, 'Happy Tears', 83.52),
(2, 'Hugo Pool', 66.69),
(3, 'Creation', 28.45),
(4, 'Trailer Park of Terror', 91.48),
(5, 'Very Annie Mary', 98.91),
(6, 'Prom', 98.99),
(7, 'Theremin: An Electronic Odyssey', 51.68),
(8, 'All In: The Poker Movie', 79.55),
(9, 'Bring It On: In It To Win It', 92.92),
(
10,
'Best of Youth, The (La meglio gioventù)',
3.81
),
(11, 'The Count of Monte Cristo', 76.65),
(12, 'Girl 6', 35.63),
(13, 'Helen', 29.14),
(14, 'Once Upon a Time (Der var engang)', 73.54),
(
15,
'Gendarme Gets Married, The (Le gendarme se marie)',
70.6
),
(16, 'Never Talk to Strangers', 63.84),
(
17,
'Eye for an Eye, An (Oeil pour oeil) (Eyes of the Sahara)',
57.64
),
(18, 'Unconditional', 28.72),
(19, 'People That Time Forgot, The', 2.27),
(
20,
'Bar at the Victoria Station, A (Bar na Victorii)',
98.53
),
(21, 'Where the Day Takes You', 58.68),
(22, 'City by the Sea', 43.62),
(23, 'Who Do I Gotta Kill?', 86.05),
(24, 'Babbitt', 65.25),
(25, 'Ride the High Country', 40.55),
(
26,
'Land of Plenty (Angst and Alienation in America)',
97.46
),
(27, 'Walk the Line', 74.77),
(28, 'Murder, He Says', 90.44),
(29, 'Elvis and Anabelle', 38.98),
(30, 'Payday', 28.18),
(31, 'I Saw Mommy Kissing Santa Claus', 10.24),
(32, 'Without Warning', 66.52),
(33, 'Havana', 59.55),
(
34,
'Exterminating Angel, The (Ángel exterminador, El)',
61.89
),
(35, 'Deadly Surveillance', 61.69),
(36, 'Heiress, The', 71.26),
(
37,
'Harvest: 3,000 Years (Mirt Sost Shi Amit)',
68.42
),
(38, 'My Best Friend''s Wife', 41.31),
(39, 'Deceiver', 4.68),
(40, 'The Challenge', 2.93),
(41, 'Susan Slept Here', 31.22),
(42, 'Seven Sinners', 26.95),
(43, 'Fatso', 89.43),
(44, 'Idiot''s Delight', 83.82),
(
45,
'Tale of the Wind, A (Histoire de vent, Une)',
82.99
),
(46, 'Marie Antoinette', 96.45),
(47, 'The Wonders', 48.4),
(48, 'Jurassic Park III', 78.6),
(49, 'Deep Red (Profondo rosso)', 95.6),
(50, 'Transylmania', 22.92),
(
51,
'Year My Parents Went on Vacation, The (O Ano em Que Meus Pais Saíram de Férias)',
62.8
),
(
52,
'Godzilla vs. Biollante (Gojira vs. Biorante) ',
96.99
),
(53, 'Caiman, The (Il caimano)', 13.89),
(54, 'Carry on Behind', 50.95),
(55, 'Whoregasm', 40.88),
(56, 'Crimes of Passion', 25.86),
(57, 'You Killed Me First', 97.09),
(58, 'MirrorMask', 58.85),
(59, 'Valet, The (La doublure)', 78.59),
(
60,
'Old Man Made in Spain (Abuelo made in Spain)',
88.96
),
(61, 'Holy Flying Circus', 18.16),
(62, 'Two Sisters from Boston', 90.45),
(63, 'Iceberg, L''', 6.11),
(
64,
'Guerrilla: The Taking of Patty Hearst',
5.36
),
(65, 'Mantrap', 11.41),
(
66,
'Moon in the Gutter, The (La lune dans le caniveau)',
31.36
),
(67, 'Odd Couple, The', 92.49),
(68, 'Man Without a Face, The', 24.27),
(
69,
'Four Nights with Anna (Cztery noce z Anna)',
52.27
),
(70, 'Lord Jim', 34.19),
(71, 'Pont du Nord, Le', 29.72),
(72, 'Invaders from Mars', 30.66),
(73, 'America''s Most Haunted Inns', 16.18),
(74, 'Welcome to Macintosh', 30.9),
(75, 'Head Above Water', 12.89),
(
76,
'Life and Times of Allen Ginsberg, The',
12.9
),
(77, 'Passion of the Christ, The', 15.9),
(78, 'Cobra', 74.99),
(
79,
'Affair of Love, An (Liaison pornographique, Une)',
87.45
),
(80, '13 Tzameti', 2.99),
(81, 'Executive Action', 81.28),
(82, 'Champion', 58.61),
(83, 'Felidae', 64.26),
(84, 'Thank You, Jeeves!', 14.96),
(
85,
'Off the Menu: The Last Days of Chasen''s',
82.53
),
(86, 'The Hunting Ground', 64.77),
(87, 'Bridge Too Far, A', 70.25),
(88, 'Contempt (Mépris, Le)', 99.3),
(89, 'Kermit''s Swamp Years', 4.86),
(90, 'Great Texas Dynamite Chase, The', 97.05),
(91, 'Cat Chaser', 40.41),
(92, 'Surf Ninjas', 16.97),
(
93,
'S21: The Khmer Rouge Death Machine (S-21, la machine de mort Khmère rouge)',
59.76
),
(
94,
'After School Special (a.k.a. Barely Legal)',
70.94
),
(95, 'Shooting Gallery', 92.74),
(96, 'Seaside (Bord de Mer)', 91.56),
(97, 'Animal House', 22.85),
(
98,
'Keep the River on Your Right: A Modern Cannibal Tale',
68.73
),
(99, 'Katalin Varga', 83.92),
(100, 'City of Angels', 76.91);
alter sequence goods_seq restart with 150;
-- create table order_line (
-- id INT,
-- order_id INT,
-- goods_id INT,
-- count INT
-- );
insert into
order_line (id, order_id, goods_id, count)
values
(1, 1, 18, 7),
(2, 1, 28, 8),
(3, 1, 41, 9),
(4, 1, 55, 6),
(5, 2, 59, 32),
(6, 2, 52, 66),
(7, 2, 3, 10),
(8, 2, 35, 6),
(9, 2, 35, 80),
(10, 2, 5, 76),
(11, 3, 32, 20),
(12, 3, 9, 96),
(13, 3, 96, 74),
(14, 3, 39, 14),
(15, 4, 16, 48),
(16, 4, 13, 54),
(17, 4, 42, 93),
(18, 5, 53, 10),
(19, 6, 19, 89),
(20, 5, 80, 95),
(21, 8, 20, 92),
(22, 4, 13, 100),
(23, 9, 16, 88),
(24, 3, 65, 27),
(25, 9, 38, 20),
(26, 2, 23, 85),
(27, 4, 45, 79),
(28, 4, 90, 43),
(29, 2, 30, 62),
(30, 3, 48, 26),
(31, 9, 8, 56),
(32, 6, 62, 3),
(33, 3, 52, 46),
(34, 2, 52, 22),
(35, 7, 67, 23),
(36, 9, 6, 22),
(37, 5, 76, 9),
(38, 9, 28, 52),
(39, 3, 56, 57),
(40, 4, 70, 64),
(41, 5, 86, 25),
(42, 9, 46, 31),
(43, 9, 81, 43),
(44, 3, 6, 46),
(45, 1, 56, 18),
(46, 7, 89, 37),
(47, 8, 66, 87),
(48, 8, 39, 33),
(49, 6, 54, 43),
(50, 7, 32, 81),
(51, 1, 94, 33),
(52, 6, 50, 46),
(53, 5, 71, 61),
(54, 2, 73, 40),
(55, 7, 22, 35),
(56, 1, 82, 72),
(57, 4, 54, 61),
(58, 1, 4, 28),
(59, 2, 88, 94),
(60, 6, 97, 54),
(61, 4, 20, 27),
(62, 7, 61, 43),
(63, 5, 26, 96),
(64, 8, 80, 89),
(65, 9, 26, 39),
(66, 6, 60, 55),
(67, 5, 20, 93),
(68, 2, 16, 10),
(69, 8, 15, 13),
(70, 8, 81, 49),
(71, 3, 25, 73),
(72, 6, 39, 75),
(73, 1, 79, 11),
(74, 4, 31, 40),
(75, 3, 3, 38),
(76, 6, 95, 71),
(77, 8, 12, 69),
(78, 4, 28, 86),
(79, 5, 14, 54),
(80, 6, 69, 73),
(81, 9, 50, 43),
(82, 3, 15, 81),
(83, 4, 10, 21),
(84, 3, 29, 46),
(85, 5, 91, 96),
(86, 8, 74, 35),
(87, 7, 77, 42),
(88, 2, 73, 36),
(89, 4, 6, 85),
(90, 8, 67, 29),
(91, 7, 86, 58),
(92, 3, 68, 51),
(93, 8, 96, 31),
(94, 4, 42, 8),
(95, 2, 72, 84),
(96, 8, 1, 61),
(97, 2, 37, 65),
(98, 1, 40, 69),
(99, 2, 9, 13),
(100, 7, 57, 72);
alter sequence order_line_seq restart with 150;
import { Subject } from 'rxjs';
import { Injectable, OnDestroy } from '@angular/core';
@Injectable()
export class AbstractBasicComponent implements OnDestroy {
protected destroy$ = new Subject();
public ngOnDestroy(): void {
this.destroy$.next(undefined);
this.destroy$.complete();
}
}
export interface User {
id: number;
name: string;
price: number;
}
export interface OrderLine {
id: number;
order_id: number;
goods_id: number;
count: number;
}
<app-orders-list [orders]="(orders$ | async)!"></app-orders-list>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { IndexPageComponent } from './index-page.component';
describe('IndexPageComponent', () => {
let component: IndexPageComponent;
let fixture: ComponentFixture<IndexPageComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [IndexPageComponent]
})
.compileComponents();
fixture = TestBed.createComponent(IndexPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import {Component, OnInit} from '@angular/core';
import {Observable} from "rxjs";
import {Order} from "../../core/model/order.model";
import {OrderService} from "../../core/service/order.service";
import {AbstractBasicComponent} from "../../core/abstract/abstract-component";
@Component({
selector: 'app-index-page',
templateUrl: './index-page.component.html',
styleUrl: './index-page.component.scss'
})
export class IndexPageComponent extends AbstractBasicComponent implements OnInit {
protected orders$!: Observable<Order[]>;
constructor(private orderService: OrderService) {
super();
}
ngOnInit() {
this.orders$ = this.orderService.getOrders();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment