-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
소셜 기능 (찜하기, 조회수) 구현 #20
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/trade_ham/domain/auth/controller/UserController.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.trade_ham.domain.auth.controller; | ||
|
||
import com.trade_ham.domain.auth.dto.CustomOAuth2User; | ||
import com.trade_ham.domain.auth.dto.UserUpdateDTO; | ||
import com.trade_ham.domain.auth.service.UserService; | ||
import com.trade_ham.global.common.response.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@RequestMapping("/api/v1") | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
@PostMapping("/user") | ||
public ApiResponse<UserUpdateDTO> updateUser(@RequestBody UserUpdateDTO userUpdateDTO, @AuthenticationPrincipal CustomOAuth2User oAuth2User) { | ||
Long sellerId = oAuth2User.getId(); | ||
// ID가 제대로 나오는지 확인 | ||
log.info("OAuth2 User ID: {}", oAuth2User.getId()); | ||
|
||
UserUpdateDTO userResponse = userService.updateUser(sellerId, userUpdateDTO); | ||
|
||
return ApiResponse.success(userResponse); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/trade_ham/domain/auth/dto/UserUpdateDTO.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,11 @@ | ||
package com.trade_ham.domain.auth.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class UserUpdateDTO { | ||
private String account; // 계좌번호 | ||
private String realname; | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/trade_ham/domain/auth/service/UserService.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.trade_ham.domain.auth.service; | ||
|
||
import com.trade_ham.domain.auth.dto.UserUpdateDTO; | ||
import com.trade_ham.domain.auth.entity.UserEntity; | ||
import com.trade_ham.domain.auth.repository.UserRepository; | ||
import com.trade_ham.global.common.exception.ErrorCode; | ||
import com.trade_ham.global.common.exception.ResourceNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
public UserUpdateDTO updateUser(Long sellerId, UserUpdateDTO userUpdateDTO) { | ||
UserEntity userEntity = userRepository.findById(sellerId) | ||
.orElseThrow(() -> new ResourceNotFoundException(ErrorCode.USER_NOT_FOUND)); | ||
|
||
userEntity.setAccount(userUpdateDTO.getAccount()); | ||
userEntity.setNickname(userUpdateDTO.getRealname()); | ||
|
||
userRepository.save(userEntity); | ||
|
||
return userUpdateDTO; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/trade_ham/domain/locker/controller/NotificationController.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,29 @@ | ||
package com.trade_ham.domain.locker.controller; | ||
|
||
import com.trade_ham.domain.auth.dto.CustomOAuth2User; | ||
import com.trade_ham.domain.locker.entity.NotificationEntity; | ||
import com.trade_ham.domain.locker.service.NotificationService; | ||
import com.trade_ham.global.common.response.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/notification") | ||
public class NotificationController { | ||
|
||
private final NotificationService notificationService; | ||
|
||
@GetMapping() | ||
public ApiResponse<List<NotificationEntity>> getAllNotifications(@AuthenticationPrincipal CustomOAuth2User oAuth2User) { | ||
Long userId = oAuth2User.getId(); | ||
|
||
List<NotificationEntity> notifications = notificationService.allNotification(userId); | ||
return ApiResponse.success(notifications); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/trade_ham/domain/locker/dto/NotificationBuyerDTO.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,13 @@ | ||
package com.trade_ham.domain.locker.dto; | ||
|
||
import com.trade_ham.domain.auth.entity.UserEntity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class NotificationBuyerDTO { | ||
private String message; | ||
private boolean isRead; | ||
private UserEntity userId; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/trade_ham/domain/locker/dto/NotificationLockerDTO.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,15 @@ | ||
package com.trade_ham.domain.locker.dto; | ||
|
||
import com.trade_ham.domain.auth.entity.UserEntity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class NotificationLockerDTO { | ||
private String message; | ||
private Long lockerId; | ||
private String lockerPassword; | ||
private boolean isRead; | ||
private UserEntity userId; | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/trade_ham/domain/locker/entity/NotificationEntity.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,51 @@ | ||
package com.trade_ham.domain.locker.entity; | ||
|
||
import com.trade_ham.domain.auth.entity.UserEntity; | ||
import com.trade_ham.domain.locker.dto.NotificationBuyerDTO; | ||
import com.trade_ham.domain.locker.dto.NotificationLockerDTO; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Getter | ||
public class NotificationEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "notification_id") | ||
private Long id; | ||
|
||
//seller | ||
@Column(name = "locker_id") | ||
private Long lockerId; | ||
|
||
@Column(name = "locker_password") | ||
private String lockerPassword; | ||
|
||
// common | ||
private String message; | ||
|
||
@Setter | ||
private boolean isRead; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
private UserEntity user; | ||
|
||
// 판매자 전용 알림 | ||
public NotificationEntity(NotificationLockerDTO notificationLockerDTO) { | ||
this.message = notificationLockerDTO.getMessage(); | ||
this.lockerId = notificationLockerDTO.getLockerId(); | ||
this.lockerPassword = notificationLockerDTO.getLockerPassword(); | ||
this.isRead = notificationLockerDTO.isRead(); | ||
this.user = notificationLockerDTO.getUserId(); | ||
} | ||
|
||
// 구매자 전용 알림 | ||
public NotificationEntity(NotificationBuyerDTO NotificationBuyerDTO) { | ||
this.message = NotificationBuyerDTO.getMessage(); | ||
this.isRead = NotificationBuyerDTO.isRead(); | ||
this.user = NotificationBuyerDTO.getUserId(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/trade_ham/domain/locker/repository/NotificationRepository.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,12 @@ | ||
package com.trade_ham.domain.locker.repository; | ||
|
||
import com.trade_ham.domain.auth.entity.UserEntity; | ||
import com.trade_ham.domain.locker.entity.NotificationEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface NotificationRepository extends JpaRepository<NotificationEntity, Long> { | ||
List<NotificationEntity> findByUser_IdAndIsReadFalse(Long Id); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/trade_ham/domain/locker/service/NotificationService.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.trade_ham.domain.locker.service; | ||
|
||
import com.trade_ham.domain.locker.entity.NotificationEntity; | ||
import com.trade_ham.domain.locker.repository.NotificationRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class NotificationService { | ||
|
||
private final NotificationRepository notificationRepository; | ||
|
||
@Transactional | ||
public List<NotificationEntity> allNotification(Long userId) { | ||
List<NotificationEntity> notifications = notificationRepository.findByUser_IdAndIsReadFalse(userId); | ||
|
||
for(NotificationEntity notificationEntity : notifications) { | ||
notificationEntity.setRead(true); | ||
} | ||
|
||
return notificationRepository.saveAll(notifications); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/trade_ham/domain/product/controller/LikeController.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,49 @@ | ||
package com.trade_ham.domain.product.controller; | ||
|
||
import com.trade_ham.domain.auth.dto.CustomOAuth2User; | ||
import com.trade_ham.domain.product.entity.LikeEntity; | ||
import com.trade_ham.domain.product.service.LikeService; | ||
import com.trade_ham.global.common.response.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@Controller | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class LikeController { | ||
|
||
private final LikeService likeService; | ||
|
||
// 상품 좋아요 클릭 | ||
@PostMapping("/likes/{productId}") | ||
public ApiResponse<String> toggleLike(@PathVariable Long productId, @AuthenticationPrincipal CustomOAuth2User oAuth2User) { | ||
boolean isLiked = likeService.toggleLike(productId, oAuth2User.getId()); | ||
|
||
if (isLiked) { | ||
return ApiResponse.success("좋아요 추가"); | ||
} else { | ||
return ApiResponse.success("좋아요 취소"); | ||
} | ||
} | ||
|
||
|
||
// 상품별 좋아요 cnt 조회 | ||
@GetMapping("/products/{productId}/likes") | ||
public ApiResponse<Long> getLikeCount(@PathVariable Long productId) { | ||
Long likeCount = likeService.getLikeCount(productId); | ||
|
||
return ApiResponse.success(likeCount); | ||
} | ||
|
||
// 특정 유저가 좋아요한 상품 조회 | ||
@GetMapping("/products/likes/{userId}") | ||
public ApiResponse<List<LikeEntity>> getLikedProductsByUser(@PathVariable Long userId) { | ||
List<LikeEntity> likeEntities = likeService.getLikedProductsByUser(userId); | ||
return ApiResponse.success(likeEntities); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/trade_ham/domain/product/controller/SearchProductController.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.trade_ham.domain.product.controller; | ||
|
||
import com.trade_ham.domain.product.entity.ProductEntity; | ||
import com.trade_ham.domain.product.service.SearchProductService; | ||
import com.trade_ham.global.common.response.ApiResponse; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class SearchProductController { | ||
|
||
private final SearchProductService searchProductService; | ||
|
||
@GetMapping("/search") | ||
public ApiResponse<List<ProductEntity>> searchSellProduct(@RequestParam String keyword) { | ||
List<ProductEntity> productEntities = searchProductService.searchSellProduct(keyword); | ||
|
||
return ApiResponse.success(productEntities); | ||
} | ||
|
||
// 상품 클릭 | ||
@GetMapping("/products/{productId}") | ||
public ApiResponse<ProductEntity> getProductDetail(@PathVariable Long productId, HttpServletRequest request, HttpServletResponse response) { | ||
ProductEntity productEntity = searchProductService.getProductDetail(productId, request, response); | ||
|
||
return ApiResponse.success(productEntity); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
본인이 아닌 다른 사람의 좋아요를 조회할 경우가 있을까요..?
저는 자신의 좋아요만 조회해도 될 것 같아서 myPage 안의 기능과 통합했습니다!