Skip to content

Commit dd39328

Browse files
committed
update
1 parent 8d25592 commit dd39328

27 files changed

+150
-84
lines changed

.DS_Store

6 KB
Binary file not shown.

Dockerfile

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
1-
## start with a base image
2-
FROM maven:latest
3-
VOLUME /tmp
4-
ARG PROJECT_VERSION=0.0.1
1+
#FROM maven:latest
2+
#VOLUME /tmp
3+
#ARG PROJECT_VERSION=0.0.1
4+
#RUN mkdir -p /home/app
5+
#WORKDIR /home/app
6+
#ENV SPRING_PROFILES_ACTIVE application
7+
#COPY . .
8+
#RUN mvn clean package
9+
#EXPOSE 8888
10+
#ENTRYPOINT ["java", "-jar", "target/ticket-booking-api-0.0.1-SNAPSHOT.jar"]
11+
12+
# Sử dụng một phiên bản cụ thể của Maven
13+
FROM maven:3.8.4-openjdk-8 AS builder
14+
15+
# Tạo thư mục app và thiết lập nó làm thư mục làm việc
516
RUN mkdir -p /home/app
617
WORKDIR /home/app
7-
ENV SPRING_PROFILES_ACTIVE application
8-
COPY ./ .
9-
ADD target/ticket-booking-api-0.0.1-SNAPSHOT.jar ticket-booking-api-0.0.1-SNAPSHOT.jar
10-
EXPOSE 8888
11-
ENTRYPOINT ["java", "-jar", "ticket-booking-api-0.0.1-SNAPSHOT.jar"]
12-
CMD ["mvn", "spring-boot:run"]
18+
19+
# Sao chép toàn bộ mã nguồn vào thư mục làm việc
20+
COPY . .
21+
22+
# Sử dụng Maven Wrapper để build ứng dụng
23+
RUN chmod +x mvnw
24+
RUN ./mvnw clean package
25+
26+
# Sử dụng hình ảnh Java để chạy ứng dụng
27+
FROM openjdk:8-jre-slim
28+
29+
# Sao chép tập tin JAR đã được build từ builder stage
30+
COPY --from=builder /home/app/target/ticket-booking-api-0.0.1-SNAPSHOT.jar /app.jar
31+
32+
# Mở cổng 8080
33+
EXPOSE 8080
34+
35+
# Chạy ứng dụng khi container được khởi động
36+
CMD ["java", "-jar", "/app.jar"]
37+

booking_ticket.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11

2-
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
3-
SET AUTOCOMMIT = 0;
4-
START TRANSACTION;
5-
SET time_zone = "+00:00";
6-
72
-- Table structure for table `booking`
83
CREATE TABLE `booking` (
94
`booking_id` int(11) NOT NULL,

docker-compose.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,3 @@ services:
2727
entrypoint: [ "java", "-jar", "ticket-booking-api-0.0.1-SNAPSHOT.jar" ]
2828
depends_on:
2929
- mysql
30-
build:
31-
context: .
32-
args:
33-
PROJECT_VERSION: 0.0.1

pom.xml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,53 @@
1313
<version>0.0.1-SNAPSHOT</version>
1414
<name>ticket-booking-api</name>
1515
<description>Booking ticket cinema api</description>
16-
1716
<properties>
1817
<java.version>1.8</java.version>
1918
</properties>
20-
2119
<dependencies>
2220
<dependency>
2321
<groupId>org.springframework.boot</groupId>
2422
<artifactId>spring-boot-starter-web</artifactId>
2523
</dependency>
26-
2724
<dependency>
2825
<groupId>mysql</groupId>
2926
<artifactId>mysql-connector-java</artifactId>
3027
<scope>runtime</scope>
3128
</dependency>
32-
3329
<dependency>
3430
<groupId>io.springfox</groupId>
3531
<artifactId>springfox-swagger2</artifactId>
3632
<version>2.6.1</version>
3733
</dependency>
38-
3934
<dependency>
4035
<groupId>io.springfox</groupId>
4136
<artifactId>springfox-swagger-ui</artifactId>
4237
<version>2.6.1</version>
4338
</dependency>
44-
45-
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
4639
<dependency>
4740
<groupId>org.springframework.boot</groupId>
4841
<artifactId>spring-boot-starter-security</artifactId>
4942
</dependency>
50-
51-
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
5243
<dependency>
5344
<groupId>io.jsonwebtoken</groupId>
5445
<artifactId>jjwt</artifactId>
5546
<version>0.9.1</version>
5647
</dependency>
57-
5848
<dependency>
5949
<groupId>org.springframework.boot</groupId>
6050
<artifactId>spring-boot-starter-data-jpa</artifactId>
6151
</dependency>
62-
63-
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
6452
<dependency>
6553
<groupId>org.projectlombok</groupId>
6654
<artifactId>lombok</artifactId>
6755
<version>1.18.28</version>
6856
<scope>provided</scope>
6957
</dependency>
70-
71-
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
7258
<dependency>
7359
<groupId>javax.validation</groupId>
7460
<artifactId>validation-api</artifactId>
7561
<version>2.0.1.Final</version>
7662
</dependency>
77-
7863
<dependency>
7964
<groupId>org.springframework.boot</groupId>
8065
<artifactId>spring-boot-starter-test</artifactId>
@@ -86,14 +71,23 @@
8671
</exclusion>
8772
</exclusions>
8873
</dependency>
89-
9074
</dependencies>
9175

76+
<!-- <build>-->
77+
<!-- <plugins>-->
78+
<!-- <plugin>-->
79+
<!-- <groupId>org.springframework.boot</groupId>-->
80+
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
81+
<!-- </plugin>-->
82+
<!-- </plugins>-->
83+
<!-- </build>-->
84+
9285
<build>
9386
<plugins>
9487
<plugin>
95-
<groupId>org.springframework.boot</groupId>
96-
<artifactId>spring-boot-maven-plugin</artifactId>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-compiler-plugin</artifactId>
90+
<version>3.8.1</version> <!-- Cập nhật lên phiên bản mới nhất -->
9791
</plugin>
9892
</plugins>
9993
</build>

src/main/java/com/hoangtien2k3/ticketbookingapi/config/JwtRequestFilter.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,22 @@ protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServl
5151
}
5252

5353
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
54-
5554
UserDetails userDetails = this.jwtUserDetailsService.loadUserByUsername(username);
5655

5756
if (jwtTokenUtil.validateToken(jwtToken, userDetails)) {
58-
5957
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(
60-
userDetails, null, userDetails.getAuthorities());
61-
62-
usernamePasswordAuthenticationToken
63-
.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest));
64-
58+
userDetails,
59+
null,
60+
userDetails.getAuthorities()
61+
);
62+
63+
usernamePasswordAuthenticationToken.setDetails(
64+
new WebAuthenticationDetailsSource().buildDetails(httpServletRequest)
65+
);
6566
SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken);
6667
}
6768
}
69+
6870
filterChain.doFilter(httpServletRequest, httpServletResponse);
6971
}
7072
}

src/main/java/com/hoangtien2k3/ticketbookingapi/config/JwtToken.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ private Boolean isTokenExpired(String token) {
4848
final Date expiration = getExpirationDateFromToken(token);
4949

5050
return expiration.before(new Date());
51-
5251
}
5352

5453
private Date getExpirationDateFromToken(String token) {
@@ -60,25 +59,19 @@ public String generateToken(UserDetails userDetails) {
6059
return doGenerateToken(claims, userDetails.getUsername());
6160
}
6261

63-
6462
private String doGenerateToken(Map<String, Object> claims, String subject) {
65-
6663
return Jwts
6764
.builder()
6865
.setClaims(claims)
6966
.setSubject(subject)
7067
.setIssuedAt(new Date(System.currentTimeMillis()))
7168
.setExpiration(new Date(System.currentTimeMillis() + JWT_TOKEN_VALIDITY * 1000))
7269
.signWith(SignatureAlgorithm.HS512, secret).compact();
73-
7470
}
7571

76-
7772
public Boolean validateToken(String token, UserDetails userDetails) {
78-
7973
final String username = getUsernameFromToken(token);
8074
return (username.equals(userDetails.getUsername()) && !isTokenExpired(token));
81-
8275
}
8376

8477
}

src/main/java/com/hoangtien2k3/ticketbookingapi/config/WebSecurityConfig.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public JwtAuthenticationEntryPoint jwtAuthenticationEntryPointBean() throws Exce
4040
return new JwtAuthenticationEntryPoint();
4141
}
4242

43-
4443
@Bean
4544
public PasswordEncoder passwordEncoder() {
4645
return new BCryptPasswordEncoder();
@@ -55,9 +54,8 @@ public AuthenticationManager authenticationManagerBean() throws Exception {
5554

5655
@Override
5756
protected void configure(HttpSecurity httpSecurity) throws Exception {
58-
59-
httpSecurity.csrf().disable()
60-
57+
httpSecurity
58+
.csrf().disable()
6159
.authorizeRequests()
6260
.antMatchers(
6361
"/authenticate",
@@ -77,12 +75,12 @@ protected void configure(HttpSecurity httpSecurity) throws Exception {
7775
"/webjars/**"
7876
).permitAll().anyRequest().authenticated()
7977
.and()
80-
.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
78+
.exceptionHandling()
79+
.authenticationEntryPoint(jwtAuthenticationEntryPoint)
8180
.and()
8281
.sessionManagement()
8382
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
8483

8584
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
86-
8785
}
8886
}

src/main/java/com/hoangtien2k3/ticketbookingapi/controller/UserController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ public ResponseEntity<?> loginUser(@Valid @RequestBody HashMap<String, String> r
3939
return ResponseEntity.ok(userService.loginUser(request.get("username"), request.get("password")));
4040
}
4141

42+
// get info from token
4243
@GetMapping("/info")
4344
public ResponseEntity<?> getInfo(Authentication authentication){
4445
return ResponseEntity.ok(userService.getInfo(authentication));
4546
}
47+
4648
}

src/main/java/com/hoangtien2k3/ticketbookingapi/entity/Book.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@
1414
@Table(name = "booking")
1515
public class Book {
1616
@Id
17-
@GeneratedValue(strategy = GenerationType.AUTO)
17+
@GeneratedValue(strategy = GenerationType.IDENTITY)
1818
@Column(name = "booking_id")
1919
private int bookingId;
20+
2021
@Column(name = "user_id")
2122
private int userId;
23+
2224
@Column(name = "schedule_id")
2325
private int scheduleId;
26+
2427
@Column(name = "seat_id")
2528
private int seatId;
29+
2630
@Column(name = "price")
2731
private double price;
32+
2833
@Column(name = "seat_status")
2934
private int seatStatus;
3035
}

0 commit comments

Comments
 (0)