Skip to content
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

[Feature] 알림 조회 API #44

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ services:
- 8080
restart: always
ports:
- 8080:8080
- 8080:8080
environment:
- TZ=Asia/Seoul
19 changes: 0 additions & 19 deletions src/main/java/ewha/lux/once/domain/home/dto/AnnouncListDto.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/ewha/lux/once/domain/home/dto/AnnounceListDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ewha.lux.once.domain.home.dto;

import lombok.*;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class AnnounceListDto {

private String nickname;
private long announceCount;
private List<AnnounceDto> announceTodayList;
private List<AnnounceDto> announcePastList;

}
40 changes: 25 additions & 15 deletions src/main/java/ewha/lux/once/domain/home/service/HomeService.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package ewha.lux.once.domain.home.service;

import ewha.lux.once.domain.home.dto.*;
import ewha.lux.once.domain.card.entity.Card;
import ewha.lux.once.domain.card.entity.OwnedCard;
import ewha.lux.once.domain.home.dto.*;
import ewha.lux.once.domain.home.entity.Announcement;
import ewha.lux.once.domain.home.entity.ChatHistory;
import ewha.lux.once.domain.card.entity.OwnedCard;
import ewha.lux.once.domain.user.entity.Users;
import ewha.lux.once.global.common.CustomException;
import ewha.lux.once.global.common.ResponseCode;
import ewha.lux.once.global.repository.CardRepository;
import ewha.lux.once.global.repository.AnnouncementRepository;
import ewha.lux.once.global.repository.CardRepository;
import ewha.lux.once.global.repository.ChatHistoryRepository;
import ewha.lux.once.global.repository.OwnedCardRepository;
import ewha.lux.once.domain.user.entity.Users;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -22,6 +22,7 @@
@Service
@RequiredArgsConstructor
public class HomeService {

private final CardRepository cardRepository;
private final OwnedCardRepository ownedCardRepository;
private final ChatHistoryRepository chatHistoryRepository;
Expand All @@ -30,6 +31,7 @@ public class HomeService {
private final GeminiService geminiService;
private final OpenaiService openaiService;

// 챗봇 카드 추천
public ChatDto getHomeChat(Users nowUser, String keyword, int paymentAmount) throws CustomException {

// 1. Gemini 사용하는 경우
Expand Down Expand Up @@ -123,6 +125,7 @@ private static String getCategory(String keyword) {
return "기타";
}

// 홈 화면 기본정보 조회
public HomeDto getHome(Users nowUser) throws CustomException {
// 사용자별 맞춤형 키워드 조회
List<ChatHistory> allChatHistory = chatHistoryRepository.findByUsers(nowUser);
Expand All @@ -138,35 +141,37 @@ public HomeDto getHome(Users nowUser) throws CustomException {
.limit(3) // 상위 3개 키워드
.map(Map.Entry::getKey)
.collect(Collectors.toList());
List<String> defaultKeywords = List.of("배달의 민족", "스타벅스","GS25"); // 고정 키워드
List<String> defaultKeywords = List.of("배달의 민족", "스타벅스", "GS25"); // 고정 키워드
while (topKeywords.size() < 3) {
topKeywords.add(defaultKeywords.get(topKeywords.size()));
}

return new HomeDto(nowUser.getNickname(),topKeywords);
return new HomeDto(nowUser.getNickname(), topKeywords);

}

// 결제 여부 변경
public void getPayCardHistory(Users nowUser, Long chatId) throws CustomException {
Optional<ChatHistory> optionalChatHistory = chatHistoryRepository.findById(chatId);
ChatHistory chatHistory = optionalChatHistory.orElseThrow(() -> new CustomException(ResponseCode.CHAT_HISTORY_NOT_FOUND));
ChatHistory chatHistory = optionalChatHistory.orElseThrow(() -> new CustomException(ResponseCode.CHAT_HISTORY_NOT_FOUND));
int paymentAmount = chatHistory.getPaymentAmount();

String cardName = chatHistory.getCardName();
Optional<Card> optionalCard = cardRepository.findByName(cardName);
Card card = optionalCard.orElseThrow(() -> new CustomException(ResponseCode.CARD_NOT_FOUND));
OwnedCard ownedCard = ownedCardRepository.findOwnedCardByCardAndUsers(card,nowUser);
OwnedCard ownedCard = ownedCardRepository.findOwnedCardByCardAndUsers(card, nowUser);
boolean isMain = ownedCard.isMain(); // 주카드인 경우 실제 실적을 불러옴


if(chatHistory.isHasPaid()==true){
if (chatHistory.isHasPaid() == true) {
chatHistory.setHasPaid(false);
if(isMain==false) {
ownedCard.setCurrentPerformance(ownedCard.getCurrentPerformance()-paymentAmount);
if (isMain == false) {
ownedCard.setCurrentPerformance(ownedCard.getCurrentPerformance() - paymentAmount);
}
} else {
chatHistory.setHasPaid(true);
if(isMain==false) {
ownedCard.setCurrentPerformance(ownedCard.getCurrentPerformance()+paymentAmount);
if (isMain == false) {
ownedCard.setCurrentPerformance(ownedCard.getCurrentPerformance() + paymentAmount);
}
}

Expand All @@ -176,7 +181,10 @@ public void getPayCardHistory(Users nowUser, Long chatId) throws CustomException
return;
}

public AnnouncListDto getAnnounce(Users nowUser) throws CustomException {
// 알림 리스트 조회
public AnnounceListDto getAnnounce(Users nowUser) throws CustomException {
String nickname = nowUser.getNickname();

LocalDate today = LocalDate.now();
LocalDate thisWeek = today.minusDays(7);

Expand All @@ -202,8 +210,10 @@ public AnnouncListDto getAnnounce(Users nowUser) throws CustomException {
&& announcement.getCreatedAt().toLocalDate().isAfter(thisWeek))
.count();

return new AnnouncListDto(uncheckedcnt,todayAnnounceDto,recentAnnounceDto);
return new AnnounceListDto(nickname, uncheckedcnt, todayAnnounceDto, recentAnnounceDto);
}

// 알림 상세 조회
public AnnounceDetailDto getAnnounceDetail(Long announceId) throws CustomException {
Optional<Announcement> optionalAnnouncement = announcementRepository.findById(announceId);
Announcement announcement = optionalAnnouncement.orElseThrow(() -> new CustomException(ResponseCode.ANNOUNCEMENT_NOT_FOUND));
Expand Down
Loading