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 index a53abc6..16584a9 100644 --- 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 @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.ai.openai.OpenAiChatModel; import org.springframework.web.bind.annotation.GetMapping; +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; @@ -14,7 +15,7 @@ public class AiController { private final OpenAiChatModel openAiChatModel; @GetMapping("/chat") - public String chat(@RequestParam String message) { + public String chat(@RequestBody String message) { return openAiChatModel.call(String.valueOf(message)); } 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 deleted file mode 100644 index f5ef8e6..0000000 --- a/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/comment/Comment.java +++ /dev/null @@ -1,56 +0,0 @@ -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 deleted file mode 100644 index 4630156..0000000 --- a/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/domain/Post.java +++ /dev/null @@ -1,68 +0,0 @@ -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 deleted file mode 100644 index 1843342..0000000 --- a/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/dto/AddCommentRequest.java +++ /dev/null @@ -1,32 +0,0 @@ -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 deleted file mode 100644 index f939a1e..0000000 --- a/crescendo-server/src/main/java/com/example/crescendoserver/domain/post/repository/CommentRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -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 index 835b1bd..c4e16ff 100644 --- 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 @@ -21,7 +21,7 @@ @Tag(name = "투두", description = "ToDo") @RestController -@RequestMapping("/posts") +@RequestMapping("/todos") @RequiredArgsConstructor public class TodoController { private final TodoService todoService; @@ -46,7 +46,7 @@ public void deleteTodo(@PathVariable Long todoId) { todoService.deleteTodo(todoId); } - @PostMapping("/{todoId}") + @PatchMapping("/{todoId}/check") public void checkTodo(@PathVariable Long todoId) { todoService.todoCheck(todoId); } 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 index c0528c4..49a7613 100644 --- 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 @@ -3,9 +3,11 @@ import com.example.crescendoserver.domain.todo.domain.Todo; import com.example.crescendoserver.domain.user.domain.User; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.util.List; +@Repository public interface TodoRepository extends JpaRepository { List findAllByAuthorOrderByIdDesc(User author); } 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 index da36073..b77f072 100644 --- 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 @@ -15,7 +15,7 @@ @Service @RequiredArgsConstructor public class TodoServiceImpl implements TodoService { - private TodoRepository todoRepository; + private final TodoRepository todoRepository; private final AuthService authService; @Override diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/user/domain/UserRole.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/user/domain/UserRole.java index 3ceec6b..1a40f00 100644 --- a/crescendo-server/src/main/java/com/example/crescendoserver/domain/user/domain/UserRole.java +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/user/domain/UserRole.java @@ -1,6 +1,5 @@ package com.example.crescendoserver.domain.user.domain; public enum UserRole { - USER, - ADMIN + USER } 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 8ded9ca..2190de5 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 @@ -54,6 +54,12 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers(HttpMethod.GET, "/ws/chat").permitAll() .requestMatchers(HttpMethod.POST, "/chat").permitAll() .requestMatchers(HttpMethod.GET, "/chat").permitAll() + .requestMatchers(HttpMethod.GET, "/todos/{todoId}").permitAll() + .requestMatchers(HttpMethod.GET, "/todos").permitAll() + .requestMatchers(HttpMethod.POST, "/todos").permitAll() + .requestMatchers(HttpMethod.PATCH, "/todos/{todoId}/check").permitAll() + .requestMatchers(HttpMethod.PATCH, "/todos/{todoId}").permitAll() + .requestMatchers(HttpMethod.DELETE, "/todos/{todoId}").permitAll() ) .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) diff --git a/crescendo-server/src/main/resources/application.yml b/crescendo-server/src/main/resources/application.yml index f0ca524..33a72ee 100644 --- a/crescendo-server/src/main/resources/application.yml +++ b/crescendo-server/src/main/resources/application.yml @@ -12,14 +12,12 @@ spring: # dialect: org.hibernate.dialect.PostgreSQLDialect show-sql: true hibernate: - ddl-auto: create - -ai: - openai: - api-key: ${CHATGPT_API_KEY} - chat: - options: - model: gpt-3.5-turbo + ddl-auto: update + + ai: + openai: + api-key: ${CHATGPT_API_KEY} + redis: