Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/main/java/com/likelion/session/SessionApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@SpringBootApplication // 스프링 부트 애플리케이션임을 나타냄
public class SessionApplication {

public static void main(String[] args) {
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/likelion/session/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

import java.util.List;

@RestController
@RequestMapping("/boards")
@RequiredArgsConstructor
@RestController // REST API 요청을 처리하는 컨트롤러 (JSON 형태로 응답)
@RequestMapping("/boards") // /boards 경로로 들어오는 요청을 이 컨트롤러가 처리
@RequiredArgsConstructor // final 필드를 사용하는 생성자를 자동 생성 (의존성 주입)
public class BoardController {

private final ;
Expand All @@ -32,7 +32,7 @@ public class BoardController {
-> 결과 반환
-> JSON 응답
*/
@Operation(
@Operation( // Swagger에서 API 설명을 작성하는 어노테이션
summary = "게시글 생성",
description = "새로운 게시글을 생성합니다."
)
Expand All @@ -43,7 +43,7 @@ public ResponseEntity<BoardResponse> create(@RequestBody BoardCreateRequest requ
}

// 게시글 전체 조회
@Operation(
@Operation( // Swagger API 설명
summary = "게시글 전체 조회",
description = "등록된 모든 게시글을 조회합니다."
)
Expand All @@ -54,36 +54,36 @@ public ResponseEntity<List<BoardResponse>> findAll() {
}

// 게시글 단건 조회
@Operation(
@Operation( // Swagger API 설명
summary = "게시글 단건 조회",
description = "id로 특정 게시글을 조회합니다."
)
@GetMapping("/{id}")
@GetMapping("/{id}") // URL 경로의 id 값을 받아서 조회
public ResponseEntity<BoardResponse> findById(@PathVariable Long id) {
BoardResponse response = boardService.findById(id);
return ResponseEntity.ok(response);
}

// 게시글 수정
@Operation(
@Operation( // Swagger API 설명
summary = "게시글 수정",
description = "id로 특정 게시글의 제목과 내용을 수정합니다."
)
@("/{id}")
@("/{id}") // HTTP PUT 요청 처리 (데이터 수정)
public ResponseEntity<BoardResponse> update(@PathVariable Long id,
@RequestBody BoardUpdateRequest request) {
@RequestBody BoardUpdateRequest request) { / 요청 body를 객체로 변환
BoardResponse response = boardService.update(id, request);
return ResponseEntity.ok(response);
}

// 게시글 삭제
@Operation(
@Operation( // Swagger API 설명
summary = "게시글 삭제",
description = "id로 특정 게시글을 삭제합니다."
)
@("/{id}")
@("/{id}") // HTTP DELETE 요청 처리 (데이터 삭제)
public ResponseEntity<Void> delete(@PathVariable Long id) {
boardService.delete(id);
return ResponseEntity.noContent().build();
}
}
}
26 changes: 13 additions & 13 deletions src/main/java/com/likelion/session/domain/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@

@Getter // getter 메서드 자동 생성
@Entity // 해당 클래스 DB 테이블로 인식하고 관리
@Table(name = "boards")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "boards") // DB 테이블 이름을 boards로 지정
@NoArgsConstructor(access = AccessLevel.PROTECTED) // 기본 생성자를 protected로 생성 (JPA에서 사용)
@AllArgsConstructor // 모든 필드를 포함한 생성자 생성
public class Board {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id // 기본 키(primary key) 지정
@GeneratedValue(strategy = GenerationType.IDENTITY) // DB가 자동으로 id 값 생성
private Long ;

// 게시글 제목
@Column(nullable = false, length = 100)
@Column(nullable = false, length = 100) // null 불가, 최대 길이 100
private String ;

// 게시글 내용
@Column(nullable = false, columnDefinition = "TEXT")
@Column(nullable = false, columnDefinition = "TEXT") // 긴 문자열(TEXT 타입), null 불가
private String ;

// 작성자
@Column(nullable = false, length = 30)
@Column(nullable = false, length = 30) // null 불가, 최대 길이 30
private String ;

// 생성 시간
@Column(nullable = false)
@Column(nullable = false) // null 불가
private LocalDateTime ;

// 수정 시간
@Column(nullable = false)
@Column(nullable = false) // null 불가
private LocalDateTime ;


Expand All @@ -46,13 +46,13 @@ public Board(String title, String content, String writer) {
this.writer = writer;
}

@PrePersist
@PrePersist // 엔티티가 DB에 저장되기 전에 실행되는 메서드
public void prePersist() {
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}

@PreUpdate
@PreUpdate // 엔티티가 수정되기 전에 실행되는 메서드
public void preUpdate() {
this.updatedAt = LocalDateTime.now();
}
Expand All @@ -62,4 +62,4 @@ public void update(String title, String content) {
this.title = title;
this.content = content;
}
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/likelion/session/dto/BoardCreateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Getter // 모든 필드의 getter 메서드를 자동 생성
@Setter // 모든 필드의 setter 메서드를 자동 생성
@NoArgsConstructor // 기본 생성자(파라미터 없는 생성자) 생성
@AllArgsConstructor // 모든 필드를 포함한 생성자 생성
public class BoardCreateRequest {
// 넘겨주고 싶은 정보: 제목(title), 내용(content), 작성자(writer)
private String ;
private String ;
private String ;
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/likelion/session/dto/BoardResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import java.time.LocalDateTime;

@Getter
@AllArgsConstructor
@Builder
@Getter // 모든 필드의 getter 메서드를 자동 생성
@AllArgsConstructor // 모든 필드를 포함한 생성자 생성
@Builder // 객체를 builder 패턴으로 생성할 수 있게 해줌 (가독성 좋은 객체 생성)
public class BoardResponse {

// 돌려주고 싶은 응답: id, title, content, writer, createdAt, updatedAt
Expand All @@ -18,4 +18,4 @@ public class BoardResponse {
private String writer;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/likelion/session/dto/BoardUpdateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

@Getter
@Setter
@NoArgsConstructor
@Getter // 모든 필드의 getter 메서드를 자동 생성
@Setter // 모든 필드의 setter 메서드를 자동 생성
@NoArgsConstructor // 기본 생성자 생성
public class BoardUpdateRequest {
@NotBlank(message = "제목은 필수입니다.")
@Size(max = 100, message = "제목은 100자 이하로 입력해주세요.")
@NotBlank(message = "제목은 필수입니다.") // null 또는 공백 문자열을 허용하지 않음 (필수값)
@Size(max = 100, message = "제목은 100자 이하로 입력해주세요.") // 문자열 길이를 100자 이하로 제한
private String title;

@NotBlank(message = "내용은 필수입니다.")
@NotBlank(message = "내용은 필수입니다.") // null 또는 공백을 허용하지 않음 (필수값)
private String content;
}