Skip to content
Open
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {

// gateway, eureka-client 의존성 추가
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
// implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'

compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/users/UsersApplication.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.users;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
//@EnableDiscoveryClient
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class UsersApplication {
public static void main(String[] args) {
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/com/users/token/business/TokenBusiness.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,20 @@ public class TokenBusiness {
* 3. converter -> token response로 변경
*/

public TokenResponse issueToken(User userEntity){
public TokenResponse issueToken(User userEntity) {

return Optional.ofNullable(userEntity)
.map(user -> {
return user.getId();
})
.map(user -> {
Integer id = userEntity.getId();
String role = userEntity.getRole().name();
Integer id = user.getId(); // user.getId()를 변수에 할당
String role = user.getRole().name();
var accessToken = tokenService.issueAccessToken(id);
var refreshToken = tokenService.issueRefreshToken(id);
return tokenConverter.toResponse(accessToken, refreshToken, role);
return tokenConverter.toResponse(accessToken, refreshToken, role, id); // id를 그대로 사용
})
.orElseThrow(
()-> new ApiException(ErrorCode.NULL_POINT)
);
.orElseThrow(() -> new ApiException(ErrorCode.NULL_POINT));
}


public String validationAccessToken(String accessToken){
var id = tokenService.validationToken(accessToken);
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public class TokenResponse {
private String refreshToken;

private String role;

private int id;
}
4 changes: 3 additions & 1 deletion src/main/java/com/users/token/converter/TokenConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class TokenConverter {
public TokenResponse toResponse(
TokenDto accessToken,
TokenDto refreshToken,
String role
String role,
int id
) {
Objects.requireNonNull(accessToken, () -> {
throw new ApiException(ErrorCode.NULL_POINT);
Expand All @@ -32,6 +33,7 @@ public TokenResponse toResponse(
.accessTokenExpiredAt(accessToken.getExpiredAt())
.refreshToken(refreshToken.getToken())
.role(role)
.id(id)
.build();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/users/user/db/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ public class User {
private LocalDateTime createdAt;
@UpdateTimestamp
@Column
private LocalDateTime LastAcceptedAt;
private LocalDateTime lastAcceptedAt;
}
2 changes: 1 addition & 1 deletion src/main/java/com/users/user/dto/UserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public class UserDto {
private String email;
private UserRole role;
private LocalDateTime createdat;
private LocalDateTime LastAcceptedat;
private LocalDateTime lastAcceptedat;
}
2 changes: 2 additions & 0 deletions src/main/java/com/users/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public User register(User user) {
user.setNickname(user.getNickname() != null ? user.getNickname() : user.getUsername());

user.setCreatedAt(LocalDateTime.now());

System.out.println(user.getUsername()+"//"+encodedPassword+"//");
return userRepository.save(user);
}

Expand Down
44 changes: 22 additions & 22 deletions src/main/resources/application.YAML
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#server:
# port: 8080
#
#spring:
# application:
# name: USERS
#
## eureka client 설정 추가
#eureka:
# client:
# register-with-eureka: true
# fetch-registry: true
# service-url:
# defaultZone: http://192.168.0.153:8088/eureka
#
# instance:
# instance-id: USERS:8080 # 고정 값으로 설정
# lease-renewal-interval-in-seconds: 10
# lease-expiration-duration-in-seconds: 30
#
# resources:
# static-locations: classpath:/static/
server:
port: 8080

spring:
application:
name: USERS

# eureka client 설정 추가
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://192.168.0.229:8088/eureka

instance:
instance-id: USERS:8080 # 고정 값으로 설정
lease-renewal-interval-in-seconds: 10
lease-expiration-duration-in-seconds: 30

resources:
static-locations: classpath:/static/
13 changes: 7 additions & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ jwt.secret=${USER_JWT_SECRET:defaultSecret}

# MariaDB
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=${USER_DB_URL}
spring.datasource.username=${USER_DB_USERNAME}
spring.datasource.password=${USER_DB_PASSWORD}

#spring.datasource.url=jdbc:mariadb://localhost:3306/users
#spring.datasource.username=root
#spring.datasource.password=1234
#spring.datasource.url=${USER_DB_URL}
#spring.datasource.username=${USER_DB_USERNAME}
#spring.datasource.password=${USER_DB_PASSWORD}

spring.datasource.url=jdbc:mariadb://localhost:3307/userdb
spring.datasource.username=root
spring.datasource.password=maria

# JPA
spring.jpa.hibernate.ddl-auto=update
Expand Down