-
Notifications
You must be signed in to change notification settings - Fork 4
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
[REFACTOR] 게시글 도메인 리팩터링 #549
Changes from 38 commits
8364575
9532248
0d6999e
9d1ca69
81e6844
e7d0086
faef4bd
7ff5833
e299018
72b3da2
b6991b4
65af6c4
2402ea2
3d5a1de
73bda7c
6fe7a98
0e6704b
6d19f77
d1664a4
c434481
d9268f0
e3d94b0
0b39825
295f94d
1ecd08d
6d1d394
f92607e
b8f52bb
5ce0e1e
8fb3e1b
4a38b2a
2e42394
6521e92
b94ee8e
82d3bcc
dd83cdc
776f051
46db22d
0ea2280
fc7c107
16bbcb9
69b9c4d
e58ac1f
e7e05ab
f971cbe
5c0e7eb
6f0589a
bd78629
443b151
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,27 +9,28 @@ | |
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Nickname { | ||
|
||
private static final int MINIMUM_NICKNAME_LENGTH = 2; | ||
private static final int MAXIMUM_NICKNAME_LENGTH = 15; | ||
private static final Pattern PATTERN = Pattern.compile("^[가-힣a-zA-Z0-9]+$"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요런것도 있군요 신기하네요 👍 |
||
|
||
@Column(name = "nickname", length = 20, unique = true, nullable = false) | ||
private String value; | ||
|
||
public Nickname(final String nickname) { | ||
validateNickname(nickname); | ||
this.value = nickname; | ||
public Nickname(final String value) { | ||
validateNickname(value); | ||
this.value = value; | ||
} | ||
|
||
private void validateNickname(final String nickname) { | ||
if (nickname.length() < MINIMUM_NICKNAME_LENGTH || nickname.length() > MAXIMUM_NICKNAME_LENGTH) { | ||
private void validateNickname(final String value) { | ||
if (value.length() < MINIMUM_NICKNAME_LENGTH || value.length() > MAXIMUM_NICKNAME_LENGTH) { | ||
throw new BadRequestException(MemberExceptionType.INVALID_NICKNAME_LENGTH); | ||
} | ||
if (!Pattern.matches("^[가-힣a-zA-Z0-9]+$", nickname)) { | ||
if (!PATTERN.matcher(value).matches()) { | ||
throw new BadRequestException(MemberExceptionType.INVALID_NICKNAME_LETTER); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.votogether.domain.post.controller; | ||
|
||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.domain.post.dto.request.post.PostCreateRequest; | ||
import com.votogether.domain.post.dto.request.post.PostUpdateRequest; | ||
import com.votogether.domain.post.service.PostCommandService; | ||
import com.votogether.global.jwt.Auth; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.Positive; | ||
import java.net.URI; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
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.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Validated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 처음 알게된 사실이네요..! |
||
@RequiredArgsConstructor | ||
@RequestMapping("/posts") | ||
@RestController | ||
public class PostCommandController { | ||
|
||
private final PostCommandService postCommandService; | ||
|
||
@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE}) | ||
public ResponseEntity<Void> createPost( | ||
@ModelAttribute @Valid final PostCreateRequest postCreateRequest, | ||
@Auth final Member loginMember | ||
) { | ||
final Long postId = postCommandService.createPost(postCreateRequest, loginMember); | ||
return ResponseEntity.created(URI.create("/posts/" + postId)).build(); | ||
} | ||
|
||
@PutMapping(value = "/{postId}", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_VALUE}) | ||
public ResponseEntity<Void> updatePost( | ||
@PathVariable @Positive(message = "게시글 ID는 양의 정수만 가능합니다.") final Long postId, | ||
@ModelAttribute @Valid final PostUpdateRequest postUpdateRequest, | ||
@Auth final Member loginMember | ||
) { | ||
postCommandService.updatePost(postId, postUpdateRequest, loginMember); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PatchMapping("/{postId}/close") | ||
public ResponseEntity<Void> closePostEarly( | ||
@PathVariable @Positive(message = "게시글 ID는 양의 정수만 가능합니다.") final Long postId, | ||
@Auth final Member loginMember | ||
) { | ||
postCommandService.closePostEarly(postId, loginMember); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@DeleteMapping("/{postId}") | ||
public ResponseEntity<Void> deletePost( | ||
@PathVariable @Positive(message = "게시글 ID는 양의 정수만 가능합니다.") final Long postId, | ||
@Auth final Member loginMember | ||
) { | ||
postCommandService.deletePost(postId, loginMember); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.votogether.domain.post.controller; | ||
|
||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.domain.post.dto.request.post.PostCreateRequest; | ||
import com.votogether.domain.post.dto.request.post.PostUpdateRequest; | ||
import com.votogether.global.exception.ExceptionResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.Positive; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Tag(name = "게시글 커맨드", description = "게시글 커맨드 API") | ||
public interface PostCommandControllerDocs { | ||
|
||
@Operation(summary = "게시글 작성", description = "게시글을 작성한다.") | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "201", | ||
description = "게시글 작성 성공" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "정상적이지 않은 요청", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
) | ||
}) | ||
ResponseEntity<Void> createPost( | ||
@Valid final PostCreateRequest postCreateRequest, | ||
final Member loginMember | ||
); | ||
|
||
@Operation(summary = "게시글 수정", description = "게시글을 수정한다.") | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "게시글 수정 성공" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = """ | ||
1.게시글 ID가 양의 정수가 아닌 경우 | ||
|
||
2.정상적이지 않은 요청 | ||
|
||
3.게시글이 블라인드 처리된 경우 | ||
|
||
4.게시글 작성자가 아닌 경우 | ||
""", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
), | ||
@ApiResponse( | ||
responseCode = "404", | ||
description = "존재하지 않는 게시글", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
) | ||
}) | ||
ResponseEntity<Void> updatePost( | ||
@Parameter(description = "게시글 ID", example = "1") | ||
@Positive(message = "게시글 ID는 양의 정수만 가능합니다.") final Long postId, | ||
@Valid final PostUpdateRequest postUpdateRequest, | ||
final Member loginMember | ||
); | ||
|
||
@Operation(summary = "게시글 조기 마감", description = "게시글을 조기 마감한다.") | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "게시글 조기 마감 성공" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = """ | ||
1.게시글 ID가 양의 정수가 아닌 경우 | ||
|
||
2.게시글이 블라인드 처리된 경우 | ||
|
||
3.게시글 작성자가 아닌 경우 | ||
""", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
), | ||
@ApiResponse( | ||
responseCode = "404", | ||
description = "존재하지 않는 게시글", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
) | ||
}) | ||
ResponseEntity<Void> closePostEarly( | ||
@Parameter(description = "게시글 ID", example = "1") | ||
@Positive(message = "게시글 ID는 양의 정수만 가능합니다.") final Long postId, | ||
final Member loginMember | ||
); | ||
|
||
@Operation(summary = "게시글 삭제", description = "게시글을 삭제한다.") | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "204", | ||
description = "게시글 삭제 성공" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = """ | ||
1.게시글 ID가 양의 정수가 아닌 경우 | ||
|
||
2.게시글이 블라인드 처리된 경우 | ||
|
||
3.게시글 작성자가 아닌 경우 | ||
|
||
4.삭제할 수 없는 투표 수가 존재하는 게시글인 경우 | ||
""", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
), | ||
@ApiResponse( | ||
responseCode = "404", | ||
description = "존재하지 않는 게시글", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
) | ||
}) | ||
ResponseEntity<Void> deletePost( | ||
@Parameter(description = "게시글 ID", example = "1") | ||
@Positive(message = "게시글 ID는 양의 정수만 가능합니다.") final Long postId, | ||
final Member loginMember | ||
); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q
@Column
이 사라졌는데 없어도 되나요??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Entity
필드는 자동으로 테이블과 매핑이 되기에 이름이나 별다른 속성이 없으면 제거해도 괜찮을 것 같아서 삭제했습니다 ㅎㅎ