-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from kakao-tech-campus-2nd-step3/Master
9조 BE 코드리뷰 4회차
- Loading branch information
Showing
60 changed files
with
1,248 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/helpmeCookies/global/entity/BaseTimeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.helpmeCookies.global.entity; | ||
|
||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Getter | ||
public abstract class BaseTimeEntity { | ||
|
||
@CreatedDate | ||
private LocalDateTime createdDate; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime modifiedDate; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/helpmeCookies/global/infra/CustomDatabaseHealthIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.helpmeCookies.global.infra; | ||
|
||
import com.helpmeCookies.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CustomDatabaseHealthIndicator implements HealthIndicator { | ||
|
||
private final UserRepository userRepository; | ||
@Override | ||
public Health health() { | ||
try { | ||
// 테이블이 존재하는지 확인하는 쿼리 (Users 테이블 사용) | ||
long count = userRepository.count(); | ||
// 테이블 존재 시 0 이상을 반환 | ||
return Health.up().withDetail("Users table exists, count: ", count).build(); | ||
} catch (Exception e) { | ||
// 테이블이 없거나 데이터베이스 연결에 문제가 있는 경우 | ||
return Health.down(e).withDetail("Users table", "Table missing or database issue") | ||
.build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/helpmeCookies/global/security/Oauth2CustomUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.helpmeCookies.global.security; | ||
|
||
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService; | ||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest; | ||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService; | ||
import org.springframework.security.oauth2.core.OAuth2AuthenticationException; | ||
import org.springframework.security.oauth2.core.user.OAuth2User; | ||
|
||
import com.helpmeCookies.user.service.UserService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class Oauth2CustomUserService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> { | ||
|
||
@Override | ||
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { | ||
final DefaultOAuth2UserService delegate = new DefaultOAuth2UserService(); | ||
OAuth2User oAuth2User = delegate.loadUser(userRequest); | ||
return oAuth2User; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/helpmeCookies/global/security/UserDetailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.helpmeCookies.global.security; | ||
|
||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.helpmeCookies.global.jwt.JwtUser; | ||
import com.helpmeCookies.user.entity.User; | ||
import com.helpmeCookies.user.entity.UserInfo; | ||
import com.helpmeCookies.user.repository.UserRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserDetailService { | ||
private final UserRepository userRepository; | ||
|
||
|
||
public JwtUser loadUserByEmail(String email,String nickname) throws UsernameNotFoundException { | ||
// 만약 유저가 존재하지 않는다면 저장 | ||
User user = userRepository.findByUserInfoEmail(email) | ||
.orElseGet(() -> { | ||
User newUser = User.builder() | ||
.userInfo(UserInfo.builder() | ||
.email(email) | ||
.build()) | ||
.nickname(nickname) | ||
.build(); | ||
return userRepository.save(newUser); | ||
}); | ||
return JwtUser.of(user.getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.