Skip to content

Commit c2c5ee5

Browse files
authored
Journal app (#882)
Journal app
1 parent 300ec41 commit c2c5ee5

File tree

9 files changed

+254
-0
lines changed

9 files changed

+254
-0
lines changed

tolldemo/journal-app/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
.mvn/**
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
17+
### IntelliJ IDEA ###
18+
.idea
19+
*.iws
20+
*.iml
21+
*.ipr
22+
23+
### NetBeans ###
24+
/nbproject/private/
25+
/nbbuild/
26+
/dist/
27+
/nbdist/
28+
/.nb-gradle/
29+
build/
30+
!**/src/main/**/build/
31+
!**/src/test/**/build/
32+
33+
### VS Code ###
34+
.vscode/

tolldemo/journal-app/pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.2.5</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example</groupId>
12+
<artifactId>journal-app</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>journal-app</name>
15+
<description>journal-app</description>
16+
<properties>
17+
<java.version>21</java.version>
18+
<oracle-springboot-starter.version>23.4.0</oracle-springboot-starter.version>
19+
</properties>
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-actuator</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-jdbc</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-web</artifactId>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.projectlombok</groupId>
36+
<artifactId>lombok</artifactId>
37+
<optional>true</optional>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.oracle.database.spring</groupId>
41+
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
42+
<version>${oracle-springboot-starter.version}</version>
43+
<type>pom</type>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-test</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-data-jpa</artifactId>
53+
</dependency>
54+
</dependencies>
55+
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-maven-plugin</artifactId>
61+
<configuration>
62+
<excludes>
63+
<exclude>
64+
<groupId>org.projectlombok</groupId>
65+
<artifactId>lombok</artifactId>
66+
</exclude>
67+
</excludes>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.journalapp;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class JournalAppApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(JournalAppApplication.class, args);
11+
}
12+
13+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.example.journalapp.controller;
2+
3+
import com.example.journalapp.model.Journal;
4+
//import com.example.journalapp.model.JournalJDBC;
5+
import com.example.journalapp.repository.JournalRepository;
6+
//import com.example.journalapp.service.JournalService;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestBody;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RestController;
14+
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
15+
16+
import java.net.URI;
17+
18+
@RestController
19+
@Slf4j
20+
@RequestMapping("api/v1")
21+
public class JournalController {
22+
23+
final JournalRepository journalRepository;
24+
25+
public JournalController(JournalRepository journalRepository) {
26+
this.journalRepository = journalRepository;
27+
}
28+
29+
// http POST :8080/api/v1/journal tagId=tagid licensePlate=licplate vehicleType=vtype tollDate=tdate
30+
@PostMapping("/journal")
31+
public ResponseEntity<Journal> createAccount(@RequestBody Journal journal) {
32+
log.info("Creating journal {}", journal);
33+
try {
34+
Journal newJournal = journalRepository.saveAndFlush(journal);
35+
URI location = ServletUriComponentsBuilder
36+
.fromCurrentRequest()
37+
.path("/{id}")
38+
.buildAndExpand(newJournal.getJournalId())
39+
.toUri();
40+
log.info("Successfully created journal {}", location);
41+
return ResponseEntity.created(location).build();
42+
} catch (Exception e) {
43+
return new ResponseEntity<>(journal, HttpStatus.INTERNAL_SERVER_ERROR);
44+
}
45+
}
46+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example.journalapp.model;
2+
3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.GenerationType;
7+
import jakarta.persistence.Id;
8+
import jakarta.persistence.Table;
9+
import lombok.AllArgsConstructor;
10+
import lombok.Data;
11+
import lombok.NoArgsConstructor;
12+
13+
@Entity
14+
@Table(name = "JOURNAL")
15+
@Data
16+
@NoArgsConstructor
17+
@AllArgsConstructor
18+
public class Journal {
19+
20+
@Id
21+
@Column(name = "JOURNAL_ID")
22+
@GeneratedValue(strategy = GenerationType.IDENTITY)
23+
private Integer journalId;
24+
@Column(name = "TAG_ID")
25+
private String tagId;
26+
@Column(name = "LICENSE_PLATE")
27+
private String licensePlate;
28+
@Column(name = "VEHICLE_TYPE")
29+
private String vehicleType;
30+
@Column(name = "TOLL_DATE")
31+
private String tollDate;
32+
33+
}
34+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.example.journalapp.repository;
2+
3+
import com.example.journalapp.model.Journal;
4+
//import com.example.journalapp.model.JournalJDBC;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
7+
public interface JournalRepository extends JpaRepository<Journal, Long> {
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
spring:
2+
application:
3+
name: journal-app
4+
threads:
5+
virtual:
6+
enabled: true
7+
jpa:
8+
hibernate:
9+
ddl-auto: validate
10+
11+
datasource:
12+
url: jdbc:oracle:thin:@//localhost:1521/orclpdb1
13+
username: tolldemo
14+
password: Welcome12345
15+
driver-class-name: oracle.jdbc.OracleDriver
16+
type: oracle.ucp.jdbc.PoolDataSource
17+
oracleucp:
18+
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
19+
connection-pool-name: JournalAppConnectionPool
20+
initial-pool-size: 15
21+
min-pool-size: 10
22+
max-pool-size: 30
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
drop table if exists journal cascade constraints;
2+
3+
create table if not exists journal (
4+
JOURNAL_ID NUMBER GENERATED ALWAYS AS IDENTITY (START WITH 1 CACHE 20),
5+
tag_id varchar2(64),
6+
license_plate varchar2(10),
7+
vehicle_type varchar2(10),
8+
toll_date varchar2(25)
9+
);
10+
11+
ALTER TABLE journal ADD CONSTRAINT jounral_PK PRIMARY KEY (journal_id) USING INDEX LOGGING;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.journalapp;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class JournalAppApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}

0 commit comments

Comments
 (0)