Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pots #26

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Pots #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# UMC Spring A팀 레포지토리입니다.
# erd
![스크린샷 2024-07-02 175331](https://github.com/UMC-CAU-6th/Spring-A/assets/65022037/c632642c-ba27-464d-862a-5d9f26be0bd2)

19 changes: 14 additions & 5 deletions umc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,34 @@ repositories {
}

dependencies {

//implementation group: 'com.mysql', name: 'mysql-connector-j', version: '8.0.33'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

testImplementation 'junit:junit:4.13.1'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'org.springframework.boot:spring-boot-starter-validation'


runtimeOnly 'com.mysql:mysql-connector-j'
implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '5.6.15.Final'
implementation 'mysql:mysql-connector-java:8.0.33'
// jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'

implementation 'org.springdoc:springdoc-openapi-ui:1.6.15'
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

//implementation 'io.springfox:springfox-swagger2:3.0.0'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
//implementation 'io.springfox:springfox-swagger-ui:2.9.2'

}

Expand Down
4 changes: 2 additions & 2 deletions umc/src/main/java/com/umc/common/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class SwaggerConfig {
@Bean
public OpenAPI SchrodingerApi() {
Info info = new Info()
.title("BuddyU API")
.description("BuddyU API 명세서")
.title("제목")
.description("명세서 설명")
.version("1.0.0");

String jwtSchemeName = "JWT TOKEN";
Expand Down
8 changes: 5 additions & 3 deletions umc/src/main/java/com/umc/common/entity/BaseTimeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@


import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Getter
@Setter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class) // Auditing 기능 포함
public abstract class BaseTimeEntity {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.umc.domain.board.controller;

import com.umc.common.response.ApiResponse;
import com.umc.domain.board.dto.BoardResponseDTO;
import com.umc.domain.board.service.BoardService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/board")
@RestController
public class BoardController {

private final BoardService boardService;

@CrossOrigin
@Operation(summary = "모든 게시판 조회 API")
@GetMapping("/")
public ApiResponse<List<BoardResponseDTO>> getALLBoards() {
List<BoardResponseDTO> boards = boardService.getAllBoards();
return ApiResponse.onSuccess(boards);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.umc.domain.board.dto;

import lombok.Data;

@Data
public class BoardRequestDTO {
private Long board_id;
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.umc.domain.board.dto;

import lombok.Data;

@Data
public class BoardResponseDTO {
private Long board_id;
private String name;
}
30 changes: 30 additions & 0 deletions umc/src/main/java/com/umc/domain/board/entity/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.umc.domain.board.entity;

import com.umc.common.entity.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "member")
public class Board extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "board_id")
private Long id;

@Column
private String name;



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.umc.domain.board.repository;


import com.umc.domain.board.entity.Board;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BoardRepository extends JpaRepository<Board, Long> {
}

31 changes: 31 additions & 0 deletions umc/src/main/java/com/umc/domain/board/service/BoardService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.umc.domain.board.service;

import com.umc.domain.board.dto.BoardResponseDTO;
import com.umc.domain.board.entity.Board;
import com.umc.domain.board.repository.BoardRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

@Service
@RequiredArgsConstructor
public class BoardService {

private final BoardRepository boardRepository;

public List<BoardResponseDTO> getAllBoards() {
List<Board> boards = boardRepository.findAll();
return boards.stream()
.map(this::convertToResponseDto)
.collect(Collectors.toList());
}

private BoardResponseDTO convertToResponseDto(Board board) {
BoardResponseDTO boardResponseDto = new BoardResponseDTO();
boardResponseDto.setBoard_id(board.getId());
boardResponseDto.setName(board.getName());
return boardResponseDto;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.umc.domain.comment.controller;

import com.umc.common.response.ApiResponse;
import com.umc.domain.comment.dto.CommentRequestDTO;
import com.umc.domain.comment.dto.CommentResponseDTO;
import com.umc.domain.comment.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/comment")
@RestController
public class CommentController {

private final CommentService commentService;

@CrossOrigin
@Operation(summary = "댓글 작성 API")
@PostMapping("/")
public ApiResponse<CommentResponseDTO> addComment(
@RequestBody CommentRequestDTO commentRequestDTO,
@RequestParam Long postId,
@RequestParam Long memberId) {
CommentResponseDTO createdComment = commentService.addComment(commentRequestDTO, postId, memberId);
return ApiResponse.onSuccess(createdComment);
}

@CrossOrigin
@Operation(summary = "댓글 수정 API")
@PostMapping("/{comment_id}")
public ApiResponse<CommentResponseDTO> modifyComment(
@PathVariable("comment_id") Long commentId,
@RequestBody CommentRequestDTO commentRequestDTO) {
CommentResponseDTO updatedComment = commentService.modifyComment(commentId, commentRequestDTO);
return ApiResponse.onSuccess(updatedComment);
}

@CrossOrigin
@Operation(summary = "특정 게시물 댓글 읽기 API")
@GetMapping("/{post_id}")
public ApiResponse<List<CommentResponseDTO>> getComments(@PathVariable("post_id") Long postId) {
List<CommentResponseDTO> comments = commentService.getCommentsByPostId(postId);
return ApiResponse.onSuccess(comments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.umc.domain.comment.dto;

import jakarta.validation.constraints.Pattern;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

@Builder
@Data
public class CommentRequestDTO {

@Pattern(regexp = "^[a-zA-z0-9]{1,50}$", message = "1 ~ 50자로 작성해 주십시오.")
private String body;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.umc.domain.comment.dto;

import lombok.Builder;
import lombok.Data;
import lombok.Getter;

import java.time.LocalDateTime;

@Builder
@Getter
@Data
public class CommentResponseDTO {
private Long comment_id;
private Long post_id;
private Long member_id;
private String nickname;
private String body;
private LocalDateTime createAt;
private LocalDateTime updateAt;
}
33 changes: 33 additions & 0 deletions umc/src/main/java/com/umc/domain/comment/entity/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.umc.domain.comment.entity;

import com.umc.common.entity.BaseTimeEntity;
import com.umc.domain.post.entity.Post;
import com.umc.domain.user.entity.Member;
import jakarta.persistence.*;
import lombok.*;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "comment")
public class Comment extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "comment_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private Post post;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@Column(name = "body", length = 50, nullable = false)
private String body;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.umc.domain.comment.repository;

import com.umc.domain.comment.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {
List<Comment> findByPostId(Long postId);
}
Loading