diff --git a/src/main/java/Dogpaw/api/ChannelApiController.java b/src/main/java/Dogpaw/api/ChannelApiController.java new file mode 100644 index 0000000..e85c4fc --- /dev/null +++ b/src/main/java/Dogpaw/api/ChannelApiController.java @@ -0,0 +1,64 @@ +package Dogpaw.api; + + +import Dogpaw.domain.*; +import Dogpaw.dto.ChannelDTO; +import Dogpaw.dto.ResponseDTO; +import Dogpaw.service.ChannelService; +import Dogpaw.service.ChattingService; +import Dogpaw.service.IdeaBoardService; +import Dogpaw.service.IdeaService; +import Dogpaw.service.UserService; +import javassist.NotFoundException; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +public class ChannelApiController { + @NonNull + private final ChannelService channelService; + @NonNull + private final UserService userService; + @NonNull + private final ChattingService chattingService; + + @NonNull + private final IdeaBoardService ideaBoardService; + + @PostMapping("/channel") + public ResponseDTO.Create createUser(@RequestBody ChannelDTO.Create dto) throws ChannelService.InvalidArgumentException, ChannelService.ArgumentNullException, ChattingService.InvalidArgumentException, ChattingService.ArgumentNullException, IdeaBoardService.ArgumentNullException, IdeaBoardService.InvalidArgumentException{ + + Chatting chatting = new Chatting(); + IdeaBoard ideaBoard = new IdeaBoard(); + Long saveId2 = chattingService.saveChatting(chatting); + Long saveId3 = ideaBoardService.saveIdeaBoard(ideaBoard); + + Channel channel = new Channel(dto.getName(), dto.getPurpose(),chatting, ideaBoard); + + Long saveId = channelService.saveChannel(channel, dto.getUserId()); + + return new ResponseDTO.Create(saveId, true); + } + + @DeleteMapping("/channel") + public ResponseDTO.Delete createChat(@RequestBody ChannelDTO.Delete dto) throws NotFoundException { + channelService.deleteByChannelId(dto.getId()); + chattingService.deleteByChattingId(dto.getId()); + ideaBoardService.deleteByIdeaBoardId(dto.getId()); + + return new ResponseDTO.Delete(true); + } + + @GetMapping("/channel") + public ResponseDTO.ChannelResponse getChatting(@RequestBody ChannelDTO.Get dto) throws NotFoundException{ + User user = userService.findOne(dto.getUserId()); + List channelList = channelService.getChannelList(dto.getUserId()); + return new ResponseDTO.ChannelResponse(true, channelList); + + } +} diff --git a/src/main/java/Dogpaw/api/ChatApiController.java b/src/main/java/Dogpaw/api/ChatApiController.java index 1467ff2..87dc6ae 100644 --- a/src/main/java/Dogpaw/api/ChatApiController.java +++ b/src/main/java/Dogpaw/api/ChatApiController.java @@ -40,7 +40,4 @@ public ResponseDTO.Delete createChat(@RequestBody ChatDTO.Delete dto) throws Not chatService.deleteByChatId(dto.getId()); return new ResponseDTO.Delete(true); } - - - } diff --git a/src/main/java/Dogpaw/api/ChattingApiController.java b/src/main/java/Dogpaw/api/ChattingApiController.java index 79393ab..2328c4f 100644 --- a/src/main/java/Dogpaw/api/ChattingApiController.java +++ b/src/main/java/Dogpaw/api/ChattingApiController.java @@ -21,26 +21,12 @@ public class ChattingApiController { private final ChattingService chattingService; private final ChatService chatService; - @PostMapping("/chatting") - public ResponseDTO.Create createChatting (@RequestBody ChattingDTO.Create dto) throws ChattingService.ArgumentNullException, ChattingService.InvalidArgumentException{ - Chatting chatting = new Chatting(dto.getName(), dto.getPurpose()); - - Long saveId = chattingService.saveChatting(chatting); - - return new ResponseDTO.Create(saveId, true); - } - - @DeleteMapping("/chatting") - public ResponseDTO.Delete deleteChatting(@RequestBody ChattingDTO.Delete dto) throws NotFoundException{ - chattingService.deleteByChattingId(dto.getId()); - return new ResponseDTO.Delete(true); - } @GetMapping("/chatting") public ResponseDTO.ChattingResponse getChatting(@RequestBody ChattingDTO.Get dto) throws NotFoundException{ Chatting chatting = chattingService.findOne(dto.getId()); List chatList = chatService.getChatList(dto.getId()); - return new ResponseDTO.ChattingResponse(true, chatList, chatting); + return new ResponseDTO.ChattingResponse(true, chatting, chatList); } diff --git a/src/main/java/Dogpaw/api/CommentApiController.java b/src/main/java/Dogpaw/api/CommentApiController.java new file mode 100644 index 0000000..1dfb7fb --- /dev/null +++ b/src/main/java/Dogpaw/api/CommentApiController.java @@ -0,0 +1,49 @@ +package Dogpaw.api; + +import Dogpaw.domain.Chat; +import Dogpaw.domain.Comment; +import Dogpaw.domain.User; +import Dogpaw.dto.ChatDTO; +import Dogpaw.dto.CommentDTO; +import Dogpaw.dto.ResponseDTO; +import Dogpaw.service.ChatService; +import Dogpaw.service.CommentService; +import Dogpaw.service.UserService; +import javassist.NotFoundException; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +public class CommentApiController { + @NonNull + private final ChatService chatService; + @NonNull + private final CommentService commentService; + @NonNull + private final UserService userService; + + + @PostMapping("/comment") + public ResponseDTO.Create createComment(@RequestBody CommentDTO.Create dto) throws NotFoundException, CommentService.InvalidArgumentException, CommentService.ArgumentNullException { + Chat chat = chatService.findOne(dto.getChatId()); + User user = userService.findOne(dto.getUserId()); + + Comment comment = new Comment(user, dto.getText(),dto.getDate(), dto.getTime(), chat); + + Long saveId = commentService.saveComment(comment); + return new ResponseDTO.Create(saveId, true); + } + + + @DeleteMapping("/comment") + public ResponseDTO.Delete deleteComment(@RequestBody CommentDTO.Delete dto) throws NotFoundException { + commentService.deleteByCommentId(dto.getId()); + return new ResponseDTO.Delete(true); + } + + + +} diff --git a/src/main/java/Dogpaw/api/IdeaApiController.java b/src/main/java/Dogpaw/api/IdeaApiController.java index f61a06c..8ba22f2 100644 --- a/src/main/java/Dogpaw/api/IdeaApiController.java +++ b/src/main/java/Dogpaw/api/IdeaApiController.java @@ -1,60 +1,42 @@ package Dogpaw.api; - -import Dogpaw.domain.File; import Dogpaw.domain.Idea; +import Dogpaw.domain.IdeaBoard; +import Dogpaw.domain.User; import Dogpaw.dto.IdeaDTO; import Dogpaw.dto.ResponseDTO; -import Dogpaw.service.FileService; import Dogpaw.service.IdeaService; +import Dogpaw.service.IdeaBoardService; +import Dogpaw.service.UserService; import javassist.NotFoundException; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import java.util.ArrayList; -import java.util.List; @RestController @RequiredArgsConstructor @RequestMapping("/api") public class IdeaApiController { - @NonNull private final IdeaService IdeaService; - private final FileService FileService; - - @PostMapping("/Idea") - public ResponseDTO.Create createIdea(@RequestBody IdeaDTO.Create dto, @RequestParam MultipartFile[] uploadFiles) throws IdeaService.ArgumentNullException, IdeaService.InvalidArgumentException { -// List files = new ArrayList<>(); -// for(MultipartFile file : uploadFiles){ -// if(!file.isEmpty()){ -// String fileName = file.getOriginalFilename(); -// String contentType = file.getContentType(); -// String savePath = System.getProperty("user.dir") + "\\files"; -// if (!new File(savePath).exists()) { -// try{ -// new File(savePath).mkdir(); -// } -// catch(Exception e){ -// e.getStackTrace(); -// } -// } -// -// String filePath = savePath + "\\" + fileName; -// } -// } - - Idea Idea = new Idea(dto.getUser(), dto.getText(), dto.getDate()); + private final IdeaBoardService IdeaBoardService; + private final UserService userService; - Long saveId = IdeaService.saveIdea(Idea); + @PostMapping("/idea") + public ResponseDTO.Create createIdea(@RequestBody IdeaDTO.Create dto) throws IdeaService.ArgumentNullException, IdeaService.InvalidArgumentException, NotFoundException { + IdeaBoard ideaBoard = IdeaBoardService.findOne(dto.getIdeaBoardId()); + User user = userService.findOne(dto.getUserId()); + + Idea Idea = new Idea(user, dto.getText(),dto.getDate(), dto.getTime(), ideaBoard); + + Long saveId = IdeaService.saveIdea(Idea); return new ResponseDTO.Create(saveId, true); } - @DeleteMapping("/Idea") - public ResponseDTO.Delete deleteIdea(@RequestBody IdeaDTO.Delete dto) throws NotFoundException { + + @DeleteMapping("/idea") + public ResponseDTO.Delete createIdea(@RequestBody IdeaDTO.Delete dto) throws NotFoundException { IdeaService.deleteByIdeaId(dto.getId()); return new ResponseDTO.Delete(true); } diff --git a/src/main/java/Dogpaw/api/IdeaBoardApiController.java b/src/main/java/Dogpaw/api/IdeaBoardApiController.java new file mode 100644 index 0000000..0d2f66d --- /dev/null +++ b/src/main/java/Dogpaw/api/IdeaBoardApiController.java @@ -0,0 +1,33 @@ +package Dogpaw.api; + +import Dogpaw.domain.IdeaMapping; +import Dogpaw.domain.IdeaBoard; +import Dogpaw.dto.IdeaBoardDTO; +import Dogpaw.dto.ResponseDTO; +import Dogpaw.service.IdeaService; +import Dogpaw.service.IdeaBoardService; +import javassist.NotFoundException; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +public class IdeaBoardApiController { + @NonNull + private final IdeaBoardService IdeaBoardService; + private final IdeaService IdeaService; + + + @GetMapping("/ideaBoard") + public ResponseDTO.IdeaBoardResponse getIdeaBoard(@RequestBody IdeaBoardDTO.Get dto) throws NotFoundException{ + IdeaBoard IdeaBoard = IdeaBoardService.findOne(dto.getId()); + List IdeaList = IdeaService.getIdeaList(dto.getId()); + return new ResponseDTO.IdeaBoardResponse(true, IdeaBoard, IdeaList); + + } + +} diff --git a/src/main/java/Dogpaw/api/MessageAllApiController.java b/src/main/java/Dogpaw/api/MessageAllApiController.java deleted file mode 100644 index c8706e3..0000000 --- a/src/main/java/Dogpaw/api/MessageAllApiController.java +++ /dev/null @@ -1,46 +0,0 @@ -package Dogpaw.api; - -import Dogpaw.domain.MessageAll; -import Dogpaw.domain.MessageMapping; -import Dogpaw.dto.MessageAllDTO; -import Dogpaw.dto.ResponseDTO; -import Dogpaw.service.MessageAllService; -import Dogpaw.service.MessageService; -import javassist.NotFoundException; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api") -public class MessageAllApiController { - @NonNull - private final MessageAllService messageAllService; - private final MessageService messageService; - - @PostMapping("/messageall") - public ResponseDTO.Create createMessageAll (@RequestBody MessageAllDTO.Create dto) throws MessageAllService.ArgumentNullException, MessageAllService.InvalidArgumentException{ - MessageAll messageAll = new MessageAll(dto.getUser()); - - Long saveId = messageAllService.saveMessageAll(messageAll); - - return new ResponseDTO.Create(saveId, true); - } - - @DeleteMapping("/messageall") - public ResponseDTO.Delete deleteMessageAll(@RequestBody MessageAllDTO.Delete dto) throws NotFoundException { - messageService.deleteByMessageId(dto.getId()); - return new ResponseDTO.Delete(true); - } - - @GetMapping("/messageall") - public ResponseDTO.MessageAllResponse getMessageAll(@RequestBody MessageAllDTO.Get dto) throws NotFoundException { - MessageAll messageAll = messageAllService.findOne(dto.getId()); - List messageList = messageService.getMessageList(dto.getId()); - return new ResponseDTO.MessageAllResponse(true, messageList, messageAll); - } - -} diff --git a/src/main/java/Dogpaw/api/MessageApiController.java b/src/main/java/Dogpaw/api/MessageApiController.java deleted file mode 100644 index d9cd486..0000000 --- a/src/main/java/Dogpaw/api/MessageApiController.java +++ /dev/null @@ -1,50 +0,0 @@ -package Dogpaw.api; - -import Dogpaw.domain.Message; -import Dogpaw.domain.MessageAll; -import Dogpaw.domain.User; -import Dogpaw.dto.MessageDTO; -import Dogpaw.dto.ResponseDTO; -import Dogpaw.service.MessageAllService; -import Dogpaw.service.MessageService; -import Dogpaw.service.UserService; -import javassist.NotFoundException; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.*; - - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api") -public class MessageApiController { - - @NonNull - private final MessageService messageService; - private final MessageAllService messageAllService; - private final UserService userService; - - @PutMapping("/message") - public ResponseDTO.Create createMessage(@RequestBody MessageDTO.Create dto) throws MessageService.ArgumentNullException, MessageService.InvalidArgumentException, NotFoundException { - MessageAll messageAll = messageAllService.findOne(dto.getId()); - - Message message = new Message(dto.getSendBy(), dto.getText(), dto.getDate(), dto.getTime(), messageAll); - - Long saveId = messageService.saveMessage(message); - - return new ResponseDTO.Create(saveId, true); - } - - // ** 업데이트 추가 ** - @PutMapping("/message") - public ResponseDTO.Update updateMessage(@RequestBody MessageDTO.Update dto, String text) throws NotFoundException { - messageService.updateByMessageId(dto.getId(), dto.getText()); - return new ResponseDTO.Update(true); - } - - @DeleteMapping("/message") - public ResponseDTO.Delete deleteMessage(@RequestBody MessageDTO.Delete dto) throws NotFoundException { - messageService.deleteByMessageId(dto.getId()); - return new ResponseDTO.Delete(true); - } -} diff --git a/src/main/java/Dogpaw/domain/Channel.java b/src/main/java/Dogpaw/domain/Channel.java new file mode 100644 index 0000000..b5ab0f1 --- /dev/null +++ b/src/main/java/Dogpaw/domain/Channel.java @@ -0,0 +1,37 @@ +package Dogpaw.domain; + +import lombok.*; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor +public class Channel { + @Id @GeneratedValue (strategy = GenerationType.IDENTITY) + private Long id; + + @NonNull + private String name; + + @NonNull + private String purpose; + + @Getter(AccessLevel.NONE) + @OneToMany(mappedBy = "channel") + private List users = new ArrayList<>(); + + @NonNull + @OneToOne + @JoinColumn(name = "CHATTING_ID") + private Chatting chatting; + + @NonNull + @OneToOne + @JoinColumn(name = "IdeaBoard_ID") + private IdeaBoard ideaBoard; + +} diff --git a/src/main/java/Dogpaw/domain/Chat.java b/src/main/java/Dogpaw/domain/Chat.java index 292c6e6..363e174 100644 --- a/src/main/java/Dogpaw/domain/Chat.java +++ b/src/main/java/Dogpaw/domain/Chat.java @@ -6,6 +6,8 @@ import javax.persistence.*; import java.time.LocalDate; import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; @Entity @Setter @@ -35,4 +37,7 @@ public class Chat { @JoinColumn(name = "CHATTING_ID") private Chatting chatting; + @OneToMany(mappedBy = "chat", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) + private List comments = new ArrayList<>(); + } diff --git a/src/main/java/Dogpaw/domain/ChatMapping.java b/src/main/java/Dogpaw/domain/ChatMapping.java index ddf8b41..61d2d24 100644 --- a/src/main/java/Dogpaw/domain/ChatMapping.java +++ b/src/main/java/Dogpaw/domain/ChatMapping.java @@ -2,10 +2,12 @@ import java.time.LocalDate; import java.time.LocalTime; +import java.util.List; public interface ChatMapping { User getUser(); String getText(); LocalDate getDate(); LocalTime getTime(); + List getComments(); } diff --git a/src/main/java/Dogpaw/domain/Chatting.java b/src/main/java/Dogpaw/domain/Chatting.java index 2d2246b..708e16f 100644 --- a/src/main/java/Dogpaw/domain/Chatting.java +++ b/src/main/java/Dogpaw/domain/Chatting.java @@ -6,14 +6,8 @@ @Entity @Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@RequiredArgsConstructor +@NoArgsConstructor public class Chatting { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - - @NonNull - private String name; - @NonNull - private String purpose; } diff --git a/src/main/java/Dogpaw/domain/Message.java b/src/main/java/Dogpaw/domain/Comment.java similarity index 67% rename from src/main/java/Dogpaw/domain/Message.java rename to src/main/java/Dogpaw/domain/Comment.java index 532f0dc..0e59f27 100644 --- a/src/main/java/Dogpaw/domain/Message.java +++ b/src/main/java/Dogpaw/domain/Comment.java @@ -1,5 +1,6 @@ package Dogpaw.domain; + import lombok.*; import javax.persistence.*; @@ -7,30 +8,31 @@ import java.time.LocalTime; @Entity -@Getter @Setter +@Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @RequiredArgsConstructor -public class Message { - +public class Comment { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @ManyToOne + @JoinColumn(name = "USER_ID") @NonNull - private byte sendBy; // 내가 보내면 0, 상대가 보내면 1 + private User user; @NonNull private String text; @NonNull private LocalDate date; - @NonNull private LocalTime time; @NonNull @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "MESSEAGE_ID") - private MessageAll messageAll; + @JoinColumn(name = "CHAT_ID") + private Chat chat; + } diff --git a/src/main/java/Dogpaw/domain/MessageMapping.java b/src/main/java/Dogpaw/domain/CommentMapping.java similarity index 83% rename from src/main/java/Dogpaw/domain/MessageMapping.java rename to src/main/java/Dogpaw/domain/CommentMapping.java index a98ed11..a83de8d 100644 --- a/src/main/java/Dogpaw/domain/MessageMapping.java +++ b/src/main/java/Dogpaw/domain/CommentMapping.java @@ -3,7 +3,7 @@ import java.time.LocalDate; import java.time.LocalTime; -public interface MessageMapping { +public interface CommentMapping { User getUser(); String getText(); LocalDate getDate(); diff --git a/src/main/java/Dogpaw/domain/Idea.java b/src/main/java/Dogpaw/domain/Idea.java index 9d40517..164097b 100644 --- a/src/main/java/Dogpaw/domain/Idea.java +++ b/src/main/java/Dogpaw/domain/Idea.java @@ -3,33 +3,38 @@ import lombok.*; import javax.persistence.*; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.time.LocalDate; +import java.time.LocalTime; @Entity -@Getter @Setter -// why protected? +@Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -//builds constructor with @NonNull annotation @RequiredArgsConstructor public class Idea { - - @Id @GeneratedValue(strategy = GenerationType.AUTO) + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @ManyToOne + @JoinColumn(name = "USER_ID") @NonNull - private String user; + private User user; @NonNull private String text; @NonNull - private Date date; + private LocalDate date; + @NonNull + private LocalTime time; + + @NonNull + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "IdeaBoard_ID") + private IdeaBoard ideaBoard; + +} // @OneToMany // List files_ID = new ArrayList<>(); - -} \ No newline at end of file diff --git a/src/main/java/Dogpaw/domain/IdeaBoard.java b/src/main/java/Dogpaw/domain/IdeaBoard.java new file mode 100644 index 0000000..c4d1faf --- /dev/null +++ b/src/main/java/Dogpaw/domain/IdeaBoard.java @@ -0,0 +1,13 @@ +package Dogpaw.domain; + +import lombok.*; + +import javax.persistence.*; + +@Entity +@Getter +@NoArgsConstructor +public class IdeaBoard { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; +} diff --git a/src/main/java/Dogpaw/domain/IdeaMapping.java b/src/main/java/Dogpaw/domain/IdeaMapping.java new file mode 100644 index 0000000..6c0039c --- /dev/null +++ b/src/main/java/Dogpaw/domain/IdeaMapping.java @@ -0,0 +1,11 @@ +package Dogpaw.domain; + +import java.time.LocalDate; +import java.time.LocalTime; + +public interface IdeaMapping { + User getUser(); + String getText(); + LocalDate getDate(); + LocalTime getTime(); +} diff --git a/src/main/java/Dogpaw/domain/User.java b/src/main/java/Dogpaw/domain/User.java index c2593d8..101c543 100644 --- a/src/main/java/Dogpaw/domain/User.java +++ b/src/main/java/Dogpaw/domain/User.java @@ -3,6 +3,8 @@ import lombok.*; import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; @Entity @Getter @@ -15,4 +17,7 @@ public class User { @NonNull private String name; + + @OneToMany(mappedBy = "user") + private List userChannels = new ArrayList<>(); } diff --git a/src/main/java/Dogpaw/domain/MessageAll.java b/src/main/java/Dogpaw/domain/UserChannel.java similarity index 54% rename from src/main/java/Dogpaw/domain/MessageAll.java rename to src/main/java/Dogpaw/domain/UserChannel.java index eb3b2d7..095f2fd 100644 --- a/src/main/java/Dogpaw/domain/MessageAll.java +++ b/src/main/java/Dogpaw/domain/UserChannel.java @@ -6,15 +6,27 @@ @Entity @Getter +@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) -@RequiredArgsConstructor -public class MessageAll { +public class UserChannel { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @NonNull @ManyToOne @JoinColumn(name = "USER_ID") private User user; + + @ManyToOne + @JoinColumn(name = "CHANNEL_ID") + private Channel channel; + + @Builder + public UserChannel(User user, Channel channel){ + this.user = user; + this.channel = channel; + } + + } diff --git a/src/main/java/Dogpaw/domain/UserChannelMapping.java b/src/main/java/Dogpaw/domain/UserChannelMapping.java new file mode 100644 index 0000000..22a8cbc --- /dev/null +++ b/src/main/java/Dogpaw/domain/UserChannelMapping.java @@ -0,0 +1,7 @@ +package Dogpaw.domain; + +import java.util.List; + +public interface UserChannelMapping { + Channel getChannel(); +} diff --git a/src/main/java/Dogpaw/dto/ChannelDTO.java b/src/main/java/Dogpaw/dto/ChannelDTO.java new file mode 100644 index 0000000..2a2469d --- /dev/null +++ b/src/main/java/Dogpaw/dto/ChannelDTO.java @@ -0,0 +1,32 @@ +package Dogpaw.dto; + +import Dogpaw.domain.User; +import lombok.Data; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.List; + +public class ChannelDTO { + @Data + public static class Create extends Update { + + } + + @Data + public static class Update { + private String name; + private String purpose; + private Long userId; + } + + @Data + public static class Delete { + private Long id; + } + + @Data + public static class Get { + private Long userId; + } +} diff --git a/src/main/java/Dogpaw/dto/MessageDTO.java b/src/main/java/Dogpaw/dto/CommentDTO.java similarity index 78% rename from src/main/java/Dogpaw/dto/MessageDTO.java rename to src/main/java/Dogpaw/dto/CommentDTO.java index 84ea931..2fd889f 100644 --- a/src/main/java/Dogpaw/dto/MessageDTO.java +++ b/src/main/java/Dogpaw/dto/CommentDTO.java @@ -1,22 +1,21 @@ package Dogpaw.dto; -import Dogpaw.domain.User; + import lombok.Data; import java.time.LocalDate; import java.time.LocalTime; -public class MessageDTO { +public class CommentDTO { @Data public static class Create extends Update { - + private Long userId; + private Long chatId; } @Data public static class Update { - private Long id; - private byte sendBy; private String text; private LocalDate date; private LocalTime time; diff --git a/src/main/java/Dogpaw/dto/MessageAllDTO.java b/src/main/java/Dogpaw/dto/IdeaBoardDTO.java similarity index 65% rename from src/main/java/Dogpaw/dto/MessageAllDTO.java rename to src/main/java/Dogpaw/dto/IdeaBoardDTO.java index 416e6b2..ec0fd85 100644 --- a/src/main/java/Dogpaw/dto/MessageAllDTO.java +++ b/src/main/java/Dogpaw/dto/IdeaBoardDTO.java @@ -1,17 +1,17 @@ package Dogpaw.dto; -import Dogpaw.domain.User; import lombok.Data; -public class MessageAllDTO { +public class IdeaBoardDTO { @Data - public static class Create extends Update { + public static class Create extends Update{ } @Data public static class Update { - private User user; + private String name; + private String purpose; } @Data @@ -23,5 +23,4 @@ public static class Delete { public static class Get { private Long id; } - } diff --git a/src/main/java/Dogpaw/dto/IdeaDTO.java b/src/main/java/Dogpaw/dto/IdeaDTO.java index 998a1a3..e19bd79 100644 --- a/src/main/java/Dogpaw/dto/IdeaDTO.java +++ b/src/main/java/Dogpaw/dto/IdeaDTO.java @@ -1,28 +1,23 @@ package Dogpaw.dto; -import Dogpaw.domain.File; import lombok.Data; -import java.util.Date; -import java.util.List; +import java.time.LocalDate; +import java.time.LocalTime; public class IdeaDTO { @Data - public static class Create extends Update{ - + public static class Create extends Update { + private Long userId; + private Long ideaBoardId; } @Data public static class Update { - - private String user; - private String text; - - private Date date; - - List files; + private LocalDate date; + private LocalTime time; } @Data diff --git a/src/main/java/Dogpaw/dto/ResponseDTO.java b/src/main/java/Dogpaw/dto/ResponseDTO.java index afde49f..269f47d 100644 --- a/src/main/java/Dogpaw/dto/ResponseDTO.java +++ b/src/main/java/Dogpaw/dto/ResponseDTO.java @@ -43,8 +43,15 @@ public Delete(Boolean success) { @AllArgsConstructor public static class ChattingResponse { Boolean success; - private List chats; private Chatting chatting; + private List chats; + } + + @Data + @AllArgsConstructor + public static class ChannelResponse { + Boolean success; + private List channelList; } @Data @@ -55,4 +62,12 @@ public static class MessageAllResponse{ private MessageAll messageAll; } -} \ No newline at end of file + @Data + @AllArgsConstructor + public static class IdeaBoardResponse{ + Boolean success; + private IdeaBoard ideaBoard; + private List ideas; + } + +} diff --git a/src/main/java/Dogpaw/repository/ChannelRepository.java b/src/main/java/Dogpaw/repository/ChannelRepository.java new file mode 100644 index 0000000..596de15 --- /dev/null +++ b/src/main/java/Dogpaw/repository/ChannelRepository.java @@ -0,0 +1,11 @@ +package Dogpaw.repository; + +import Dogpaw.domain.Channel; +import Dogpaw.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ChannelRepository extends JpaRepository { + +} diff --git a/src/main/java/Dogpaw/repository/CommentRepository.java b/src/main/java/Dogpaw/repository/CommentRepository.java new file mode 100644 index 0000000..854ab3a --- /dev/null +++ b/src/main/java/Dogpaw/repository/CommentRepository.java @@ -0,0 +1,13 @@ +package Dogpaw.repository; + +import Dogpaw.domain.Chat; +import Dogpaw.domain.ChatMapping; +import Dogpaw.domain.Comment; +import Dogpaw.domain.CommentMapping; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface CommentRepository extends JpaRepository { +// List findAllByChat(Chat chat); +} diff --git a/src/main/java/Dogpaw/repository/IdeaBoardRepository.java b/src/main/java/Dogpaw/repository/IdeaBoardRepository.java new file mode 100644 index 0000000..f3092bf --- /dev/null +++ b/src/main/java/Dogpaw/repository/IdeaBoardRepository.java @@ -0,0 +1,8 @@ +package Dogpaw.repository; + +import Dogpaw.domain.IdeaBoard; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface IdeaBoardRepository extends JpaRepository { +// List findAllByUserOrderByName(String User); +} diff --git a/src/main/java/Dogpaw/repository/IdeaRepository.java b/src/main/java/Dogpaw/repository/IdeaRepository.java index a3f8718..8391486 100644 --- a/src/main/java/Dogpaw/repository/IdeaRepository.java +++ b/src/main/java/Dogpaw/repository/IdeaRepository.java @@ -1,10 +1,12 @@ package Dogpaw.repository; import Dogpaw.domain.Idea; +import Dogpaw.domain.IdeaMapping; +import Dogpaw.domain.IdeaBoard; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -@Repository -public interface IdeaRepository extends JpaRepository { +import java.util.List; +public interface IdeaRepository extends JpaRepository { + List findAllByIdeaBoard(IdeaBoard ideaBoard); } diff --git a/src/main/java/Dogpaw/repository/MessageAllRepository.java b/src/main/java/Dogpaw/repository/MessageAllRepository.java deleted file mode 100644 index 54f6f08..0000000 --- a/src/main/java/Dogpaw/repository/MessageAllRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package Dogpaw.repository; - -import Dogpaw.domain.MessageAll; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface MessageAllRepository extends JpaRepository { - -} diff --git a/src/main/java/Dogpaw/repository/MessageRepository.java b/src/main/java/Dogpaw/repository/MessageRepository.java deleted file mode 100644 index c9c8ad0..0000000 --- a/src/main/java/Dogpaw/repository/MessageRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package Dogpaw.repository; - -import Dogpaw.domain.Message; -import Dogpaw.domain.MessageAll; -import Dogpaw.domain.MessageMapping; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface MessageRepository extends JpaRepository { - List findAllMessage(MessageAll messageAll); -} diff --git a/src/main/java/Dogpaw/repository/UserChannelRepository.java b/src/main/java/Dogpaw/repository/UserChannelRepository.java new file mode 100644 index 0000000..cd7083d --- /dev/null +++ b/src/main/java/Dogpaw/repository/UserChannelRepository.java @@ -0,0 +1,13 @@ +package Dogpaw.repository; + +import Dogpaw.domain.Channel; +import Dogpaw.domain.User; +import Dogpaw.domain.UserChannel; +import Dogpaw.domain.UserChannelMapping; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface UserChannelRepository extends JpaRepository { + List findAllByUser(User User); +} diff --git a/src/main/java/Dogpaw/service/ChannelService.java b/src/main/java/Dogpaw/service/ChannelService.java new file mode 100644 index 0000000..ba05118 --- /dev/null +++ b/src/main/java/Dogpaw/service/ChannelService.java @@ -0,0 +1,87 @@ +package Dogpaw.service; + +import Dogpaw.domain.*; +import Dogpaw.repository.ChannelRepository; +import Dogpaw.repository.UserChannelRepository; +import Dogpaw.repository.UserRepository; +import javassist.NotFoundException; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + + +@Service +@Transactional +@RequiredArgsConstructor +public class ChannelService { + @NonNull + private final ChannelRepository channelRepository; + @NonNull + private final UserRepository userRepository; + @NonNull + private final UserChannelRepository userChannelRepository; + + public void addUser(Long userId, Long channelId){ + Channel channel = channelRepository.findById(channelId).get(); + User user = userRepository.findById(userId).get(); + + userChannelRepository.save(UserChannel.builder() + .user(user) + .channel(channel) + .build()); + + } + + public Long saveChannel (Channel channel, Long userId) throws ArgumentNullException, InvalidArgumentException, UserService.UserNotFoundException { + if(channel == null){ + throw new ArgumentNullException("Channel can't be null"); + } + if(channel.getName().isEmpty() || channel.getPurpose().isEmpty()){ + throw new InvalidArgumentException("Channel Id or URl is null"); + } + Channel save = channelRepository.save(channel); + addUser(userId, channel.getId()); + + return save.getId(); + + } + + public Channel findOne(Long id) throws NotFoundException { + Channel channel = channelRepository.findById(id).orElseThrow(() -> new ChannelNotFoundException("Channel with id : " + id + "is not valid")); + return channel; + } + + public List getChannelList(Long id) throws NotFoundException{ + User user = userRepository.findById(id).get(); + return userChannelRepository.findAllByUser(user); + } + + + + + + public void deleteByChannelId(Long id) throws NotFoundException { + channelRepository.deleteById(id); + } + + + + public static class ChannelNotFoundException extends NotFoundException { + public ChannelNotFoundException(String msg) { + super(msg); + } + } + + public static class ArgumentNullException extends Throwable { + public ArgumentNullException(String s) { + } + } + + public static class InvalidArgumentException extends Throwable { + public InvalidArgumentException(String s) { + } + } +} diff --git a/src/main/java/Dogpaw/service/ChattingService.java b/src/main/java/Dogpaw/service/ChattingService.java index 4b544aa..1d78eb0 100644 --- a/src/main/java/Dogpaw/service/ChattingService.java +++ b/src/main/java/Dogpaw/service/ChattingService.java @@ -22,11 +22,9 @@ public Long saveChatting (Chatting chatting) throws ArgumentNullException, Inval if(chatting == null){ throw new ArgumentNullException("Chatting can't be null"); } - if(chatting.getName().isEmpty()){ - throw new InvalidArgumentException("Chatting Name is null"); - } Chatting save = chattingRepository.save(chatting); + return save.getId(); } @@ -39,10 +37,6 @@ public Chatting findOne(Long id) throws NotFoundException{ return chatting; } -// public List getChattingList(String User){ -// return chattingRepository.findAllByUserOrderByName(User); -// } - // exception @@ -63,4 +57,4 @@ public InvalidArgumentException(String s) { } } -} +} \ No newline at end of file diff --git a/src/main/java/Dogpaw/service/CommentService.java b/src/main/java/Dogpaw/service/CommentService.java new file mode 100644 index 0000000..80258b8 --- /dev/null +++ b/src/main/java/Dogpaw/service/CommentService.java @@ -0,0 +1,72 @@ +package Dogpaw.service; + + +import Dogpaw.domain.Chat; +import Dogpaw.domain.ChatMapping; +import Dogpaw.domain.Chatting; +import Dogpaw.domain.Comment; +import Dogpaw.repository.ChatRepository; +import Dogpaw.repository.ChattingRepository; +import Dogpaw.repository.CommentRepository; +import javassist.NotFoundException; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; +import java.util.List; + +@Service +@Transactional +@RequiredArgsConstructor +public class CommentService { + @NonNull + private final ChatRepository chatRepository; + @NonNull + private final CommentRepository commentRepository; + + public Long saveComment (Comment comment) throws ArgumentNullException, InvalidArgumentException { + if(comment == null){ + throw new ArgumentNullException("Chat can't be null"); + } + if(comment.getText().isEmpty()){ + throw new InvalidArgumentException("Chatting text is null"); + } + comment.getChat().getComments().add(comment); + Comment save = commentRepository.save(comment); + + + return save.getId(); + } + + public void deleteByCommentId(Long id) throws NotFoundException{ + commentRepository.deleteById(id); + } + + public Comment findOne(Long id) throws NotFoundException{ + Comment comment = commentRepository.findById(id).orElseThrow(() -> new CommentNotFoundException("Comment with id : " + id + "is not valid")); + return comment; + } + + + + // exception + + public static class CommentNotFoundException extends NotFoundException { + public CommentNotFoundException(String msg) { + super(msg); + } + } + + public static class ArgumentNullException extends Throwable { + public ArgumentNullException(String s) { + } + } + + public static class InvalidArgumentException extends Throwable { + public InvalidArgumentException(String s) { + } + } +} + + diff --git a/src/main/java/Dogpaw/service/IdeaBoardService.java b/src/main/java/Dogpaw/service/IdeaBoardService.java new file mode 100644 index 0000000..39fd5fc --- /dev/null +++ b/src/main/java/Dogpaw/service/IdeaBoardService.java @@ -0,0 +1,55 @@ +package Dogpaw.service; + +import Dogpaw.domain.IdeaBoard; +import Dogpaw.repository.IdeaBoardRepository; +import javassist.NotFoundException; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class IdeaBoardService { + @NonNull + private final IdeaBoardRepository ideaBoardRepository; + + public Long saveIdeaBoard (IdeaBoard ideaBoard) throws ArgumentNullException, InvalidArgumentException{ + if(ideaBoard == null){ + throw new ArgumentNullException("IdeaBoard can't be null"); + } + IdeaBoard save = ideaBoardRepository.save(ideaBoard); + + return save.getId(); + } + + public void deleteByIdeaBoardId(Long id) throws NotFoundException{ + ideaBoardRepository.deleteById(id); + } + + public IdeaBoard findOne(Long id) throws NotFoundException{ + IdeaBoard IdeaBoard = ideaBoardRepository.findById(id).orElseThrow(() -> new IdeaBoardNotFoundException("IdeaBoard with id : "+ id + "is not valid")); + return IdeaBoard; + } + + +// exception + + public static class IdeaBoardNotFoundException extends NotFoundException { + public IdeaBoardNotFoundException(String msg) { + super(msg); + } + } + + public static class ArgumentNullException extends Throwable { + public ArgumentNullException(String s) { + } + } + + public static class InvalidArgumentException extends Throwable { + public InvalidArgumentException(String s) { + } + } + +} \ No newline at end of file diff --git a/src/main/java/Dogpaw/service/IdeaService.java b/src/main/java/Dogpaw/service/IdeaService.java index 911f38b..3ab2c03 100644 --- a/src/main/java/Dogpaw/service/IdeaService.java +++ b/src/main/java/Dogpaw/service/IdeaService.java @@ -1,12 +1,20 @@ package Dogpaw.service; + + import Dogpaw.domain.Idea; +import Dogpaw.domain.IdeaMapping; +import Dogpaw.domain.IdeaBoard; import Dogpaw.repository.IdeaRepository; +import Dogpaw.repository.IdeaBoardRepository; import javassist.NotFoundException; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; + +import javax.transaction.Transactional; +import java.util.List; + @Service @Transactional @@ -15,34 +23,38 @@ public class IdeaService { @NonNull private final IdeaRepository ideaRepository; + private final IdeaBoardRepository ideaBoardRepository; public Long saveIdea (Idea idea) throws ArgumentNullException, InvalidArgumentException { - //fail fast pattern - //if Argument is invalid, dont do any logic if(idea == null){ throw new ArgumentNullException("Idea can't be null"); } if(idea.getText().isEmpty()){ - throw new InvalidArgumentException("Idea text is null"); + throw new InvalidArgumentException("IdeaBoard text is null"); + } Idea save = ideaRepository.save(idea); return save.getId(); + } + public void deleteByIdeaId(Long id) throws NotFoundException{ + ideaRepository.deleteById(id); } - public Idea findOne(Long id) throws NotFoundException { - Idea idea = ideaRepository.findById(id).orElseThrow(() -> new IdeaNotFoundException("Idea with id : " + id + "is not valid")); + public Idea findOne(Long id) throws NotFoundException{ + Idea idea = ideaRepository.findById(id).orElseThrow(() -> new IdeaNotFoundException("Work space with id : " + id + "is not valid")); return idea; } + public List getIdeaList(Long id) throws NotFoundException{ + IdeaBoard ideaBoard = ideaBoardRepository.findById(id).orElseThrow(() -> new IdeaBoardService.IdeaBoardNotFoundException("IdeaBoard with id : "+ id + "is not valid")); + return ideaRepository.findAllByIdeaBoard(ideaBoard); + } - public void deleteByIdeaId(Long id) throws NotFoundException { - ideaRepository.deleteById(id); - - } + // exception public static class IdeaNotFoundException extends NotFoundException { public IdeaNotFoundException(String msg) { @@ -59,4 +71,4 @@ public static class InvalidArgumentException extends Throwable { public InvalidArgumentException(String s) { } } -} +} \ No newline at end of file diff --git a/src/main/java/Dogpaw/service/MessageAllService.java b/src/main/java/Dogpaw/service/MessageAllService.java deleted file mode 100644 index 995ab8c..0000000 --- a/src/main/java/Dogpaw/service/MessageAllService.java +++ /dev/null @@ -1,53 +0,0 @@ -package Dogpaw.service; - -import Dogpaw.domain.MessageAll; -import Dogpaw.repository.MessageAllRepository; -import javassist.NotFoundException; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import javax.transaction.Transactional; - -@Service -@Transactional -@RequiredArgsConstructor -public class MessageAllService { - @NonNull - private final MessageAllRepository messageAllRepository; - - public Long saveMessageAll(MessageAll messageAll) throws ArgumentNullException, InvalidArgumentException { - if (messageAll == null) { - throw new ArgumentNullException("MessageAll can't be null"); - } - MessageAll save = messageAllRepository.save(messageAll); - - return save.getId(); - } - - public void deleteByMessageAllId(Long id) throws NotFoundException { - messageAllRepository.deleteById(id); - } - - public MessageAll findOne(Long id) throws NotFoundException { - MessageAll messageAll = messageAllRepository.findById(id).orElseThrow(() -> new MessageAllNotFoundException("MessageAll with id : " + id + "is not valid")); - return messageAll; - } - - // exception - - public static class MessageAllNotFoundException extends NotFoundException { - public MessageAllNotFoundException(String msg) { - super(msg); - } - } - - public static class ArgumentNullException extends Throwable { - public ArgumentNullException(String s) {} - } - - public static class InvalidArgumentException extends Throwable { - public InvalidArgumentException(String s) {} - } - -} diff --git a/src/main/java/Dogpaw/service/MessageService.java b/src/main/java/Dogpaw/service/MessageService.java deleted file mode 100644 index ce629f2..0000000 --- a/src/main/java/Dogpaw/service/MessageService.java +++ /dev/null @@ -1,72 +0,0 @@ -package Dogpaw.service; - -import Dogpaw.domain.Message; -import Dogpaw.domain.MessageAll; -import Dogpaw.domain.MessageMapping; -import Dogpaw.repository.MessageAllRepository; -import Dogpaw.repository.MessageRepository; -import javassist.NotFoundException; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -@RequiredArgsConstructor -public class MessageService { - - @NonNull - private final MessageRepository messageRepository; - private final MessageAllRepository messageAllRepository; - - public Long saveMessage(Message message) throws ArgumentNullException, InvalidArgumentException { - if(message == null) { - throw new ArgumentNullException("Message can't be null"); - } - if(message.getText().isEmpty()){ - throw new InvalidArgumentException("Message TEXT is null"); - } - Message save = messageRepository.save(message); - - return save.getId(); - } - - public Message findOne(Long id) throws NotFoundException { - Message message = messageRepository.findById(id).orElseThrow(() -> new MessageNotFoundException("Message with id : " + id + "is not valid")); - return message; - } - - public void deleteByMessageId(Long id) throws NotFoundException { - messageRepository.deleteById(id); - } - - // ** 업데이트 추가 ** - public void updateByMessageId(Long id, String text) throws NotFoundException { - Message message = findOne(id); - message.setText(text); - messageRepository.save(message); - } - - public List getMessageList(Long id) throws NotFoundException { - MessageAll messageAll = messageAllRepository.findById(id).orElseThrow(() -> new MessageAllService.MessageAllNotFoundException("MessageAll with id : "+ id + "is not valid")); - return messageRepository.findAllMessage(messageAll); - } - - - // exception - - public static class MessageNotFoundException extends NotFoundException { - public MessageNotFoundException(String msg) { super(msg); } - } - - public static class ArgumentNullException extends Throwable { - public ArgumentNullException(String s) {} - } - - public static class InvalidArgumentException extends Throwable { - public InvalidArgumentException(String s) {} - } -}