-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] 유저 추가 API 수정 + 어드민 설정의 해시태그 보유 유저 조회 API 구현
- Loading branch information
Showing
19 changed files
with
349 additions
and
24 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
27 changes: 27 additions & 0 deletions
27
...n/java/com/bbteam/budgetbuddies/domain/favoritehashtag/controller/FavoriteHashtagApi.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.bbteam.budgetbuddies.domain.favoritehashtag.controller; | ||
|
||
import com.bbteam.budgetbuddies.apiPayload.ApiResponse; | ||
import com.bbteam.budgetbuddies.domain.favoritehashtag.dto.FavoriteHashtagResponseDto; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import java.util.List; | ||
|
||
public interface FavoriteHashtagApi { | ||
|
||
@Operation(summary = "[User] 해당되는 해시태그를 설정한 유저 조회 API", description = "특정 할인정보 또는 지원정보에 등록된 해시태그를 설정한 유저를 조회합니다.") | ||
@ApiResponses({ | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), | ||
}) | ||
@Parameters({ | ||
@Parameter(name = "discountInfoId", description = "조회할 할인정보 ID", required = false), | ||
@Parameter(name = "supportInfoId", description = "조회할 지원정보 ID", required = false), | ||
}) | ||
ApiResponse<List<FavoriteHashtagResponseDto>> getUsersByHashtags( | ||
@RequestParam(required = false) Long discountInfoId, | ||
@RequestParam(required = false) Long supportInfoId | ||
); | ||
} |
27 changes: 27 additions & 0 deletions
27
...com/bbteam/budgetbuddies/domain/favoritehashtag/controller/FavoriteHashtagController.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.bbteam.budgetbuddies.domain.favoritehashtag.controller; | ||
|
||
import com.bbteam.budgetbuddies.apiPayload.ApiResponse; | ||
import com.bbteam.budgetbuddies.domain.favoritehashtag.dto.FavoriteHashtagResponseDto; | ||
import com.bbteam.budgetbuddies.domain.favoritehashtag.service.FavoriteHashtagService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/favoriteHashtags") | ||
public class FavoriteHashtagController implements FavoriteHashtagApi { | ||
|
||
private final FavoriteHashtagService favoriteHashtagService; | ||
|
||
@Override | ||
@GetMapping("/applicable-users") | ||
public ApiResponse<List<FavoriteHashtagResponseDto>> getUsersByHashtags( | ||
@RequestParam(required = false) Long discountInfoId, | ||
@RequestParam(required = false) Long supportInfoId | ||
) { | ||
List<FavoriteHashtagResponseDto> users = favoriteHashtagService.findUsersByHashtag(discountInfoId, supportInfoId); | ||
return ApiResponse.onSuccess(users); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../java/com/bbteam/budgetbuddies/domain/favoritehashtag/dto/FavoriteHashtagResponseDto.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,16 @@ | ||
package com.bbteam.budgetbuddies.domain.favoritehashtag.dto; | ||
|
||
import com.bbteam.budgetbuddies.domain.user.entity.User; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
|
||
public class FavoriteHashtagResponseDto { | ||
private Long userId; | ||
|
||
public FavoriteHashtagResponseDto(User user) { | ||
this.userId = user.getId(); | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
...com/bbteam/budgetbuddies/domain/favoritehashtag/repository/FavoriteHashtagRepository.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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package com.bbteam.budgetbuddies.domain.favoritehashtag.repository; | ||
|
||
import com.bbteam.budgetbuddies.domain.favoritehashtag.entity.FavoriteHashtag; | ||
import com.bbteam.budgetbuddies.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FavoriteHashtagRepository extends JpaRepository<FavoriteHashtag, Long> { | ||
import java.util.List; | ||
|
||
public interface FavoriteHashtagRepository extends JpaRepository<FavoriteHashtag, Long> { | ||
List<FavoriteHashtag> findByUser(User user); | ||
|
||
} | ||
List<FavoriteHashtag> findByHashtagIdIn(List<Long> hashtagIds); | ||
} |
12 changes: 12 additions & 0 deletions
12
.../java/com/bbteam/budgetbuddies/domain/favoritehashtag/service/FavoriteHashtagService.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.bbteam.budgetbuddies.domain.favoritehashtag.service; | ||
|
||
import com.bbteam.budgetbuddies.domain.favoritehashtag.dto.FavoriteHashtagResponseDto; | ||
|
||
import java.util.List; | ||
|
||
public interface FavoriteHashtagService { | ||
List<Long> getUsersForHashtag(Long discountInfoId, Long supportInfoId); | ||
|
||
List<FavoriteHashtagResponseDto> findUsersByHashtag(Long discountInfoId, Long supportInfoId); | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
...a/com/bbteam/budgetbuddies/domain/favoritehashtag/service/FavoriteHashtagServiceImpl.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,76 @@ | ||
package com.bbteam.budgetbuddies.domain.favoritehashtag.service; | ||
|
||
import com.bbteam.budgetbuddies.domain.connectedinfo.entity.ConnectedInfo; | ||
import com.bbteam.budgetbuddies.domain.connectedinfo.repository.ConnectedInfoRepository; | ||
import com.bbteam.budgetbuddies.domain.discountinfo.entity.DiscountInfo; | ||
import com.bbteam.budgetbuddies.domain.favoritehashtag.dto.FavoriteHashtagResponseDto; | ||
import com.bbteam.budgetbuddies.domain.favoritehashtag.entity.FavoriteHashtag; | ||
import com.bbteam.budgetbuddies.domain.favoritehashtag.repository.FavoriteHashtagRepository; | ||
import com.bbteam.budgetbuddies.domain.supportinfo.entity.SupportInfo; | ||
import com.bbteam.budgetbuddies.domain.user.entity.User; | ||
import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class FavoriteHashtagServiceImpl implements FavoriteHashtagService { | ||
|
||
private final ConnectedInfoRepository connectedInfoRepository; | ||
private final FavoriteHashtagRepository favoriteHashtagRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Override | ||
public List<Long> getUsersForHashtag(Long discountInfoId, Long supportInfoId) { | ||
List<ConnectedInfo> connectedInfos; | ||
|
||
if (discountInfoId != null) { | ||
DiscountInfo discountInfo = DiscountInfo.withId(discountInfoId); | ||
connectedInfos = connectedInfoRepository.findAllByDiscountInfo(discountInfo); | ||
} else if (supportInfoId != null) { | ||
SupportInfo supportInfo = SupportInfo.withId(supportInfoId); | ||
connectedInfos = connectedInfoRepository.findAllBySupportInfo(supportInfo); | ||
} else { | ||
throw new IllegalArgumentException("discountInfoId 또는 supportInfoId 중 하나는 필수입니다."); | ||
} | ||
|
||
List<Long> hashtagIds = connectedInfos.stream() | ||
.map(connectedInfo -> connectedInfo.getHashtag().getId()) | ||
.collect(Collectors.toList()); | ||
System.out.println("Connected Hashtags IDs: " + hashtagIds); | ||
|
||
|
||
List<FavoriteHashtag> favoriteHashtags = favoriteHashtagRepository.findByHashtagIdIn(hashtagIds); | ||
System.out.println("Favorite Hashtags: " + favoriteHashtags); | ||
|
||
return favoriteHashtags.stream() | ||
.map(favoriteHashtag -> favoriteHashtag.getUser().getId()) | ||
.distinct() | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public List<FavoriteHashtagResponseDto> findUsersByHashtag(Long discountInfoId, Long supportInfoId) { | ||
List<Long> userIds = getUsersForHashtag(discountInfoId, supportInfoId); | ||
|
||
return userIds.stream() | ||
.map(userId -> { | ||
Optional<User> optionalUser = userRepository.findById(userId); | ||
optionalUser.ifPresent(user -> System.out.println("User found: " + user)); // 여기에 추가 | ||
return optionalUser.map(FavoriteHashtagResponseDto::new) | ||
.orElseGet(() -> { | ||
System.out.println("User not found with id: " + userId); | ||
return null; | ||
}); | ||
}) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -173,8 +173,6 @@ void toggleLikeTest() { | |
.age(30) | ||
.gender(Gender.MALE) | ||
.email("[email protected]") | ||
.photoUrl("http://example.com/photo.jpg") | ||
.consumptionPattern("Regular") | ||
.lastLoginAt(LocalDateTime.now()) | ||
.build(); | ||
|
||
|
Oops, something went wrong.