diff --git a/week03/src/main/java/.DS_Store b/week03/src/main/java/.DS_Store new file mode 100644 index 0000000..e6dc460 Binary files /dev/null and b/week03/src/main/java/.DS_Store differ diff --git a/week03/src/main/java/org/.DS_Store b/week03/src/main/java/org/.DS_Store new file mode 100644 index 0000000..ae6e1d8 Binary files /dev/null and b/week03/src/main/java/org/.DS_Store differ diff --git a/week03/src/main/java/org/sopt/.DS_Store b/week03/src/main/java/org/sopt/.DS_Store new file mode 100644 index 0000000..6364795 Binary files /dev/null and b/week03/src/main/java/org/sopt/.DS_Store differ diff --git a/week03/src/main/java/org/sopt/spring/Application.java b/week03/src/main/java/org/sopt/spring/Application.java new file mode 100644 index 0000000..9331693 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/Application.java @@ -0,0 +1,13 @@ +package org.sopt.spring; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/week03/src/main/java/org/sopt/spring/common/GlobalExceptionHandler.java b/week03/src/main/java/org/sopt/spring/common/GlobalExceptionHandler.java new file mode 100644 index 0000000..03cbeec --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/common/GlobalExceptionHandler.java @@ -0,0 +1,27 @@ +package org.sopt.spring.common; + + +import jakarta.persistence.EntityNotFoundException; +import org.sopt.spring.common.dto.ErrorMessage; +import org.sopt.spring.exception.NotFoundException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.sopt.spring.common.dto.ErrorResponse; + +import java.util.Objects; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(MethodArgumentNotValidException.class) + protected ResponseEntity handleMethodArgumentNotValidException(MethodArgumentNotValidException e){ + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ErrorResponse.of(HttpStatus.BAD_REQUEST.value(), Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage())); + } + @ExceptionHandler(NotFoundException.class) + protected ResponseEntity handleNotFoundException(NotFoundException e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ErrorResponse.of(e.getErrorMessage())); + } +} diff --git a/week03/src/main/java/org/sopt/spring/common/dto/ErrorMessage.java b/week03/src/main/java/org/sopt/spring/common/dto/ErrorMessage.java new file mode 100644 index 0000000..f9390e1 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/common/dto/ErrorMessage.java @@ -0,0 +1,16 @@ +package org.sopt.spring.common.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ErrorMessage { + MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "ID에 해당하는 사용자가 존재하지 않습니다."), + + BLOG_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "ID에 해당하는 블로그가 없습니다."), + ; + private final int status; + private final String message; +} diff --git a/week03/src/main/java/org/sopt/spring/common/dto/ErrorResponse.java b/week03/src/main/java/org/sopt/spring/common/dto/ErrorResponse.java new file mode 100644 index 0000000..3a645b7 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/common/dto/ErrorResponse.java @@ -0,0 +1,14 @@ +package org.sopt.spring.common.dto; + +public record ErrorResponse( + int status, + String message +) { + public static ErrorResponse of(int status, String message) { + return new ErrorResponse(status, message); + } + + public static ErrorResponse of(ErrorMessage errorMessage) { + return new ErrorResponse(errorMessage.getStatus(), errorMessage.getMessage()); + } +} diff --git a/week03/src/main/java/org/sopt/spring/common/dto/SuccessMessage.java b/week03/src/main/java/org/sopt/spring/common/dto/SuccessMessage.java new file mode 100644 index 0000000..8e87c83 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/common/dto/SuccessMessage.java @@ -0,0 +1,18 @@ +package org.sopt.spring.common.dto; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum SuccessMessage { + + BLOG_CREATE_SUCCESS(HttpStatus.CREATED.value(),"블로그 생성이 완료되었습니다."), + POST_CREATE_SUCCESS(HttpStatus.CREATED.value(), "게시글이 생성되었습니다."); + + + private final int status; + private final String message; +} diff --git a/week03/src/main/java/org/sopt/spring/common/dto/SuccessStatusResponse.java b/week03/src/main/java/org/sopt/spring/common/dto/SuccessStatusResponse.java new file mode 100644 index 0000000..381219c --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/common/dto/SuccessStatusResponse.java @@ -0,0 +1,11 @@ +package org.sopt.spring.common.dto; + +public record SuccessStatusResponse( + int status, + String message +) { + + public static SuccessStatusResponse of(SuccessMessage successMessage) { + return new SuccessStatusResponse(successMessage.getStatus(), successMessage.getMessage()); + } +} diff --git a/week03/src/main/java/org/sopt/spring/config/JpaAuditingConfig.java b/week03/src/main/java/org/sopt/spring/config/JpaAuditingConfig.java new file mode 100644 index 0000000..1d247eb --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/config/JpaAuditingConfig.java @@ -0,0 +1,9 @@ +package org.sopt.spring.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@EnableJpaAuditing +@Configuration +public class JpaAuditingConfig { +} diff --git a/week03/src/main/java/org/sopt/spring/controller/BlogController.java b/week03/src/main/java/org/sopt/spring/controller/BlogController.java new file mode 100644 index 0000000..3651c78 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/controller/BlogController.java @@ -0,0 +1,46 @@ +package org.sopt.spring.controller; + +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.sopt.spring.common.dto.SuccessMessage; +import org.sopt.spring.common.dto.SuccessStatusResponse; +import org.sopt.spring.service.BlogService; +import org.sopt.spring.service.dto.BlogCreateRequest; +import org.sopt.spring.service.dto.BlogTitleUpdateRequest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +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.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1") +@RequiredArgsConstructor +public class BlogController { + + private final BlogService blogService; + + @PostMapping("/blog") + public ResponseEntity createBlog( + @RequestHeader(name = "memberId") Long memberId, + @RequestBody BlogCreateRequest blogCreateRequest + ) { + return ResponseEntity.status(HttpStatus.CREATED).header( + "Location", + blogService.create(memberId, blogCreateRequest)) + .body(SuccessStatusResponse.of(SuccessMessage.BLOG_CREATE_SUCCESS)); + } + + @PatchMapping("/blog/{blogId}/title") + public ResponseEntity updateBlogTitle( + @PathVariable Long blogId, + @Valid @RequestBody BlogTitleUpdateRequest blogTitleUpdateRequest + ) { + blogService.updateTitle(blogId, blogTitleUpdateRequest); + return ResponseEntity.noContent().build(); + } +} diff --git a/week03/src/main/java/org/sopt/spring/controller/MemberController.java b/week03/src/main/java/org/sopt/spring/controller/MemberController.java new file mode 100644 index 0000000..ab92021 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/controller/MemberController.java @@ -0,0 +1,47 @@ +package org.sopt.spring.controller; + + +import lombok.RequiredArgsConstructor; +import org.sopt.spring.service.MemberService; +import org.sopt.spring.service.dto.MemberCreateDto; +import org.sopt.spring.service.dto.MemberFindDto; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +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.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.net.URI; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/member") +public class MemberController { + + private final MemberService memberService; + + @PostMapping + public ResponseEntity createMember( + @RequestBody MemberCreateDto memberCreateDto + ) { + return ResponseEntity.created(URI.create(memberService.createMember(memberCreateDto))) + .build(); + } + + @GetMapping("/{memberId}") + public ResponseEntity findMemberById(@PathVariable Long memberId) { + return ResponseEntity.ok(memberService.findMemberById(memberId)); + } + + @DeleteMapping("/{memberId}") + public ResponseEntity deleteMemberById(@PathVariable Long memberId){ + memberService.deleteMemberById(memberId); + return ResponseEntity.noContent().build(); + } + + +} diff --git a/week03/src/main/java/org/sopt/spring/controller/PostController.java b/week03/src/main/java/org/sopt/spring/controller/PostController.java new file mode 100644 index 0000000..95a58d8 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/controller/PostController.java @@ -0,0 +1,29 @@ +package org.sopt.spring.controller; + +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.sopt.spring.common.dto.SuccessStatusResponse; +import org.sopt.spring.service.PostService; +import org.sopt.spring.service.dto.PostCreateRequest; +import org.sopt.spring.common.dto.SuccessMessage; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/v1") +@RequiredArgsConstructor +public class PostController { + + private final PostService postService; + + @PostMapping("/posts") + public ResponseEntity createPost( + @RequestHeader Long blogId, + @Valid @RequestBody PostCreateRequest postCreateRequest) { + return ResponseEntity.status(HttpStatus.CREATED).header( + "Location", + postService.create(blogId, postCreateRequest)) + .body(SuccessStatusResponse.of(SuccessMessage.POST_CREATE_SUCCESS)); + } +} diff --git a/week03/src/main/java/org/sopt/spring/domain/BaseTimeEntity.java b/week03/src/main/java/org/sopt/spring/domain/BaseTimeEntity.java new file mode 100644 index 0000000..0ea75c9 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/domain/BaseTimeEntity.java @@ -0,0 +1,21 @@ +package org.sopt.spring.domain; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + + +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseTimeEntity { + + @CreatedDate + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; +} diff --git a/week03/src/main/java/org/sopt/spring/domain/Blog.java b/week03/src/main/java/org/sopt/spring/domain/Blog.java new file mode 100644 index 0000000..6b10079 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/domain/Blog.java @@ -0,0 +1,45 @@ +package org.sopt.spring.domain; + +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.OneToOne; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.sopt.spring.service.dto.BlogCreateRequest; +import org.sopt.spring.service.dto.BlogTitleUpdateRequest; + +@Entity +@Getter +@NoArgsConstructor +public class Blog extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + private Member member; + + @Column(length = 200) + private String title; + + private String description; + + private Blog(Member member, String title, String description) { + this.member = member; + this.title = title; + this.description = description; + } + + public static Blog create(Member member, BlogCreateRequest blogCreateRequest) { + return new Blog(member, blogCreateRequest.title(), blogCreateRequest.description()); + } + + public void updateTitle(BlogTitleUpdateRequest blogTitleUpdateRequest) { + this.title = blogTitleUpdateRequest.title(); + } +} diff --git a/week03/src/main/java/org/sopt/spring/domain/Member.java b/week03/src/main/java/org/sopt/spring/domain/Member.java new file mode 100644 index 0000000..e743ed7 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/domain/Member.java @@ -0,0 +1,43 @@ +package org.sopt.spring.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor +public class Member { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @Enumerated(EnumType.STRING) + private Part part; + + private int age; + + @Builder + private Member(String name, Part part, int age) { + this.name = name; + this.part = part; + this.age = age; + } + + public static Member create(String name, Part part, int age) { + return Member.builder() + .name(name) + .age(age) + .part(part) + .build(); + } +} diff --git a/week03/src/main/java/org/sopt/spring/domain/Part.java b/week03/src/main/java/org/sopt/spring/domain/Part.java new file mode 100644 index 0000000..eefaf1e --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/domain/Part.java @@ -0,0 +1,10 @@ +package org.sopt.spring.domain; + +public enum Part { + IOS, + SERVER, + ANDROID, + WEB, + PLAN, + DESIGN +} diff --git a/week03/src/main/java/org/sopt/spring/domain/Post.java b/week03/src/main/java/org/sopt/spring/domain/Post.java new file mode 100644 index 0000000..682e34b --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/domain/Post.java @@ -0,0 +1,42 @@ +package org.sopt.spring.domain; + + +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor +public class Post extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + + private String content; + + @ManyToOne(fetch = FetchType.LAZY) + private Blog blog; + + public Post(String title, String content, Blog blog) { + this.title = title; + this.content = content; + this.blog = blog; + } + + public static Post create(Blog blog, String title, String content) { + Post post = new Post(); + post.blog = blog; + post.title = title; + post.content = content; + return post; + } +} diff --git a/week03/src/main/java/org/sopt/spring/exception/BusinessException.java b/week03/src/main/java/org/sopt/spring/exception/BusinessException.java new file mode 100644 index 0000000..83c344e --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/exception/BusinessException.java @@ -0,0 +1,14 @@ +package org.sopt.spring.exception; + +import lombok.Getter; +import org.sopt.spring.common.dto.ErrorMessage; + +@Getter +public class BusinessException extends RuntimeException{ + private ErrorMessage errorMessage; + + public BusinessException(ErrorMessage errorMessage) { + super(errorMessage.getMessage()); + this.errorMessage = errorMessage; + } +} diff --git a/week03/src/main/java/org/sopt/spring/exception/NotFoundException.java b/week03/src/main/java/org/sopt/spring/exception/NotFoundException.java new file mode 100644 index 0000000..41ddc67 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/exception/NotFoundException.java @@ -0,0 +1,9 @@ +package org.sopt.spring.exception; + +import org.sopt.spring.common.dto.ErrorMessage; + +public class NotFoundException extends BusinessException { + public NotFoundException(ErrorMessage errorMessage) { + super(errorMessage); + } +} diff --git a/week03/src/main/java/org/sopt/spring/repository/BlogRepository.java b/week03/src/main/java/org/sopt/spring/repository/BlogRepository.java new file mode 100644 index 0000000..c039b2d --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/repository/BlogRepository.java @@ -0,0 +1,7 @@ +package org.sopt.spring.repository; + +import org.sopt.spring.domain.Blog; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BlogRepository extends JpaRepository { +} \ No newline at end of file diff --git a/week03/src/main/java/org/sopt/spring/repository/MemberRepository.java b/week03/src/main/java/org/sopt/spring/repository/MemberRepository.java new file mode 100644 index 0000000..89331e0 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/repository/MemberRepository.java @@ -0,0 +1,8 @@ +package org.sopt.spring.repository; + +import org.sopt.spring.domain.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberRepository extends JpaRepository { + +} diff --git a/week03/src/main/java/org/sopt/spring/repository/PostRepository.java b/week03/src/main/java/org/sopt/spring/repository/PostRepository.java new file mode 100644 index 0000000..b97f8f8 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/repository/PostRepository.java @@ -0,0 +1,9 @@ +package org.sopt.spring.repository; + +import org.sopt.spring.domain.Post; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PostRepository extends JpaRepository { + + +} diff --git a/week03/src/main/java/org/sopt/spring/service/BlogService.java b/week03/src/main/java/org/sopt/spring/service/BlogService.java new file mode 100644 index 0000000..f09f560 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/service/BlogService.java @@ -0,0 +1,38 @@ +package org.sopt.spring.service; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.sopt.spring.common.dto.ErrorMessage; +import org.sopt.spring.domain.Blog; +import org.sopt.spring.domain.Member; +import org.sopt.spring.exception.NotFoundException; +import org.sopt.spring.repository.BlogRepository; +import org.sopt.spring.service.dto.BlogCreateRequest; +import org.sopt.spring.service.dto.BlogTitleUpdateRequest; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class BlogService { + private final BlogRepository blogRepository; + private final MemberService memberService; + + + public String create(Long memberId, BlogCreateRequest blogCreateRequest) { + Member member = memberService.findById(memberId); + Blog blog = blogRepository.save(Blog.create(member, blogCreateRequest)); + return blog.getId().toString(); + } + + protected Blog findById(Long blogId) { + return blogRepository.findById(blogId).orElseThrow( + () -> new NotFoundException(ErrorMessage.BLOG_NOT_FOUND) + ); + } + + @Transactional + public void updateTitle(Long blogId, BlogTitleUpdateRequest blogTitleUpdateRequest) { + Blog blog = findById(blogId); + blog.updateTitle(blogTitleUpdateRequest); + } +} diff --git a/week03/src/main/java/org/sopt/spring/service/MemberService.java b/week03/src/main/java/org/sopt/spring/service/MemberService.java new file mode 100644 index 0000000..afee2f9 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/service/MemberService.java @@ -0,0 +1,46 @@ +package org.sopt.spring.service; + +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; +import org.sopt.spring.common.dto.ErrorMessage; +import org.sopt.spring.domain.Member; +import org.sopt.spring.exception.NotFoundException; +import org.sopt.spring.repository.MemberRepository; +import org.sopt.spring.service.dto.MemberCreateDto; +import org.sopt.spring.service.dto.MemberFindDto; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberService { + + private final MemberRepository memberRepository; + + @Transactional + public String createMember( + MemberCreateDto memberCreateDto + ) { + Member member = Member.create(memberCreateDto.name(), memberCreateDto.part(), memberCreateDto.age()); + memberRepository.save(member); + return member.getId().toString(); + } + + public Member findById(Long memberId) { + return memberRepository.findById(memberId).orElseThrow( + () -> new NotFoundException(ErrorMessage.MEMBER_NOT_FOUND) + ); + } + public MemberFindDto findMemberById(Long memberId) { + return MemberFindDto.of(memberRepository.findById(memberId).orElseThrow( + () -> new EntityNotFoundException("ID에 해당하는 사용자가 존재하지 않습니다.") + )); + } + + @Transactional + public void deleteMemberById(Long memberId) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new EntityNotFoundException("ID에 해당하는 사용자가 존재하지 않습니다.")); + memberRepository.delete(member); + } +} diff --git a/week03/src/main/java/org/sopt/spring/service/PostService.java b/week03/src/main/java/org/sopt/spring/service/PostService.java new file mode 100644 index 0000000..5ca4ce9 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/service/PostService.java @@ -0,0 +1,23 @@ +package org.sopt.spring.service; + +import lombok.RequiredArgsConstructor; +import org.sopt.spring.domain.Blog; +import org.sopt.spring.domain.Post; +import org.sopt.spring.repository.PostRepository; +import org.sopt.spring.service.dto.PostCreateRequest; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PostService { + + private final PostRepository postRepository; + private final BlogService blogService; + public String create(Long blogId, PostCreateRequest postCreateRequest) { + Blog blog = blogService.findById(blogId); + Post post = new Post(postCreateRequest.title(), postCreateRequest.content(),blog); + post = postRepository.save(post); + return post.getId().toString(); + } +} + diff --git a/week03/src/main/java/org/sopt/spring/service/dto/BlogCreateRequest.java b/week03/src/main/java/org/sopt/spring/service/dto/BlogCreateRequest.java new file mode 100644 index 0000000..76a43d6 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/service/dto/BlogCreateRequest.java @@ -0,0 +1,7 @@ +package org.sopt.spring.service.dto; + +public record BlogCreateRequest( + String title, + String description +) { +} diff --git a/week03/src/main/java/org/sopt/spring/service/dto/BlogTitleUpdateRequest.java b/week03/src/main/java/org/sopt/spring/service/dto/BlogTitleUpdateRequest.java new file mode 100644 index 0000000..6fa58ef --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/service/dto/BlogTitleUpdateRequest.java @@ -0,0 +1,8 @@ +package org.sopt.spring.service.dto; + +import jakarta.validation.constraints.Size; + +public record BlogTitleUpdateRequest( + @Size(max = 10, message = "블로그 제목이 최대 글자 수(10자)를 초과했습니다.") String title +) { +} diff --git a/week03/src/main/java/org/sopt/spring/service/dto/MemberCreateDto.java b/week03/src/main/java/org/sopt/spring/service/dto/MemberCreateDto.java new file mode 100644 index 0000000..f4e84e9 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/service/dto/MemberCreateDto.java @@ -0,0 +1,10 @@ +package org.sopt.spring.service.dto; + +import org.sopt.spring.domain.Part; + +public record MemberCreateDto( + String name, + Part part, + int age +) { +} diff --git a/week03/src/main/java/org/sopt/spring/service/dto/MemberFindDto.java b/week03/src/main/java/org/sopt/spring/service/dto/MemberFindDto.java new file mode 100644 index 0000000..c50426a --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/service/dto/MemberFindDto.java @@ -0,0 +1,14 @@ +package org.sopt.spring.service.dto; + +import org.sopt.spring.domain.Member; +import org.sopt.spring.domain.Part; + +public record MemberFindDto( + String name, + Part part, + int age +) { + public static MemberFindDto of(Member member) { + return new MemberFindDto(member.getName(), member.getPart(), member.getAge()); + } +} diff --git a/week03/src/main/java/org/sopt/spring/service/dto/PostCreateRequest.java b/week03/src/main/java/org/sopt/spring/service/dto/PostCreateRequest.java new file mode 100644 index 0000000..4425dd5 --- /dev/null +++ b/week03/src/main/java/org/sopt/spring/service/dto/PostCreateRequest.java @@ -0,0 +1,8 @@ +package org.sopt.spring.service.dto; + +public record PostCreateRequest( + String title, + String content + +) {} +