-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] #12 지원서 코멘트 작성
- Loading branch information
Showing
13 changed files
with
241 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/java/land/leets/domain/admin/presentation/dto/AdminDetailsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package land.leets.domain.admin.presentation.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class AdminDetailsResponse { | ||
@NotBlank | ||
private String name; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/land/leets/domain/comment/domain/Comment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package land.leets.domain.comment.domain; | ||
|
||
import jakarta.persistence.*; | ||
import land.leets.domain.admin.domain.Admin; | ||
import land.leets.domain.shared.BaseTimeEntity; | ||
import lombok.*; | ||
|
||
@Entity(name = "comments") | ||
@Builder | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class Comment extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Long applicationId; | ||
|
||
@Column(nullable = false) | ||
private String content; | ||
|
||
@OneToOne | ||
private Admin admin; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/land/leets/domain/comment/domain/repository/CommentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package land.leets.domain.comment.domain.repository; | ||
|
||
import land.leets.domain.comment.domain.Comment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface CommentRepository extends JpaRepository<Comment, Long> { | ||
List<Comment> findAllByApplicationId(Long applicationId); | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/land/leets/domain/comment/presentation/CommentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package land.leets.domain.comment.presentation; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
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 land.leets.domain.auth.AuthDetails; | ||
import land.leets.domain.comment.presentation.dto.CommentRequest; | ||
import land.leets.domain.comment.presentation.dto.CommentResponse; | ||
import land.leets.domain.comment.usecase.CreateComment; | ||
import land.leets.domain.comment.usecase.GetComments; | ||
import land.leets.global.error.ErrorResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/comments") | ||
public class CommentController { | ||
|
||
private final CreateComment createComment; | ||
private final GetComments getComments; | ||
|
||
@Operation(summary = "(관리자) 댓글 작성", description = "지원서에 댓글을 작성합니다.") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200"), | ||
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
}) | ||
@PostMapping | ||
public CommentResponse create(@AuthenticationPrincipal AuthDetails authDetails, | ||
@RequestBody CommentRequest request) { | ||
return createComment.execute(authDetails, request); | ||
} | ||
|
||
@Operation(summary = "(관리자) 댓글 조회", description = "지원서 댓글을 조회합니다.") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200"), | ||
@ApiResponse(responseCode = "400", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "403", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "404", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
}) | ||
@GetMapping("/{applicationId}") | ||
public List<CommentResponse> get(@PathVariable Long applicationId) { | ||
return getComments.execute(applicationId); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/land/leets/domain/comment/presentation/dto/CommentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package land.leets.domain.comment.presentation.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class CommentRequest { | ||
@NotBlank | ||
private Long applicationId; | ||
|
||
@NotBlank | ||
private String content; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/land/leets/domain/comment/presentation/dto/CommentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package land.leets.domain.comment.presentation.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import land.leets.domain.admin.presentation.dto.AdminDetailsResponse; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CommentResponse { | ||
@NotBlank | ||
private String content; | ||
|
||
@NotBlank | ||
private LocalDateTime createdAt; | ||
|
||
@NotBlank | ||
private LocalDateTime updatedAt; | ||
|
||
@NotNull | ||
private AdminDetailsResponse admin; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/land/leets/domain/comment/presentation/mapper/CommentMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package land.leets.domain.comment.presentation.mapper; | ||
|
||
import land.leets.domain.comment.domain.Comment; | ||
import land.leets.domain.comment.presentation.dto.CommentResponse; | ||
import org.mapstruct.BeanMapping; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.NullValuePropertyMappingStrategy; | ||
import org.mapstruct.ReportingPolicy; | ||
|
||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) | ||
public interface CommentMapper { | ||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) | ||
CommentResponse mappingCommentToDto(Comment comment); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/land/leets/domain/comment/usecase/CreateComment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package land.leets.domain.comment.usecase; | ||
|
||
import land.leets.domain.auth.AuthDetails; | ||
import land.leets.domain.comment.presentation.dto.CommentRequest; | ||
import land.leets.domain.comment.presentation.dto.CommentResponse; | ||
|
||
public interface CreateComment { | ||
CommentResponse execute(AuthDetails authDetails, CommentRequest request); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/land/leets/domain/comment/usecase/CreateCommentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package land.leets.domain.comment.usecase; | ||
|
||
import land.leets.domain.admin.domain.Admin; | ||
import land.leets.domain.admin.domain.repository.AdminRepository; | ||
import land.leets.domain.admin.exception.AdminNotFoundException; | ||
import land.leets.domain.auth.AuthDetails; | ||
import land.leets.domain.comment.domain.Comment; | ||
import land.leets.domain.comment.domain.repository.CommentRepository; | ||
import land.leets.domain.comment.presentation.dto.CommentRequest; | ||
import land.leets.domain.comment.presentation.dto.CommentResponse; | ||
import land.leets.domain.comment.presentation.mapper.CommentMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CreateCommentImpl implements CreateComment { | ||
private final CommentRepository commentRepository; | ||
private final AdminRepository adminRepository; | ||
private final CommentMapper commentMapper; | ||
|
||
@Override | ||
public CommentResponse execute(AuthDetails authDetails, CommentRequest request) { | ||
Admin admin = adminRepository.findById(authDetails.getUid()).orElseThrow(AdminNotFoundException::new); | ||
Comment comment = Comment.builder() | ||
.applicationId(request.getApplicationId()) | ||
.content(request.getContent()) | ||
.admin(admin) | ||
.build(); | ||
Comment save = commentRepository.save(comment); | ||
return commentMapper.mappingCommentToDto(save); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/land/leets/domain/comment/usecase/GetComments.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package land.leets.domain.comment.usecase; | ||
|
||
import land.leets.domain.comment.presentation.dto.CommentResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface GetComments { | ||
List<CommentResponse> execute(Long applicationId); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/land/leets/domain/comment/usecase/GetCommentsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package land.leets.domain.comment.usecase; | ||
|
||
import land.leets.domain.comment.domain.Comment; | ||
import land.leets.domain.comment.domain.repository.CommentRepository; | ||
import land.leets.domain.comment.presentation.dto.CommentResponse; | ||
import land.leets.domain.comment.presentation.mapper.CommentMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GetCommentsImpl implements GetComments { | ||
private final CommentRepository commentRepository; | ||
private final CommentMapper commentMapper; | ||
|
||
@Override | ||
public List<CommentResponse> execute(Long applicationId) { | ||
List<Comment> comments = commentRepository.findAllByApplicationId(applicationId); | ||
return comments.stream() | ||
.map(commentMapper::mappingCommentToDto) | ||
.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters