diff --git a/.DS_Store b/.DS_Store index 88eb7c3..315acef 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index 042f2f3..735e131 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ brew update && brew install azure-cli ``` ``` -# 윈도우 +# 윈도우 powershell $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; Remove-Item .\AzureCLI.msi ``` @@ -287,7 +287,7 @@ https://portal.azure.com/#home 에 접속합니다. ![png](https://github.com/hackersground-kr/hg-crescendo-server/blob/main/images/az4.png) -1-1. Cosmos DB를 검색합니다. +1-1. Cosmos DB를 검색합니다. +만들기를 클릭합니다 1-2. Others 에 PostgreSQL 을 선택합니다. (만들기 클릭) diff --git a/crescendo-server/build.gradle b/crescendo-server/build.gradle index a6c8520..32c47a4 100644 --- a/crescendo-server/build.gradle +++ b/crescendo-server/build.gradle @@ -21,6 +21,7 @@ configurations { repositories { mavenCentral() + maven {url 'https://repo.spring.io/snapshot'} //스냅샷 저장소 추가 } dependencies { @@ -57,10 +58,10 @@ dependencies { testRuntimeOnly 'org.junit.platform:junit-platform-launcher' // spring AI -// implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:1.0.0-SNAPSHOT' + implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:1.0.0-SNAPSHOT' // 소켓 통신 -// implementation 'org.springframework.boot:spring-boot-starter-websocket' + implementation 'org.springframework.boot:spring-boot-starter-websocket' } diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/ai/controller/AiController.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/ai/controller/AiController.java new file mode 100644 index 0000000..a53abc6 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/ai/controller/AiController.java @@ -0,0 +1,21 @@ +package com.example.crescendoserver.domain.ai.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.ai.openai.OpenAiChatModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RequestMapping("/ai") +@RestController +@RequiredArgsConstructor +public class AiController { + private final OpenAiChatModel openAiChatModel; + + @GetMapping("/chat") + public String chat(@RequestParam String message) { + return openAiChatModel.call(String.valueOf(message)); + } + +} \ No newline at end of file diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/auth/service/AuthService.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/auth/service/AuthService.java index 0db7a5c..5523e1c 100644 --- a/crescendo-server/src/main/java/com/example/crescendoserver/domain/auth/service/AuthService.java +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/auth/service/AuthService.java @@ -3,6 +3,7 @@ import com.example.crescendoserver.domain.auth.dto.LoginRequest; import com.example.crescendoserver.domain.auth.dto.ReissueRequest; import com.example.crescendoserver.domain.auth.dto.SignUpRequest; +import com.example.crescendoserver.domain.user.domain.User; import com.example.crescendoserver.domain.user.dto.UserResponse; import com.example.crescendoserver.global.security.jwt.dto.Jwt; @@ -15,4 +16,6 @@ public interface AuthService { UserResponse me(); + User getUser(); + } diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/auth/service/AuthServiceImpl.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/auth/service/AuthServiceImpl.java index bb244ba..66bb2ce 100644 --- a/crescendo-server/src/main/java/com/example/crescendoserver/domain/auth/service/AuthServiceImpl.java +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/auth/service/AuthServiceImpl.java @@ -98,4 +98,13 @@ public UserResponse me() { return new UserResponse(user.getId(), user.getUsername(), user.getRole()); } + + @Override + public User getUser() { + String username = SecurityContextHolder.getContext().getAuthentication().getName(); + + return userRepository.findByUsername(username) + .orElseThrow(() -> new CustomException(CustomErrorCode.USER_NOT_FOUND)); + } } + diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/config/WebSockConfig.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/config/WebSockConfig.java new file mode 100644 index 0000000..f0952de --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/config/WebSockConfig.java @@ -0,0 +1,20 @@ +package com.example.crescendoserver.domain.chat.config; + +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; + +@RequiredArgsConstructor +@Configuration +@EnableWebSocket +public class WebSockConfig implements WebSocketConfigurer { + private final WebSocketHandler webSocketHandler; + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(webSocketHandler, "/ws/chat").setAllowedOrigins("*"); + } +} \ No newline at end of file diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/controller/ChatController.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/controller/ChatController.java new file mode 100644 index 0000000..925072a --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/controller/ChatController.java @@ -0,0 +1,29 @@ +package com.example.crescendoserver.domain.chat.controller; + +import com.example.crescendoserver.domain.chat.room.ChatRoom; +import com.example.crescendoserver.domain.chat.service.ChatService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/chat") +public class ChatController { + private final ChatService chatService; + + @PostMapping + public ChatRoom createRoom(@RequestParam String name) { + return chatService.createRoom(name); + } + + @GetMapping + public List findAllRoom() { + return chatService.findAllRoom(); + } +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/hadler/WebSockChatHandler.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/hadler/WebSockChatHandler.java new file mode 100644 index 0000000..4072f67 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/hadler/WebSockChatHandler.java @@ -0,0 +1,29 @@ +package com.example.crescendoserver.domain.chat.hadler; + +import com.example.crescendoserver.domain.chat.message.ChatMessage; +import com.example.crescendoserver.domain.chat.room.ChatRoom; +import com.example.crescendoserver.domain.chat.service.ChatService; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +@Slf4j +@RequiredArgsConstructor +@Component +public class WebSockChatHandler extends TextWebSocketHandler { + private final ObjectMapper objectMapper; + private final ChatService chatService; + + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + String payload = message.getPayload(); + log.info("payload {}", payload); + ChatMessage chatMessage = objectMapper.readValue(payload, ChatMessage.class); + ChatRoom room = chatService.findRoomById(chatMessage.getRoomId()); + room.handleActions(session, chatMessage, chatService); + } +} \ No newline at end of file diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/message/ChatMessage.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/message/ChatMessage.java new file mode 100644 index 0000000..456be3b --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/message/ChatMessage.java @@ -0,0 +1,23 @@ +package com.example.crescendoserver.domain.chat.message; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Builder +@Getter +@Setter +@RequiredArgsConstructor +@AllArgsConstructor +public class ChatMessage { + // 메시지 타입 : 입장, 채팅 + public enum MessageType { + ENTER, TALK + } + private MessageType type; // 메시지 타입 + private String roomId; // 방번호 + private String sender; // 메시지 보낸사람 + private String message; // 메시지 +} \ No newline at end of file diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/room/ChatRoom.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/room/ChatRoom.java new file mode 100644 index 0000000..1dea14d --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/room/ChatRoom.java @@ -0,0 +1,35 @@ +package com.example.crescendoserver.domain.chat.room; + +import com.example.crescendoserver.domain.chat.message.ChatMessage; +import com.example.crescendoserver.domain.chat.service.ChatService; +import lombok.Builder; +import lombok.Getter; +import org.springframework.web.socket.WebSocketSession; + +import java.util.HashSet; +import java.util.Set; + +@Getter +public class ChatRoom { + private String roomId; + private String name; + private Set sessions = new HashSet<>(); + + @Builder + public ChatRoom(String roomId, String name) { + this.roomId = roomId; + this.name = name; + } + + public void handleActions(WebSocketSession session, ChatMessage chatMessage, ChatService chatService) { + if (chatMessage.getType().equals(ChatMessage.MessageType.ENTER)) { + sessions.add(session); + chatMessage.setMessage(chatMessage.getSender() + "님이 입장했습니다."); + } + sendMessage(chatMessage, chatService); + } + + public void sendMessage(T message, ChatService chatService) { + sessions.parallelStream().forEach(session -> chatService.sendMessage(session, message)); + } +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/service/ChatService.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/service/ChatService.java new file mode 100644 index 0000000..d290b3d --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/chat/service/ChatService.java @@ -0,0 +1,57 @@ +package com.example.crescendoserver.domain.chat.service; + +import com.example.crescendoserver.domain.chat.room.ChatRoom; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.annotation.PostConstruct; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +@Slf4j +@RequiredArgsConstructor +@Service +public class ChatService { + + private final ObjectMapper objectMapper; + private Map chatRooms; + + @PostConstruct + private void init() { + chatRooms = new LinkedHashMap<>(); + } + + public List findAllRoom() { + return new ArrayList<>(chatRooms.values()); + } + + public ChatRoom findRoomById(String roomId) { + return chatRooms.get(roomId); + } + + public ChatRoom createRoom(String name) { + String randomId = UUID.randomUUID().toString(); + ChatRoom chatRoom = ChatRoom.builder() + .roomId(randomId) + .name(name) + .build(); + chatRooms.put(randomId, chatRoom); + return chatRoom; + } + + public void sendMessage(WebSocketSession session, T message) { + try { + session.sendMessage(new TextMessage(objectMapper.writeValueAsString(message))); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/comment/Comment.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/comment/Comment.java new file mode 100644 index 0000000..f5ef8e6 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/comment/Comment.java @@ -0,0 +1,56 @@ +package com.example.crescendoserver.domain.post.comment; + +import com.example.crescendoserver.domain.post.domain.Post; +import com.example.crescendoserver.domain.user.domain.User; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; + +import java.time.LocalDateTime; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Table(name = "comments") +@Entity +public class Comment { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(columnDefinition = "TEXT", nullable = false) + private String comment; + + @Column(name = "created_date") + @CreatedDate + private LocalDateTime createdDate; + + @Column(name = "modified_date") + @LastModifiedDate + private LocalDateTime modifiedDate; + + @ManyToOne + @JoinColumn(name = "post_id") + private Post post; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; // 작성자 + + //댓글 수정 + public void update(String comment) { + this.comment = comment; + } +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/domain/Post.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/domain/Post.java new file mode 100644 index 0000000..4630156 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/domain/Post.java @@ -0,0 +1,68 @@ +package com.example.crescendoserver.domain.post.domain; + + +import com.example.crescendoserver.domain.post.comment.Comment; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderBy; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; + +import java.time.LocalDateTime; +import java.util.List; + +@Entity +@Getter//모든필드에 대한 접근자 메서드 생성 +@Table(name = "posts") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Post { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + @Column(name="id",updatable = false) + private Long id; + + @Column(name="title",nullable = false) + private String title; + + @Column(name="content",nullable = false) + private String content; + + @Column(name="author",nullable = false) + private String author; + + + @Builder + public Post(String author,String title,String content,String comment){ + this.author = author; + this.title = title; + this.content = content; + } + + public void update(String title,String content){ + this.title = title; + this.content = content; + } + + @CreatedDate //엔티티가 생성될 때 생성 시간 저장 + @Column(name="created_at") + private LocalDateTime createdAt; + + @LastModifiedDate //엔티티가 수정될 때 수정 시간 저장 + @Column(name="updated_at") + private LocalDateTime updatedAt; + + @OneToMany(mappedBy = "posts", fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) + @OrderBy("id asc") // 댓글 정렬 + private List comments; +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/dto/AddCommentRequest.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/dto/AddCommentRequest.java new file mode 100644 index 0000000..1843342 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/dto/AddCommentRequest.java @@ -0,0 +1,32 @@ +package com.example.crescendoserver.domain.post.dto; + +import com.example.crescendoserver.domain.post.comment.Comment; +import com.example.crescendoserver.domain.user.domain.User; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class AddCommentRequest { + private Long id; + private String comment; + private String createdDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm")); + private String modifiedDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm")); + private String user; + private int article; + +// public Comment toEntity() { //생성자를 사용해 객체 생성 +// return Comment.builder() +// .comment(comment) +// .createdDate(LocalDateTime.parse(createdDate)) +// .modifiedDate(LocalDateTime.parse(modifiedDate)) +// .user(user) +// .article(article) +// .build(); +// } +} \ No newline at end of file diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/repository/CommentRepository.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/repository/CommentRepository.java new file mode 100644 index 0000000..f939a1e --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/repository/CommentRepository.java @@ -0,0 +1,8 @@ +package com.example.crescendoserver.domain.post.repository; + +import com.example.crescendoserver.domain.post.comment.Comment; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CommentRepository extends JpaRepository { +} + diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/controller/TodoController.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/controller/TodoController.java new file mode 100644 index 0000000..835b1bd --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/controller/TodoController.java @@ -0,0 +1,58 @@ +package com.example.crescendoserver.domain.todo.controller; + +import com.example.crescendoserver.domain.todo.domain.Todo; +import com.example.crescendoserver.domain.todo.dto.request.TodoCreateRequest; +import com.example.crescendoserver.domain.todo.dto.request.TodoEditRequest; +import com.example.crescendoserver.domain.todo.service.TodoService; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + + +@Tag(name = "투두", description = "ToDo") +@RestController +@RequestMapping("/posts") +@RequiredArgsConstructor +public class TodoController { + private final TodoService todoService; + + @PostMapping + public void createTodo(@RequestBody TodoCreateRequest todoCreateRequest) { + todoService.createTodo(todoCreateRequest); + } + + @GetMapping + public List getAllTodos() { + return todoService.getTodos(); + } + + @GetMapping("/{todoId}") + public Todo getTodo(@PathVariable Long todoId) { + return todoService.getTodo(todoId); + } + + @DeleteMapping("/{todoId}") + public void deleteTodo(@PathVariable Long todoId) { + todoService.deleteTodo(todoId); + } + + @PostMapping("/{todoId}") + public void checkTodo(@PathVariable Long todoId) { + todoService.todoCheck(todoId); + } + + @PatchMapping("/{todoId}") + public void editTodo(@PathVariable Long todoId, @RequestBody TodoEditRequest request) { + todoService.editTodo(todoId, request); + } +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/domain/Todo.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/domain/Todo.java new file mode 100644 index 0000000..014e19c --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/domain/Todo.java @@ -0,0 +1,45 @@ +package com.example.crescendoserver.domain.todo.domain; + + +import com.example.crescendoserver.domain.user.domain.User; +import com.example.crescendoserver.global.common.BaseEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +import java.time.LocalDate; + +@Entity +@Getter +@Setter +@SuperBuilder +@Table(name = "todos") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Todo extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String title; + + @ManyToOne() + @JoinColumn(name = "author_id", nullable = false) + private User author; + + @Column(nullable = false) + private Boolean checked = false; + + @Column(nullable = false) + private LocalDate date; +} \ No newline at end of file diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/dto/request/TodoCreateRequest.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/dto/request/TodoCreateRequest.java new file mode 100644 index 0000000..e2e99e2 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/dto/request/TodoCreateRequest.java @@ -0,0 +1,6 @@ +package com.example.crescendoserver.domain.todo.dto.request; + +import java.time.LocalDate; + +public record TodoCreateRequest(String title, LocalDate date) { +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/dto/request/TodoEditRequest.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/dto/request/TodoEditRequest.java new file mode 100644 index 0000000..de2e0df --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/dto/request/TodoEditRequest.java @@ -0,0 +1,6 @@ +package com.example.crescendoserver.domain.todo.dto.request; + +import java.time.LocalDate; + +public record TodoEditRequest(String title, LocalDate date) { +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/repository/TodoRepository.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/repository/TodoRepository.java new file mode 100644 index 0000000..c0528c4 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/repository/TodoRepository.java @@ -0,0 +1,11 @@ +package com.example.crescendoserver.domain.todo.repository; + +import com.example.crescendoserver.domain.todo.domain.Todo; +import com.example.crescendoserver.domain.user.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface TodoRepository extends JpaRepository { + List findAllByAuthorOrderByIdDesc(User author); +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/service/TodoService.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/service/TodoService.java new file mode 100644 index 0000000..f11962d --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/service/TodoService.java @@ -0,0 +1,21 @@ +package com.example.crescendoserver.domain.todo.service; + +import com.example.crescendoserver.domain.todo.domain.Todo; +import com.example.crescendoserver.domain.todo.dto.request.TodoCreateRequest; +import com.example.crescendoserver.domain.todo.dto.request.TodoEditRequest; + +import java.util.List; + +public interface TodoService { + void createTodo(TodoCreateRequest request); + + void deleteTodo(Long todoId); + + void editTodo(Long todoId, TodoEditRequest request); + + List getTodos(); + + Todo getTodo(Long todoId); + + void todoCheck(Long todoId); +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/service/TodoServiceImpl.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/service/TodoServiceImpl.java new file mode 100644 index 0000000..da36073 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/todo/service/TodoServiceImpl.java @@ -0,0 +1,64 @@ +package com.example.crescendoserver.domain.todo.service; + +import com.example.crescendoserver.domain.auth.service.AuthService; +import com.example.crescendoserver.domain.todo.domain.Todo; +import com.example.crescendoserver.domain.todo.dto.request.TodoCreateRequest; +import com.example.crescendoserver.domain.todo.dto.request.TodoEditRequest; +import com.example.crescendoserver.domain.todo.repository.TodoRepository; +import com.example.crescendoserver.domain.user.domain.User; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +@RequiredArgsConstructor +public class TodoServiceImpl implements TodoService { + private TodoRepository todoRepository; + private final AuthService authService; + + @Override + public void createTodo(TodoCreateRequest request) { + User user = authService.getUser(); + Todo todo = Todo.builder() + .title(request.title()) + .author(user) + .date(request.date()) + .checked(false) + .build(); + todoRepository.save(todo); + } + + @Override + public void deleteTodo(Long todoId) { + todoRepository.deleteById(todoId); + } + + @Override + public void editTodo(Long todoId, TodoEditRequest request) { + Todo todo = todoRepository.findById(todoId).orElse(null); + todo.setTitle(request.title()); + todo.setDate(request.date()); + + todoRepository.save(todo); + } + + @Override + public List getTodos() { + User user = authService.getUser(); + return todoRepository.findAllByAuthorOrderByIdDesc(user); + } + + @Override + public Todo getTodo(Long todoId) { + return todoRepository.findById(todoId).orElse(null); + } + + @Override + public void todoCheck(Long todoId) { + Todo todo = todoRepository.findById(todoId).orElse(null); + todo.setChecked(!todo.getChecked()); + todoRepository.save(todo); + } +} diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/global/config/security/SecurityConfig.java b/crescendo-server/src/main/java/com/example/crescendoserver/global/config/security/SecurityConfig.java index d8158d0..8ded9ca 100644 --- a/crescendo-server/src/main/java/com/example/crescendoserver/global/config/security/SecurityConfig.java +++ b/crescendo-server/src/main/java/com/example/crescendoserver/global/config/security/SecurityConfig.java @@ -49,7 +49,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers(HttpMethod.POST, "/auth/signup", "/auth/login", "/auth/reissue").anonymous() .requestMatchers(HttpMethod.GET, "/auth/me").authenticated() .requestMatchers(HttpMethod.GET, "/swagger-ui/**", "/v3/api-docs/**").permitAll() - .requestMatchers(HttpMethod.GET, "/api/chat").permitAll() + .requestMatchers(HttpMethod.GET, "/ai/chat").permitAll() .requestMatchers(HttpMethod.POST, "/ws/chat").permitAll() .requestMatchers(HttpMethod.GET, "/ws/chat").permitAll() .requestMatchers(HttpMethod.POST, "/chat").permitAll() diff --git a/crescendo-server/src/main/resources/application.yml b/crescendo-server/src/main/resources/application.yml index 1ffb5e3..f0ca524 100644 --- a/crescendo-server/src/main/resources/application.yml +++ b/crescendo-server/src/main/resources/application.yml @@ -12,14 +12,14 @@ spring: # dialect: org.hibernate.dialect.PostgreSQLDialect show-sql: true hibernate: - ddl-auto: update + ddl-auto: create -#ai: -# openai: -# api-key: ${CHATGPT_API_KEY} -# chat: -# options: -# model: gpt-3.5-turbo +ai: + openai: + api-key: ${CHATGPT_API_KEY} + chat: + options: + model: gpt-3.5-turbo redis: @@ -28,9 +28,21 @@ redis: password: 3333 jwt: - secret-key: c2lsdmVybmluZS10ZWNoLXNwcmluZy1ib290LWp3dC10dXRvcmlhbC1zZWNyZXQtc2lsdmVybmluZS10ZWNoLXNwcmluZy1ib290LWp3dC10dXRvcmlhbC1zZWNyZXQK + secret-key: ${SECRET_KEY} access-token-expiration: 300000 # 5m refresh-token-expiration: 86400000 # 24h server: port: 8088 + + +springdoc: + api-docs: + enabled: true + version: openapi_3_0 + path: /v3/api-docs + default-consumes-media-type: application/json + auto-tag-classes: true + swagger-ui: + operationsSorter: method + path: /swagger-ui.html \ No newline at end of file diff --git a/crescendo-web/.DS_Store b/crescendo-web/.DS_Store new file mode 100644 index 0000000..639e3d2 Binary files /dev/null and b/crescendo-web/.DS_Store differ diff --git a/images/.DS_Store b/images/.DS_Store new file mode 100644 index 0000000..d95a03b Binary files /dev/null and b/images/.DS_Store differ