Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@ public void decrement(String key) {
redisTemplate.opsForValue().decrement(key);
}

public Object getValue(String key) {
return redisTemplate.opsForValue().get(key);
}

public Long getSortedSetSize(String key) {
return redisTemplate.opsForZSet().size(key);
}

public Boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}

}
5 changes: 5 additions & 0 deletions common/dtos/src/main/java/user/LoginRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package user;

public record LoginRequest(String email, String password) {

}
5 changes: 0 additions & 5 deletions common/dtos/src/main/java/user/UserLookupRequest.java

This file was deleted.

6 changes: 5 additions & 1 deletion docker-compose-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ services:
- redis-master-3
- redis-replica-1
- redis-replica-2
- redis-replica-3
- redis-replica-3

networks:
redis:
driver: bridge
14 changes: 10 additions & 4 deletions gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,27 @@ ext {
}

dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation project(':common:caching')

// Cloud
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'

// Security
implementation 'org.springframework.boot:spring-boot-starter-security'

// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.0.2'

// Monitoring
implementation 'org.springframework.boot:spring-boot-starter-actuator'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'

implementation 'org.springframework.boot:spring-boot-starter-data-redis'
}

dependencyManagement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.ticketping.gateway;
package com.ticketPing.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan(basePackages = {"com.ticketPing.gateway", "caching"})
@EnableFeignClients
@SpringBootApplication
public class GatewayApplication {

public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.application.dto;
package com.ticketPing.gateway.application.dto;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.application.service;
package com.ticketPing.gateway.application.service;

public interface QueueCheckService {
boolean areTooManyWaitingUsers(String performanceId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ticketping.gateway.application.service;
package com.ticketPing.gateway.application.service;

import static com.ticketping.gateway.domain.utils.QueueTokenValueGenerator.generateTokenValue;
import static com.ticketPing.gateway.domain.utils.QueueTokenValueGenerator.generateTokenValue;

import com.ticketping.gateway.domain.repository.QueueCheckRepository;
import com.ticketPing.gateway.domain.repository.QueueCheckRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.domain.repository;
package com.ticketPing.gateway.domain.repository;

public interface QueueCheckRepository {
int getAvailableSeats(String performanceId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.ticketping.gateway.domain.utils;
package com.ticketPing.gateway.domain.utils;

import static com.ticketping.gateway.infrastructure.enums.RedisKeyPrefix.TOKEN_VALUE;
import static com.ticketping.gateway.infrastructure.utils.ConfigHolder.tokenValueSecretKey;
import static com.ticketPing.gateway.infrastructure.enums.RedisKeyPrefix.TOKEN_VALUE;
import static com.ticketPing.gateway.infrastructure.utils.ConfigHolder.tokenValueSecretKey;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ticketping.gateway.exception;
package com.ticketPing.gateway.exception;

import com.ticketping.gateway.presentation.cases.ErrorCase;
import com.ticketPing.gateway.presentation.cases.ErrorCase;
import lombok.Getter;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.infrastructure.config;
package com.ticketPing.gateway.infrastructure.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.ticketPing.gateway.infrastructure.config;

import com.ticketPing.gateway.infrastructure.config.filter.QueueCheckFilter;
import lombok.RequiredArgsConstructor;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class RouteConfig {

private final QueueCheckFilter queueCheckFilter;

@Bean
public RouteLocator gatewayRoutes(RouteLocatorBuilder builder) {
return builder.routes()

// API Routing
.route("auth-service", r -> r.path("/api/v1/auth/**")
.uri("lb://auth"))
.route("user-service", r -> r.path("/api/v1/users/**")
.uri("lb://user"))
.route("performance-service", r -> r.path(
"/api/v1/performances/**", "/api/v1/schedules/**", "/api/v1/seats/**")
.uri("lb://performance"))
.route("order-service", r -> r.path("/api/v1/orders/**")
.uri("lb://order"))
.route("payment-service", r -> r.path("/api/v1/payments/**")
.uri("lb://payment"))
.route("queue-manage-service", r -> r.path("/api/v1/waiting-queue/**", "/api/v1/working-queue/**")
.uri("lb://queue-manage"))

// Swagger Routing
.route("auth-docs", r -> r.path("/v3/api-docs/auth-service")
.filters(f -> f.rewritePath("/v3/api-docs/auth-service", "/v3/api-docs"))
.uri("lb://auth"))
.route("user-docs", r -> r.path("/v3/api-docs/user-service")
.filters(f -> f.rewritePath("/v3/api-docs/user-service", "/v3/api-docs"))
.uri("lb://user"))
.route("performance-docs", r -> r.path("/v3/api-docs/performance-service")
.filters(f -> f.rewritePath("/v3/api-docs/performance-service", "/v3/api-docs"))
.uri("lb://performance"))
.route("order-docs", r -> r.path("/v3/api-docs/order-service")
.filters(f -> f.rewritePath("/v3/api-docs/order-service", "/v3/api-docs"))
.uri("lb://order"))
.route("payment-docs", r -> r.path("/v3/api-docs/payment-service")
.filters(f -> f.rewritePath("/v3/api-docs/payment-service", "/v3/api-docs"))
.uri("lb://payment"))
.route("queue-manage-docs", r -> r.path("/v3/api-docs/queue-manage-service")
.filters(f -> f.rewritePath("/v3/api-docs/queue-manage-service", "/v3/api-docs"))
.uri("lb://queue-manage"))

.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ticketPing.gateway.infrastructure.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.properties.SwaggerUiConfigParameters;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Objects;

@Configuration
@RequiredArgsConstructor
public class SwaggerConfig {

private final RouteLocator routeLocator;

@Bean
public CommandLineRunner openApiGroups(SwaggerUiConfigParameters swaggerUiParameters) {
return args -> Objects.requireNonNull(routeLocator.getRoutes().collectList().block())
.stream()
.filter(route -> route.getId() != null && !route.getId().contains("-docs")) // API 문서 라우트 제외
.forEach(route -> {
String name = route.getId();
swaggerUiParameters.addGroup(name);
});
}

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("TicketPing API")
.version("1.0"));
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.ticketping.gateway.infrastructure.config.filter;
package com.ticketPing.gateway.infrastructure.config.filter;

import static com.ticketping.gateway.presentation.cases.FilterErrorCase.PERFORMANCE_SOLD_OUT;
import static com.ticketping.gateway.presentation.cases.FilterErrorCase.TOO_MANY_WAITING_USERS;
import static com.ticketping.gateway.presentation.cases.FilterErrorCase.WORKING_TOKEN_NOT_FOUND;
import static com.ticketPing.gateway.presentation.cases.FilterErrorCase.PERFORMANCE_SOLD_OUT;
import static com.ticketPing.gateway.presentation.cases.FilterErrorCase.TOO_MANY_WAITING_USERS;
import static com.ticketPing.gateway.presentation.cases.FilterErrorCase.WORKING_TOKEN_NOT_FOUND;

import com.ticketping.gateway.application.service.QueueCheckService;
import com.ticketping.gateway.infrastructure.enums.APIType;
import com.ticketping.gateway.infrastructure.utils.ResponseWriter;
import com.ticketPing.gateway.application.service.QueueCheckService;
import com.ticketPing.gateway.infrastructure.enums.APIType;
import com.ticketPing.gateway.infrastructure.utils.ResponseWriter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.infrastructure.enums;
package com.ticketPing.gateway.infrastructure.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.infrastructure.enums;
package com.ticketPing.gateway.infrastructure.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.ticketping.gateway.infrastructure.repository;
package com.ticketPing.gateway.infrastructure.repository;

import static com.ticketping.gateway.infrastructure.enums.RedisKeyPrefix.AVAILABLE_SEATS;
import static com.ticketping.gateway.infrastructure.enums.RedisKeyPrefix.WAITING_QUEUE;
import static com.ticketPing.gateway.infrastructure.enums.RedisKeyPrefix.AVAILABLE_SEATS;
import static com.ticketPing.gateway.infrastructure.enums.RedisKeyPrefix.WAITING_QUEUE;

import com.ticketping.gateway.domain.repository.QueueCheckRepository;
import caching.repository.RedisRepository;
import com.ticketPing.gateway.domain.repository.QueueCheckRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.ticketping.gateway.infrastructure.security;
package com.ticketPing.gateway.infrastructure.security;

import com.ticketping.gateway.application.dto.UserCache;
import com.ticketping.gateway.exception.ApplicationException;
import com.ticketping.gateway.infrastructure.repository.RedisRepository;
import com.ticketping.gateway.infrastructure.utils.ResponseWriter;
import com.ticketping.gateway.presentation.cases.SecurityErrorCase;
import caching.repository.RedisRepository;
import com.ticketPing.gateway.application.dto.UserCache;
import com.ticketPing.gateway.exception.ApplicationException;
import com.ticketPing.gateway.infrastructure.utils.ResponseWriter;
import com.ticketPing.gateway.presentation.cases.SecurityErrorCase;
import io.jsonwebtoken.*;
import io.jsonwebtoken.security.Keys;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.infrastructure.security;
package com.ticketPing.gateway.infrastructure.security;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -27,10 +27,11 @@ public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
.pathMatchers("/api/v1/users/signup").permitAll()
.pathMatchers(HttpMethod.GET, "/api/v1/performances/**").permitAll()
.pathMatchers(HttpMethod.GET, "/api/v1/schedules/{scheduleId}").permitAll()
.pathMatchers("/api/v1/payments/**").permitAll()
.pathMatchers("/actuator/prometheus").permitAll()
.anyExchange().authenticated() // 그 외 모든 경로는 인증 필요
.pathMatchers("/swagger-ui/**", "/v3/api-docs/**", "/webjars/**").permitAll()
.anyExchange().permitAll()
)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.infrastructure.utils;
package com.ticketPing.gateway.infrastructure.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ticketping.gateway.infrastructure.utils;
package com.ticketPing.gateway.infrastructure.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ticketping.gateway.presentation.response.CustomErrorResponse;
import com.ticketping.gateway.presentation.cases.FilterErrorCase;
import com.ticketPing.gateway.presentation.response.CustomErrorResponse;
import com.ticketPing.gateway.presentation.cases.FilterErrorCase;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.http.MediaType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.presentation.cases;
package com.ticketPing.gateway.presentation.cases;

import org.springframework.http.HttpStatus;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.presentation.cases;
package com.ticketPing.gateway.presentation.cases;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.presentation.cases;
package com.ticketPing.gateway.presentation.cases;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ticketping.gateway.presentation.response;
package com.ticketPing.gateway.presentation.response;

import org.springframework.http.HttpStatus;

Expand Down
Loading