-
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.
- Loading branch information
Showing
6 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/com/snsIntegrationFeedService/hashtag/repository/HashtagRepository.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.snsIntegrationFeedService.hashtag.repository; | ||
|
||
import com.snsIntegrationFeedService.hashtag.entity.Hashtag; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface HashtagRepository extends JpaRepository<Hashtag, Long> { | ||
|
||
Long findIdByName(String hashtag); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/snsIntegrationFeedService/hashtag/service/HashtagService.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,23 @@ | ||
package com.snsIntegrationFeedService.hashtag.service; | ||
|
||
import com.snsIntegrationFeedService.hashtag.entity.Hashtag; | ||
import com.snsIntegrationFeedService.hashtag.repository.HashtagRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class HashtagService { | ||
|
||
private final HashtagRepository hashtagRepository; | ||
|
||
public Hashtag createHashtag(String tag) { | ||
Hashtag hashtag = Hashtag.builder().name(tag).build(); | ||
|
||
return hashtagRepository.save(hashtag); | ||
} | ||
|
||
public Long getHashtagId(String hashtag) { | ||
return hashtagRepository.findIdByName(hashtag); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...main/java/com/snsIntegrationFeedService/postHashtag/repository/PostHashtagRepository.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.snsIntegrationFeedService.postHashtag.repository; | ||
|
||
import com.snsIntegrationFeedService.postHashtag.entity.PostHashtag; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface PostHashtagRepository extends JpaRepository<PostHashtag, Long> { | ||
|
||
@Query(value = "SELECT post_id FROM post_hashtag WHERE hashtag_id = :hashtagId", nativeQuery = true) | ||
List<Long> findPostIdsByHashtagId(@Param("hashtagId") Long hashtagId); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/snsIntegrationFeedService/postHashtag/service/PostHashtagService.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,32 @@ | ||
package com.snsIntegrationFeedService.postHashtag.service; | ||
|
||
import com.snsIntegrationFeedService.hashtag.entity.Hashtag; | ||
import com.snsIntegrationFeedService.hashtag.service.HashtagService; | ||
import com.snsIntegrationFeedService.post.entity.Post; | ||
import com.snsIntegrationFeedService.postHashtag.entity.PostHashtag; | ||
import com.snsIntegrationFeedService.postHashtag.repository.PostHashtagRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PostHashtagService { | ||
|
||
private final PostHashtagRepository postHashtagRepository; | ||
private final HashtagService hashtagService; | ||
|
||
public PostHashtag createPostHashtag(Post post, Hashtag hashtag) { | ||
PostHashtag postHashtag = PostHashtag.builder() | ||
.post(post) | ||
.hashtag(hashtag) | ||
.build(); | ||
return postHashtagRepository.save(postHashtag); | ||
} | ||
|
||
public List<Long> getPostIdsByHashtag(String hashtag) { | ||
Long hashtagId = hashtagService.getHashtagId(hashtag); | ||
|
||
return postHashtagRepository.findPostIdsByHashtagId(hashtagId); | ||
} | ||
} |