-
Notifications
You must be signed in to change notification settings - Fork 3
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 #357 from TrandPick/development
트랜드픽 배포
- Loading branch information
Showing
9 changed files
with
107 additions
and
60 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/project/trendpick_pro/domain/common/view/entity/View.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 project.trendpick_pro.domain.common.view.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
public class View { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private Long count = 0L; | ||
|
||
public void increment() { | ||
this.count++; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/project/trendpick_pro/domain/common/view/repository/ViewRepository.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,7 @@ | ||
package project.trendpick_pro.domain.common.view.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import project.trendpick_pro.domain.common.view.entity.View; | ||
|
||
public interface ViewRepository extends JpaRepository<View, Long> { | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/project/trendpick_pro/domain/common/view/service/ViewService.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 project.trendpick_pro.domain.common.view.service; | ||
|
||
import jakarta.servlet.http.HttpSession; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.kafka.core.KafkaTemplate; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import project.trendpick_pro.domain.common.view.entity.View; | ||
import project.trendpick_pro.domain.common.view.repository.ViewRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ViewService { | ||
|
||
private final ViewRepository viewRepository; | ||
|
||
private final KafkaTemplate<String, String> kafkaTemplate; | ||
|
||
@Transactional | ||
public void registerView() { | ||
viewRepository.save(new View()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public int findSize() { | ||
return viewRepository.findAll().size(); | ||
} | ||
|
||
public void requestIncrementViewCount(HttpSession session) { | ||
if (session.getAttribute("visited") == null) { | ||
kafkaTemplate.send("views", "increment", "1"); | ||
session.setAttribute("visited", true); | ||
} | ||
} | ||
|
||
@Transactional | ||
@KafkaListener(topicPattern = "views", groupId = "group_id") | ||
public void handleIncrementViewCount(@Payload String viewId) { | ||
View totalView = viewRepository.findById(Long.valueOf(viewId)).get(); | ||
totalView.increment(); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public Long getCount() { | ||
return viewRepository.findById(1L).get().getCount(); | ||
} | ||
} |
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
45 changes: 0 additions & 45 deletions
45
src/main/java/project/trendpick_pro/global/config/RedisConfig.java
This file was deleted.
Oops, something went wrong.
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