Skip to content

Commit

Permalink
๐Ÿ”’๏ธ ์„ค์ • ํŒŒ์ผ ๊ตฌ์„ฑ ๋ณ€๊ฒฝ (#9)
Browse files Browse the repository at this point in the history
* ๐Ÿ™ˆ .env ํŒŒ์ผ ์ถ”์ ํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •

* ๐Ÿ”ง ๊ตฌ์„ฑ ํŒŒ์ผ ์ •๋ฆฌ

* ๐Ÿ”ง Profile ๋“ฑ๋ก (local, prod)

* ๐ŸŽจ User ์—”ํ‹ฐํ‹ฐ ๊ด€๋ จ ๋ณ€๊ฒฝ
  • Loading branch information
MinseoKangQ authored Oct 27, 2024
1 parent 9b68b6a commit b826bc0
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

### .env ###
.env.*
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {

@CreatedDate
@Column(name = "created_at")
private LocalDateTime createAt;

@LastModifiedDate
@Column(name = "modified_at")
private LocalDateTime modifyAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.example.gather_back_end.util.entity.BaseEntity;

@Entity
@Getter
@Setter
public class UserEntity {
@NoArgsConstructor(access = AccessLevel.PUBLIC)
public class User extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.example.gather_back_end.util.jwt.repository;

import org.example.gather_back_end.util.jwt.entity.UserEntity;
import org.example.gather_back_end.util.jwt.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<UserEntity, Long> {
public interface UserRepository extends JpaRepository<User, Long> {

UserEntity findByUsername(String username);
User findByUsername(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.example.gather_back_end.util.jwt.dto.GoogleResponse;
import org.example.gather_back_end.util.jwt.dto.OAuth2Response;
import org.example.gather_back_end.util.jwt.dto.UserDto;
import org.example.gather_back_end.util.jwt.entity.UserEntity;
import org.example.gather_back_end.util.jwt.entity.User;
import org.example.gather_back_end.util.jwt.repository.UserRepository;
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
Expand Down Expand Up @@ -40,17 +40,17 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
return null;
}
String username = oAuth2Response.getProvider()+" "+oAuth2Response.getProviderId();
UserEntity existData = userRepository.findByUsername(username);
User existData = userRepository.findByUsername(username);

if (existData == null) {

UserEntity userEntity = new UserEntity();
userEntity.setUsername(username);
userEntity.setEmail(oAuth2Response.getEmail());
userEntity.setName(oAuth2Response.getName());
userEntity.setRole("ROLE_USER");
User user = new User();
user.setUsername(username);
user.setEmail(oAuth2Response.getEmail());
user.setName(oAuth2Response.getName());
user.setRole("ROLE_USER");

userRepository.save(userEntity);
userRepository.save(user);

UserDto userDto = new UserDto();
userDto.setUsername(username);
Expand Down
13 changes: 0 additions & 13 deletions src/main/resources/application-local.yml

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/resources/application.properties

This file was deleted.

52 changes: 50 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,53 @@ spring:
application:
name: gather_back_end

profiles:
active: local
datasource:
url: jdbc:mysql://localhost:3306/gather
username: ${DATABASE_USERNAME}
password: ${DATABASE_PASSWORD}

jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
dialect: org.hibernate.dialect.MySQLDialect

jwt:
secret: ${JWT_SECRET}

doc:
api-docs:
enabled: true
path: /api-docs
swagger-ui:
enabled: true
path: /swagger-ui.html
paths-to-match:
- /api/**

security:
oauth2:
client:
registration:
google:
client-name: ${GOOGLE_CLIENT_NAME}
client-id: ${GOOGLE_CLIENT_ID}
client-secret: ${GOOGLE_CLIENT_SECRET}
redirect-uri: ${GOOGLE_REDIRECT_URI}
authorization-grant-type: ${GOOGLE_AUTHORIZATION_GRANT_TYPE}
scope: ${GOOGLE_SCOPE}

--- ### local ํ™˜๊ฒฝ ์„ค์ •
spring:
config:
activate:
on-profile: local

--- ### prod ํ™˜๊ฒฝ ์„ค์ •
spring:
config:
activate:
on-profile: prod

0 comments on commit b826bc0

Please sign in to comment.