diff --git a/src/main/java/aromanticcat/umcproject/config/AppConfig.java b/src/main/java/aromanticcat/umcproject/config/AppConfig.java deleted file mode 100644 index a764755..0000000 --- a/src/main/java/aromanticcat/umcproject/config/AppConfig.java +++ /dev/null @@ -1,21 +0,0 @@ -package aromanticcat.umcproject.config; - -import org.modelmapper.ModelMapper; -import org.modelmapper.convention.MatchingStrategies; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class AppConfig { - - @Bean - public ModelMapper getMapper(){ - ModelMapper modelMapper = new ModelMapper(); - modelMapper.getConfiguration() - .setFieldMatchingEnabled(true) - .setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE) - .setMatchingStrategy(MatchingStrategies.STRICT); - - return modelMapper; - } -} diff --git a/src/main/java/aromanticcat/umcproject/converter/NangmanPostBoxConverter.java b/src/main/java/aromanticcat/umcproject/converter/NangmanPostBoxConverter.java new file mode 100644 index 0000000..cb0858b --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/converter/NangmanPostBoxConverter.java @@ -0,0 +1,75 @@ +package aromanticcat.umcproject.converter; + +import aromanticcat.umcproject.entity.NangmanLetter; +import aromanticcat.umcproject.entity.NangmanReply; +import aromanticcat.umcproject.web.dto.NangmanPostBoxRequestDTO; +import aromanticcat.umcproject.web.dto.NangmanPostBoxResponseDTO; + +public class NangmanPostBoxConverter { + + //낭만 레터 엔티티 -> DTO 생성 + public static NangmanPostBoxResponseDTO.SendLetterResultDTO toSendLetterResultDTO(NangmanLetter nangmanLetter){ + + return NangmanPostBoxResponseDTO.SendLetterResultDTO.builder() + .nangmanLetterId(nangmanLetter.getId()) + .senderNickname(nangmanLetter.getSenderNickname()) + .createdAt(nangmanLetter.getCreatedAt()) + .build(); + } + + //낭만 레터 DTO -> 엔티티 생성 + public static NangmanLetter toNangmanLetterResult(NangmanPostBoxRequestDTO.SendLetterDTO request){ + return NangmanLetter.builder() + .isPublic(request.getIsPublic()) + .content(request.getContent()) + .senderNickname(request.getSenderRandomNickname()) +// .member(request.getMember()) + .build(); + } + + //낭만 레터 엔티티 -> 프리뷰 낭만 레터 DTO 생성 + public static NangmanPostBoxResponseDTO.LetterSummaryResultDTO toLetterSummaryResultDTO(NangmanLetter nangmanLetter){ + // 편지 내용을 40자 까지만 보이도록 + String content = nangmanLetter.getContent(); + String preview = content.length() <= 40 ? content: content.substring(0, 40) + "..."; + + return NangmanPostBoxResponseDTO.LetterSummaryResultDTO.builder() + .nangmanLetterId(nangmanLetter.getId()) + .preview(preview) + .createdAt(nangmanLetter.getCreatedAt()) + .build(); + } + + //낭만 레터 엔티티 + 랜덤 닉네임 -> 낭만 리플라이 DTO 생성 + public static NangmanPostBoxResponseDTO.SelectedLetterResultDTO toReplyLetterResultDTO(NangmanLetter nangmanLetter, String randomNickname){ + return NangmanPostBoxResponseDTO.SelectedLetterResultDTO.builder() + .nangmanLetterId(nangmanLetter.getId()) + .nangmanLetterContent(nangmanLetter.getContent()) + .senderNickname(nangmanLetter.getSenderNickname()) + .replySenderNickname(randomNickname) + .build(); + } + + // 낭만 리플라이 DTO -> 낭만 리플라이 엔티티 + public static NangmanReply toNangmanReplyResult(NangmanPostBoxRequestDTO.ReplyLetterDTO request, NangmanLetter nangmanLetter){ + return NangmanReply.builder() + .content(request.getReplyContent()) + .replySenderNickname(request.getReplySenderNickname()) + .nangmanLetter(nangmanLetter) +// .member(request.getMember()) + .build(); + + } + + public static NangmanPostBoxResponseDTO.SendReplyResultDTO toSendReplyResultDTO(NangmanReply nangmanReply){ + return NangmanPostBoxResponseDTO.SendReplyResultDTO.builder() + .nangmanReplyId(nangmanReply.getId()) + .nangmanLetterId(nangmanReply.getNangmanLetter().getId()) + .replySenderNickname(nangmanReply.getReplySenderNickname()) + .createdAt(nangmanReply.getCreatedAt()) + .build(); + } + + + +} diff --git a/src/main/java/aromanticcat/umcproject/entity/Letter.java b/src/main/java/aromanticcat/umcproject/entity/Letter.java new file mode 100644 index 0000000..1eedfda --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/entity/Letter.java @@ -0,0 +1,42 @@ +package aromanticcat.umcproject.entity; + +import lombok.Getter; + +import javax.persistence.*; +import java.time.LocalDateTime; + +@Entity +@Getter +@Table(name = "letter") +public class Letter extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long letter_id; + + @Column(name = "nickname", length = 60) + private String nickname; + + @Column(length = 255) + private String content; + + private Boolean open; + + @Column(name = "login_status") + private Boolean loginStatus; + + @Column(name = "sender_ID") + private Long senderId; + + @ManyToOne + @JoinColumn(name = "letter_paper_id",insertable = false, updatable = false) + private LetterPaper letterPaper; + + @ManyToOne + @JoinColumn(name = "stamp_id", insertable = false, updatable = false) + private Stamp stamp; + + @ManyToOne + @JoinColumn(name = "id", insertable = false, updatable = false) + private Letterbox letterbox; +} diff --git a/src/main/java/aromanticcat/umcproject/entity/LetterPaper.java b/src/main/java/aromanticcat/umcproject/entity/LetterPaper.java new file mode 100644 index 0000000..d07fd15 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/entity/LetterPaper.java @@ -0,0 +1,26 @@ +package aromanticcat.umcproject.entity; + +import lombok.Getter; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Entity +@Getter +@Table(name = "letter_paper") +public class LetterPaper extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long letter_paper_id; + + @NotNull + private String image_url; + + @NotNull + private String name; + + @OneToMany(mappedBy = "letterPaper") + private List letters; +} \ No newline at end of file diff --git a/src/main/java/aromanticcat/umcproject/entity/Letterbox.java b/src/main/java/aromanticcat/umcproject/entity/Letterbox.java new file mode 100644 index 0000000..023ff03 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/entity/Letterbox.java @@ -0,0 +1,38 @@ +package aromanticcat.umcproject.entity; + +import lombok.Getter; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; +import java.util.List; + +@Entity +@Getter +@Table(name = "letterbox") +public class Letterbox extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long letterbox_id; + + @Column(name = "user_id", nullable = false) + private Long userId; + + @NotNull + private String name; + @NotNull + private String color; + + @NotNull + @Column(name = "end_dt") + private LocalDateTime endDt; + + @NotNull + private Boolean activate; + + @NotNull + private Boolean sender; + + @OneToMany(mappedBy = "letterbox") + private List letters; +} diff --git a/src/main/java/aromanticcat/umcproject/entity/NangmanLetter.java b/src/main/java/aromanticcat/umcproject/entity/NangmanLetter.java index f786d29..81a6bff 100644 --- a/src/main/java/aromanticcat/umcproject/entity/NangmanLetter.java +++ b/src/main/java/aromanticcat/umcproject/entity/NangmanLetter.java @@ -18,35 +18,35 @@ public class NangmanLetter extends BaseEntity { private Long id; @NotNull - private String sender_nickname; + private String senderNickname; @NotNull - private Boolean is_public; + private Boolean isPublic; @NotNull private String content; @NotNull @Builder.Default - private Boolean has_response = false; + private Boolean hasResponse = false; - private Integer thumbs_up_cnt; + private Integer thumbsUpCnt; - private Integer heart_cnt; + private Integer heartCnt; - private Integer crying_cnt; + private Integer cryingCnt; - private Integer clover_cnt; + private Integer cloverCnt; - private Integer clap_cnt; + private Integer clapCnt; - private Integer star_cnt; + private Integer starCnt; @JoinColumn(name = "member_id") @ManyToOne(fetch = FetchType.LAZY) private Member member; - public void change(Boolean has_response){ - this.has_response = has_response; + public void change(Boolean hasResponse){ + this.hasResponse = hasResponse; } } diff --git a/src/main/java/aromanticcat/umcproject/entity/NangmanReply.java b/src/main/java/aromanticcat/umcproject/entity/NangmanReply.java index 1ad1741..e16fb5b 100644 --- a/src/main/java/aromanticcat/umcproject/entity/NangmanReply.java +++ b/src/main/java/aromanticcat/umcproject/entity/NangmanReply.java @@ -1,25 +1,26 @@ package aromanticcat.umcproject.entity; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToOne; -import lombok.Getter; +import lombok.*; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; @Entity @Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString public class NangmanReply extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - private String response_sender_nickname; + @NotNull + private String replySenderNickname; + @NotNull private String content; @JoinColumn(name = "letter_id") diff --git a/src/main/java/aromanticcat/umcproject/entity/Stamp.java b/src/main/java/aromanticcat/umcproject/entity/Stamp.java new file mode 100644 index 0000000..00df663 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/entity/Stamp.java @@ -0,0 +1,26 @@ +package aromanticcat.umcproject.entity; + +import lombok.Getter; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Entity +@Getter +@Table(name = "stamp") +public class Stamp extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long stamp_id; + + @NotNull + private String image_url; + + @NotNull + private String name; + + @OneToMany(mappedBy = "stamp") + private List letters; +} \ No newline at end of file diff --git a/src/main/java/aromanticcat/umcproject/repository/NangmanLetterRepository.java b/src/main/java/aromanticcat/umcproject/repository/NangmanLetterRepository.java index 79a52e5..c882ffb 100644 --- a/src/main/java/aromanticcat/umcproject/repository/NangmanLetterRepository.java +++ b/src/main/java/aromanticcat/umcproject/repository/NangmanLetterRepository.java @@ -3,5 +3,10 @@ import aromanticcat.umcproject.entity.NangmanLetter; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface NangmanLetterRepository extends JpaRepository { + + List findByHasResponseFalse(); + } diff --git a/src/main/java/aromanticcat/umcproject/repository/NangmanReplyRepository.java b/src/main/java/aromanticcat/umcproject/repository/NangmanReplyRepository.java new file mode 100644 index 0000000..941e1f1 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/repository/NangmanReplyRepository.java @@ -0,0 +1,8 @@ +package aromanticcat.umcproject.repository; + +import aromanticcat.umcproject.entity.NangmanReply; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NangmanReplyRepository extends JpaRepository { + +} diff --git a/src/main/java/aromanticcat/umcproject/service/NangmanPostBoxService.java b/src/main/java/aromanticcat/umcproject/service/NangmanPostBoxService.java new file mode 100644 index 0000000..deb79a3 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/service/NangmanPostBoxService.java @@ -0,0 +1,22 @@ +package aromanticcat.umcproject.service; + +import aromanticcat.umcproject.entity.NangmanLetter; +import aromanticcat.umcproject.entity.NangmanReply; +import aromanticcat.umcproject.web.dto.NangmanPostBoxRequestDTO; + +import java.util.List; + +public interface NangmanPostBoxService { + + NangmanLetter writeAndSendLetter(NangmanPostBoxRequestDTO.SendLetterDTO requestDTO); + + List getLetterList(); + + NangmanLetter getLetterById(Long id); + + NangmanReply writeAndSendReply(NangmanPostBoxRequestDTO.ReplyLetterDTO requestDTO, Long id); + +// NangmanLetterDTO readOne(Long id); +// +// void receivedReply(NangmanLetterDTO nangmanLetterDTO); +} diff --git a/src/main/java/aromanticcat/umcproject/service/NangmanPostBoxServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/NangmanPostBoxServiceImpl.java new file mode 100644 index 0000000..69f5d93 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/service/NangmanPostBoxServiceImpl.java @@ -0,0 +1,90 @@ +package aromanticcat.umcproject.service; + +import aromanticcat.umcproject.converter.NangmanPostBoxConverter; +import aromanticcat.umcproject.entity.NangmanLetter; +import aromanticcat.umcproject.entity.NangmanReply; +import aromanticcat.umcproject.repository.MemberRepository; +import aromanticcat.umcproject.repository.NangmanLetterRepository; +import aromanticcat.umcproject.repository.NangmanReplyRepository; +import aromanticcat.umcproject.web.dto.NangmanPostBoxRequestDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; +import java.util.List; + +@Service +@RequiredArgsConstructor +@Transactional +public class NangmanPostBoxServiceImpl implements NangmanPostBoxService { + + private final NangmanLetterRepository nangmanLetterRepository; + private final MemberRepository memberRepository; + private final RandomNicknameService randomNicknameService; + private final NangmanReplyRepository nangmanReplyRepository; + @Override + @Transactional + public NangmanLetter writeAndSendLetter(NangmanPostBoxRequestDTO.SendLetterDTO request){ + NangmanLetter newNangmanLetter = NangmanPostBoxConverter.toNangmanLetterResult(request); + + return nangmanLetterRepository.save(newNangmanLetter); + } + + @Override + @Transactional + public List getLetterList(){ + return nangmanLetterRepository.findByHasResponseFalse(); + } + + @Override + @Transactional + public NangmanLetter getLetterById(Long nangmanLetterId){ + return nangmanLetterRepository.findById(nangmanLetterId) + .orElseThrow(() -> new RuntimeException("편지를 찾을 수 없습니다. ID: " + nangmanLetterId)); + } + + @Override + @Transactional + public NangmanReply writeAndSendReply(NangmanPostBoxRequestDTO.ReplyLetterDTO request, Long nangmanLetterId){ + NangmanLetter nangmanLetter = getLetterById(nangmanLetterId); + NangmanReply newNangmanReply = NangmanPostBoxConverter.toNangmanReplyResult(request, nangmanLetter); + + return nangmanReplyRepository.save(newNangmanReply); + } + +// @Override +// public NangmanLetterDTO readOne(Long id){ +// +// Optional result = nangmanLetterRepository.findById(id); +// +// NangmanLetter nangmanLetter = result.orElseThrow(); +// +// NangmanLetterDTO nangmanLetterDTO = modelMapper.map(nangmanLetter, NangmanLetterDTO.class); +// +// return nangmanLetterDTO; +// } +// +// +// +// //답장 받을 때 has_response 업데이트 +// @Override +// public void receivedReply(NangmanLetterDTO nangmanLetterDTO) { +// Optional result = nangmanLetterRepository.findById(nangmanLetterDTO.getId()); +// +// NangmanLetter nangmanLetter = result.orElseThrow(); +// +// //has_response 값 업데이트 +// nangmanLetter.change(nangmanLetterDTO.getHas_response()); +// +// //is_public 값에 따라 낭만 모음집에 추가 +// if(nangmanLetter.getIs_public()){ +// addLetterToNangmanCollectoin(nangmanLetter); +// } +// nangmanLetterRepository.save(nangmanLetter); +// } +// +// private void addLetterToNangmanCollectoin(NangmanLetter nangmanLetter){ +// // 낭만 모음집에 해당 편지를 추가하는 로직을 구현 +// // 추가되는 방법은 해당 모음집의 컬렉션에 편지를 추가하거나 다른 적절한 방법으로 구현 +// } +} diff --git a/src/main/java/aromanticcat/umcproject/service/RandomNicknameService.java b/src/main/java/aromanticcat/umcproject/service/RandomNicknameService.java index be0b163..3486a12 100644 --- a/src/main/java/aromanticcat/umcproject/service/RandomNicknameService.java +++ b/src/main/java/aromanticcat/umcproject/service/RandomNicknameService.java @@ -10,7 +10,7 @@ public class RandomNicknameService { private static final String[] ADJECTIVES = { "이야기를 나누는", "그림을 그리는", "창문 너머를 보는", "뒤척이는", "별빛을 따라 떠나는", "달콤한 꿈을 꾸는", "손에 쥐는", "어깨에 기대는", "길을 걷는", "노래하는", "햇살을 받는", "책을 읽는", "쇼핑을 하는", "생각에 잠긴", "향기에 취하는", "바람에 실려 오는", - "바다를 바라보는", "눈을 감고 듣는", "손을 흔드는", "입술에 미소 지어지는", "흰 구름을 따라", "옛 추억에 빠진", "노을을 바라보는", + "바다를 바라보는", "눈을 감고 듣는", "손을 흔드는", "입술에 미소 지어지는", "흰 구름을 따라가는", "옛 추억에 빠진", "노을을 바라보는", "별들을 세는", "사진을 찍는", "운전하는", "손에 든 커피맛이 나는", "열쇠를 꽂는", "무엇인가를 찾는", "일기를 쓰는", "구름 사이를 걷는", "친구에게 전화하는", "빗소리를 듣는", "높은 곳을 내려다보는", "모자를 쓴", "새로운 일을 기대하는", "유쾌한 이야기를 나누는", "햇볕에 담근", "색다른 맛을 느끼는", "머릿결에 바람이 스치는", "두 손에 꽃을 든", "몽환적인 햇살에 비친", "달콤한 미소를 띤", "꿈결처럼 가벼운", "가슴에 품은", diff --git a/src/main/java/aromanticcat/umcproject/web/controller/NangmanPostBoxController.java b/src/main/java/aromanticcat/umcproject/web/controller/NangmanPostBoxController.java new file mode 100644 index 0000000..8c11719 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/web/controller/NangmanPostBoxController.java @@ -0,0 +1,120 @@ +package aromanticcat.umcproject.web.controller; + +import aromanticcat.umcproject.apiPayload.ApiResponse; +import aromanticcat.umcproject.converter.NangmanPostBoxConverter; +import aromanticcat.umcproject.entity.NangmanLetter; +import aromanticcat.umcproject.entity.NangmanReply; +import aromanticcat.umcproject.service.NangmanPostBoxService; +import aromanticcat.umcproject.service.RandomNicknameService; +import aromanticcat.umcproject.web.dto.NangmanPostBoxRequestDTO; +import aromanticcat.umcproject.web.dto.NangmanPostBoxResponseDTO; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.stream.Collectors; + +@RestController +@RequestMapping("/nangman-letterbox") +@RequiredArgsConstructor +public class NangmanPostBoxController { + + private final NangmanPostBoxService nangmanPostBoxService; + private final RandomNicknameService randomNicknameService; + + @GetMapping("/send/random-nickname") + @ApiOperation(value = "낭만우편함 고민 편지에 사용될 랜덤 닉네임 생성") + public ApiResponse getRandomNickname(){ + try { + //랜덤 닉네임 생성 + String randomNickname = randomNicknameService.generateRandomNickname(); + + // 성공 응답 생성 + return ApiResponse.onSuccess(randomNickname); + } catch (Exception e){ + return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null); + } + } + + + @PostMapping("/send") + @ApiOperation(value = "낭만우편함 고민 편지 발송") + public ApiResponse sendLetter(@RequestBody NangmanPostBoxRequestDTO.SendLetterDTO request){ + try{ + //편지 작성 및 발송 +// String senderNickname = request.getSenderRandomNickname(); +// NangmanLetter nangmanLetter = nangmanPostBoxService.writeAndSendLetter(request, senderNickname); + NangmanLetter nangmanLetter = nangmanPostBoxService.writeAndSendLetter(request); + + + //성공 응답 생성 + return ApiResponse.onSuccess(NangmanPostBoxConverter.toSendLetterResultDTO(nangmanLetter)); + + }catch (Exception e){ + //에러 발생 시 실패 응답 반환 + return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null); + } + } + + @GetMapping("/letter-list") + @ApiOperation(value = "낭만우편함 답장하기 - 편지 목록") + public ApiResponse> getLetterList(){ + try{ + //편지 목록 조회 + List letterList = nangmanPostBoxService.getLetterList(); + + //편지 내용의 두 줄만 포함하도록 변환 + List letterSummaryDTOList = letterList.stream() + .map(NangmanPostBoxConverter::toLetterSummaryResultDTO) + .collect(Collectors.toList()); + + //성공 응답 생성 + return ApiResponse.onSuccess(letterSummaryDTOList); + }catch (Exception e){ + //에러 발생 시 실패 응답 반환 + return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null); + + } + } + + @GetMapping("/letter-list/{nangmanLetterId}") + @ApiOperation(value = "낭만우편함 답장할 편지 조회") + public ApiResponse getNangmanLetterInfo(@PathVariable Long nangmanLetterId){ + try{ + // 특정 편지에 대한 정보 조회 + NangmanLetter seledtedLetter = nangmanPostBoxService.getLetterById(nangmanLetterId); + + // 랜덤 닉네임 생성 + String randomNickname = randomNicknameService.generateRandomNickname(); + + //응답 생성 + NangmanPostBoxResponseDTO.SelectedLetterResultDTO selectedLetterResultDTO = NangmanPostBoxConverter.toReplyLetterResultDTO(seledtedLetter, randomNickname); + + return ApiResponse.onSuccess(selectedLetterResultDTO); + }catch (Exception e){ + + // 에러 발생 시 실패 응답 반환 + return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null); + } + } + + @PostMapping("/letter-list/{nangmanLetterId}") + @ApiOperation(value = "낭만우편함 답장하기 - 편지 발송") + public ApiResponse sendReply(@PathVariable Long nangmanLetterId, @RequestBody NangmanPostBoxRequestDTO.ReplyLetterDTO request){ + try{ + //답장 작성 및 발송 + NangmanReply nangmanReply = nangmanPostBoxService.writeAndSendReply(request, nangmanLetterId); + + //성공 응답 생성 + return ApiResponse.onSuccess(NangmanPostBoxConverter.toSendReplyResultDTO(nangmanReply)); + + + } catch(Exception e) { + // 에러 발생 시 실패 응답 반환 + return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null); + + } + } +} diff --git a/src/main/java/aromanticcat/umcproject/web/dto/NangmanPostBoxRequestDTO.java b/src/main/java/aromanticcat/umcproject/web/dto/NangmanPostBoxRequestDTO.java new file mode 100644 index 0000000..7338df1 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/web/dto/NangmanPostBoxRequestDTO.java @@ -0,0 +1,23 @@ +package aromanticcat.umcproject.web.dto; + +import lombok.Getter; + +public class NangmanPostBoxRequestDTO { + + @Getter + public static class SendLetterDTO { + + private Boolean isPublic; + private String content; + private String senderRandomNickname; + private Long memberId; + } + + @Getter + public static class ReplyLetterDTO { + + private String replySenderNickname; + private String replyContent; + private Long memberId; + } +} diff --git a/src/main/java/aromanticcat/umcproject/web/dto/NangmanPostBoxResponseDTO.java b/src/main/java/aromanticcat/umcproject/web/dto/NangmanPostBoxResponseDTO.java new file mode 100644 index 0000000..5db2c66 --- /dev/null +++ b/src/main/java/aromanticcat/umcproject/web/dto/NangmanPostBoxResponseDTO.java @@ -0,0 +1,62 @@ +package aromanticcat.umcproject.web.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +public class NangmanPostBoxResponseDTO { + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class SendLetterResultDTO { + + private Long nangmanLetterId; + + private String senderNickname; + + LocalDateTime createdAt; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class LetterSummaryResultDTO{ + private Long nangmanLetterId; + + private String preview; + + private LocalDateTime createdAt; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class SelectedLetterResultDTO { + private Long nangmanLetterId; + private String senderNickname; + private String replySenderNickname; + private String nangmanLetterContent; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class SendReplyResultDTO { + + private Long nangmanLetterId; + + private Long nangmanReplyId; + + private String replySenderNickname; + + LocalDateTime createdAt; + } +} diff --git a/src/test/java/aromanticcat/umcproject/repository/NangmanLetterRepositoryTests.java b/src/test/java/aromanticcat/umcproject/repository/NangmanLetterRepositoryTests.java deleted file mode 100644 index 26e5ebe..0000000 --- a/src/test/java/aromanticcat/umcproject/repository/NangmanLetterRepositoryTests.java +++ /dev/null @@ -1,84 +0,0 @@ -package aromanticcat.umcproject.repository; - -import aromanticcat.umcproject.entity.Member; -import aromanticcat.umcproject.entity.NangmanLetter; -import org.hibernate.Hibernate; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import javax.transaction.Transactional; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - - -@SpringBootTest -@Transactional -public class NangmanLetterRepositoryTests { - - @Autowired - private NangmanLetterRepository nangmanLetterRepository; - - @Autowired - private MemberRepository memberRepository; - - - @Test - public void testInsertNangmanLetter(){ - - Member member1 = Member.builder() - .email("test@email.com") - .nickname("member1") - .coin(0) - .build(); - memberRepository.save(member1); - - NangmanLetter nangmanLetter = NangmanLetter.builder() - .is_public(false) - .sender_nickname("낭만적인 고양이") - .content("제 고민을 들어주세요") - .member(member1) - .build(); - NangmanLetter result = nangmanLetterRepository.save(nangmanLetter); - - System.out.println(result); - } - - @Test - public void testSelectById(){ - Long id = 3L; - - Optional result = nangmanLetterRepository.findById(id); - NangmanLetter nangmanLetter = result.orElseThrow(); - - // 프록시 초기화 - Hibernate.initialize(nangmanLetter.getMember().getNangmanLetters()); - - // 영속성 컨텍스트에서 엔티티를 가져오는 것을 확인 - assertNotNull(nangmanLetter.getId()); - - // 출력 - System.out.println(nangmanLetter); - } - - @Test - public void testUpdateHasResponse(){ - Long id = 1L; - - Optional result = nangmanLetterRepository.findById(id); - - NangmanLetter nangmanLetter = result.orElseThrow(); - - nangmanLetter.change(true); - - nangmanLetterRepository.save(nangmanLetter); - } - - @Test - public void testDeleteNangmanLetter(){ - Long id = 1L; - - nangmanLetterRepository.deleteById(id); - } -} diff --git a/src/test/java/aromanticcat/umcproject/service/NangmanLetterServiceTests.java b/src/test/java/aromanticcat/umcproject/service/NangmanLetterServiceTests.java deleted file mode 100644 index fa86d31..0000000 --- a/src/test/java/aromanticcat/umcproject/service/NangmanLetterServiceTests.java +++ /dev/null @@ -1,53 +0,0 @@ -package aromanticcat.umcproject.service; - -import aromanticcat.umcproject.repository.MemberRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -public class NangmanLetterServiceTests { - - @Autowired - private NangmanLetterService nangmanLetterService; - - @Autowired - private MemberRepository memberRepository; - - @Autowired - private RandomNicknameService randomNicknameService; - -// @Test -// public void testRegister(){ -// System.out.println(nangmanLetterService.getClass().getName()); -// -// Member member1 = memberRepository.findById(1L).orElseThrow(() -> new RuntimeException("Member not found")); -// -// //랜덤 닉네임 생성 -// String randomNickname = randomNicknameService.generateRandomNickname(); -// -// NangmanLetterDTO nangmanLetterDTO = NangmanLetterDTO.builder() -// .content("낭만 편지 샘플3") -// .is_public(false) -// .member(member1) -// .build(); -// -// //생성된 랜덤 닉네임 설정 -// nangmanLetterDTO.setSender_nickname(randomNickname); -// -// Long id = nangmanLetterService.register(nangmanLetterDTO); -// -// System.out.println("id: " + id); -// } - -// @Test -// public void testModify(){ -// -// //변경에 필요한 데이터만 -// NangmanLetterDTO nangmanLetterDTO = NangmanLetterDTO.builder() -// .id(4L) -// .has_response(true) -// .build(); -// -// nangmanLetterService.modify(nangmanLetterDTO); -// } -}