Skip to content

Commit

Permalink
Merge pull request #82 from Dallili/dev/feat/notify3
Browse files Browse the repository at this point in the history
[feat] NotifyController 알림 목록 조회 기능 구현
  • Loading branch information
idon1nab authored May 8, 2024
2 parents b099791 + 2e2dcab commit 80be94e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@RestController
@Log4j2
@RequiredArgsConstructor
@RequestMapping("/notify")
@RequestMapping("/emitter")
public class EmitterController {

private final EmitterService emitterService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.dallili.secretfriends.notify.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.dallili.secretfriends.notify.dto.NotifyDTO;
import org.dallili.secretfriends.notify.service.NotifyService;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Log4j2
@RequiredArgsConstructor
@RequestMapping("/notify")
public class NotifyController {

private final NotifyService notifyService;
@Operation(summary = "Notify List GET", description = "알림 목록 조회")
@GetMapping(value = "/")
public List<NotifyDTO> notifyDTOList (Authentication authentication){
return notifyService.findAllNotify(Long.parseLong(authentication.getName()));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;
import org.dallili.secretfriends.notify.domain.Notify;

import java.time.LocalDateTime;

@Data
@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor

Expand All @@ -33,4 +31,10 @@ public class NotifyDTO {
public enum NotifyType{
NEWDIARY, REPLY, INACTIVATE
}

//modelmapper 매핑 규칙 정의를 위한 setter
//일반 코드 작성 시에는 사용 지양
public void setNotifyType(Enum<NotifyType> notifyType) {
this.notifyType = notifyType;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package org.dallili.secretfriends.notify.repository;

import org.dallili.secretfriends.domain.Diary;
import org.dallili.secretfriends.domain.Member;
import org.dallili.secretfriends.notify.domain.Notify;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface NotifyRepository extends JpaRepository<Notify, Long> {

List<Notify> findAllByReceiver_MemberID(Long receiverID);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.dallili.secretfriends.notify.dto.NotifyDTO;

import java.util.List;

public interface NotifyService {

// "2. notify 테이블에 알림 데이터 저장" 담당하는 메소드
// notify 테이블에 알림 데이터 저장" 담당하는 메소드
void saveNotifyTable(Long receiverID, Long senderID, NotifyDTO.NotifyType type);

void removeNotify(Long notifyID);
List<NotifyDTO> findAllNotify(Long receiverID);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Log4j2
Expand All @@ -26,8 +28,9 @@ public void saveNotifyTable(Long receiverID, Long senderID, NotifyDTO.NotifyType
.receiverID(receiverID)
.senderID(senderID)
.build();
//log.info(receiverNotifyDTO);
log.info(receiverNotifyDTO);
Notify receiverNotify = modelMapper.map(receiverNotifyDTO, Notify.class);
log.info(receiverNotify);
notifyRepository.save(receiverNotify);

if(type == NotifyDTO.NotifyType.NEWDIARY || type == NotifyDTO.NotifyType.INACTIVATE){
Expand All @@ -45,4 +48,19 @@ public void saveNotifyTable(Long receiverID, Long senderID, NotifyDTO.NotifyType
public void removeNotify(Long notifyID){
notifyRepository.deleteById(notifyID);
}

public List<NotifyDTO> findAllNotify(Long receiverID){
List<Notify> notifyList = notifyRepository.findAllByReceiver_MemberID(receiverID);

List<NotifyDTO> notifyDTOList = notifyList.stream()
.map(notify -> {
NotifyDTO notifyDTO = modelMapper.map(notify, NotifyDTO.class);
// notificationType 가공하여 NotifyDTO에 추가
notifyDTO.setNotifyType(NotifyDTO.NotifyType.valueOf(notify.getNotifyType()));
return notifyDTO;
})
.collect(Collectors.toList());

return notifyDTOList;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring:
show-sql: true

profiles:
active: prod
active: local

logging:
level:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class NotifyRepositoryTests {

@Autowired
private MemberRepository memberRepository;

/*
@Test
public void testInsert() {
Expand All @@ -32,5 +32,5 @@ public void testInsert() {
.build();
notifyRepository.save(notify);
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ public class NotifyServiceTests {
@Test
public void testSaveNotify() {

notifyService.saveNotifyTable(1L, 2L, NotifyDTO.NotifyType.NEWDIARY);
notifyService.saveNotifyTable(1L, 2L, NotifyDTO.NotifyType.INACTIVATE);
}

@Test
public void testRemoveNotify(){
notifyService.removeNotify(1L);
notifyService.removeNotify(3L);

}

@Test
public void testFindAllNotify() {
log.info(notifyService.findAllNotify(2L));
}
}

0 comments on commit 80be94e

Please sign in to comment.