-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] 그룹 이름 중복 검사, 그룹 추천 받기를 구현한다 (#112)
* refactor: 그룹 이름 중복을 허용하지 않는다 * feature: 그룹 이름 유일성 검증을 구현한다 * feature: 그룹 추천 받기를 구현한다 * refactor: 퀘스트 추천 DAO의 메서드 명을 축약한다
- Loading branch information
Showing
11 changed files
with
149 additions
and
8 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/daybyquest/group/application/CheckGroupNameService.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,20 @@ | ||
package daybyquest.group.application; | ||
|
||
import daybyquest.group.domain.Groups; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
public class CheckGroupNameService { | ||
|
||
private final Groups groups; | ||
|
||
public CheckGroupNameService(final Groups groups) { | ||
this.groups = groups; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public void invoke(final String name) { | ||
groups.validateNotExistentByName(name); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/daybyquest/group/application/RecommendGroupsService.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,41 @@ | ||
package daybyquest.group.application; | ||
|
||
import daybyquest.group.dto.response.GroupResponse; | ||
import daybyquest.group.dto.response.MultipleGroupsResponse; | ||
import daybyquest.group.query.GroupDao; | ||
import daybyquest.group.query.GroupData; | ||
import daybyquest.group.query.GroupRecommendDao; | ||
import daybyquest.user.domain.User; | ||
import daybyquest.user.domain.Users; | ||
import java.util.List; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
public class RecommendGroupsService { | ||
|
||
private static final int MAX_RECOMMENDATION_COUNT = 5; | ||
|
||
private final Users users; | ||
|
||
private final GroupRecommendDao recommendDao; | ||
|
||
private final GroupDao groupDao; | ||
|
||
public RecommendGroupsService(final Users users, final GroupRecommendDao recommendDao, | ||
final GroupDao groupDao) { | ||
this.users = users; | ||
this.recommendDao = recommendDao; | ||
this.groupDao = groupDao; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public MultipleGroupsResponse invoke(final Long loginId) { | ||
final User user = users.getById(loginId); | ||
final List<Long> ids = recommendDao.getRecommendIds(MAX_RECOMMENDATION_COUNT, | ||
user.getInterests()); | ||
final List<GroupData> groupData = groupDao.findAllByIdsIn(loginId, ids); | ||
final List<GroupResponse> responses = groupData.stream().map(GroupResponse::of).toList(); | ||
return new MultipleGroupsResponse(responses); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/daybyquest/group/query/GroupRecommendDao.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 daybyquest.group.query; | ||
|
||
import daybyquest.group.domain.Group; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.Repository; | ||
|
||
public interface GroupRecommendDao extends Repository<Group, Long> { | ||
|
||
@Query(value = "select g.id from `group` g where g.interest in :interests " | ||
+ "and g.id >= FLOOR(1 + RAND() * (select MAX(`group`.id) from `group`)) " | ||
+ "ORDER BY g.id limit :topN", | ||
nativeQuery = true) | ||
List<Long> getRecommendIds(final int topN, final Collection<String> interests); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER table `group` | ||
add constraint `GROUP_UNIQUE_NAME` unique (`name`); |
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