-
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 #66 from yooonwodyd/weekly
[yooonwodyd-> weekly] 카카오 로그인 및 유저 컨트롤러 리팩토링
- Loading branch information
Showing
45 changed files
with
934 additions
and
156 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
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; | ||
} |
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; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
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) throws UsernameNotFoundException { | ||
// 만약 유저가 존재하지 않는다면 저장 | ||
User user = userRepository.findByUserInfoEmail(email) | ||
.orElseGet(() -> { | ||
User newUser = User.builder() | ||
.userInfo(UserInfo.builder().email(email).build()) | ||
.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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/helpmeCookies/product/controller/docs/ProductApiDocs.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.product.controller.docs; | ||
|
||
import com.helpmeCookies.product.dto.ProductPage.Paging; | ||
import com.helpmeCookies.product.util.ProductSort; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Tag(name = "상품 관련 기능", description = "상품 관련 API") | ||
public interface ProductApiDocs { | ||
|
||
@Operation(summary = "상품 검색") | ||
ResponseEntity<Paging> getProductsByPage( | ||
String query, | ||
@Parameter(description = "default value 20") int size, | ||
int page, | ||
ProductSort productSort | ||
); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/helpmeCookies/product/dto/ProductPage.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,46 @@ | ||
package com.helpmeCookies.product.dto; | ||
|
||
import com.helpmeCookies.product.repository.dto.ProductSearch; | ||
import java.util.List; | ||
import org.springframework.data.domain.Page; | ||
|
||
public class ProductPage { | ||
|
||
public record Info( | ||
Long id, | ||
String name, | ||
String artist, | ||
Long price, | ||
String thumbnailUrl | ||
) { | ||
public static Info from(ProductSearch productSearch) { | ||
return new Info( | ||
productSearch.getId(), | ||
productSearch.getName(), | ||
productSearch.getArtist(), | ||
productSearch.getPrice(), | ||
productSearch.getThumbnailUrl() | ||
); | ||
} | ||
|
||
public static List<Info> of(List<ProductSearch> content) { | ||
return content.stream() | ||
.map(Info::from) | ||
.toList(); | ||
} | ||
} | ||
|
||
public record Paging ( | ||
boolean hasNext, | ||
List<Info> products | ||
) { | ||
|
||
public static Paging from(Page<ProductSearch> productPage) { | ||
return new Paging( | ||
productPage.hasNext(), | ||
Info.of(productPage.getContent()) | ||
); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.