-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚀 :: Api-v0.0.7
- Loading branch information
Showing
104 changed files
with
2,030 additions
and
358 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
DuDoong-Api/src/main/java/band/gosrock/api/comment/controller/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,47 @@ | ||
package band.gosrock.api.comment.controller; | ||
|
||
|
||
import band.gosrock.api.comment.model.request.CreateCommentRequest; | ||
import band.gosrock.api.comment.model.response.CreateCommentResponse; | ||
import band.gosrock.api.comment.model.response.RetrieveCommentListResponse; | ||
import band.gosrock.api.comment.service.CreateCommentUseCase; | ||
import band.gosrock.api.comment.service.RetrieveCommentUseCase; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
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.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@SecurityRequirement(name = "access-token") | ||
@Tag(name = "응원톡 컨트롤러") | ||
@RestController | ||
@RequestMapping("/v1/event/{eventId}/comments") | ||
@RequiredArgsConstructor | ||
public class CommentController { | ||
|
||
private final CreateCommentUseCase createCommentUseCase; | ||
|
||
private final RetrieveCommentUseCase retrieveCommentUseCase; | ||
|
||
@Operation(summary = "응원글을 생성합니다.") | ||
@PostMapping | ||
public CreateCommentResponse postComment( | ||
@RequestBody @Valid CreateCommentRequest createCommentRequest, | ||
@PathVariable Long eventId) { | ||
return createCommentUseCase.execute(eventId, createCommentRequest); | ||
} | ||
|
||
@Operation(summary = "응원글을 조회합니다.") | ||
@GetMapping | ||
public RetrieveCommentListResponse getComments( | ||
@PathVariable Long eventId, @RequestParam(required = false) Long lastId) { | ||
return retrieveCommentUseCase.execute(eventId, lastId); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
DuDoong-Api/src/main/java/band/gosrock/api/comment/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,38 @@ | ||
package band.gosrock.api.comment.mapper; | ||
|
||
|
||
import band.gosrock.api.comment.model.request.CreateCommentRequest; | ||
import band.gosrock.api.comment.model.response.CreateCommentResponse; | ||
import band.gosrock.api.comment.model.response.RetrieveCommentListResponse; | ||
import band.gosrock.common.annotation.Mapper; | ||
import band.gosrock.domain.domains.comment.adaptor.CommentAdaptor; | ||
import band.gosrock.domain.domains.comment.domain.Comment; | ||
import band.gosrock.domain.domains.comment.dto.condition.CommentCondition; | ||
import band.gosrock.domain.domains.event.domain.Event; | ||
import band.gosrock.domain.domains.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Mapper | ||
@RequiredArgsConstructor | ||
public class CommentMapper { | ||
|
||
private final CommentAdaptor commentAdaptor; | ||
|
||
public Comment toEntity(User user, Event event, CreateCommentRequest createDTO) { | ||
return Comment.create(createDTO.getContent(), createDTO.getNickName(), user, event.getId()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public CreateCommentResponse toCreateCommentResponse(Comment comment, User user) { | ||
return CreateCommentResponse.of(comment, user); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public RetrieveCommentListResponse toRetrieveCommentListResponse( | ||
CommentCondition commentCondition, Long currentUserId) { | ||
Slice<Comment> comments = commentAdaptor.searchComment(commentCondition); | ||
return RetrieveCommentListResponse.of(comments, currentUserId); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
DuDoong-Api/src/main/java/band/gosrock/api/comment/model/request/CreateCommentRequest.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,18 @@ | ||
package band.gosrock.api.comment.model.request; | ||
|
||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.Size; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CreateCommentRequest { | ||
|
||
@NotBlank(message = "작성자 닉네임을 입력해주세요.") | ||
@Size(min = 1, max = 15) | ||
private String nickName; | ||
|
||
@NotBlank(message = "댓글 내용을 입력해주세요.") | ||
@Size(min = 1, max = 200) | ||
private String content; | ||
} |
35 changes: 35 additions & 0 deletions
35
DuDoong-Api/src/main/java/band/gosrock/api/comment/model/response/CreateCommentResponse.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,35 @@ | ||
package band.gosrock.api.comment.model.response; | ||
|
||
|
||
import band.gosrock.common.annotation.DateFormat; | ||
import band.gosrock.domain.common.vo.UserInfoVo; | ||
import band.gosrock.domain.domains.comment.domain.Comment; | ||
import band.gosrock.domain.domains.user.domain.User; | ||
import java.time.LocalDateTime; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class CreateCommentResponse { | ||
|
||
private final Long id; | ||
|
||
private final String nickName; | ||
|
||
private final String content; | ||
|
||
@DateFormat private final LocalDateTime createdAt; | ||
|
||
private final UserInfoVo userInfoVo; | ||
|
||
public static CreateCommentResponse of(Comment comment, User user) { | ||
return CreateCommentResponse.builder() | ||
.id(comment.getId()) | ||
.nickName(comment.getNickName()) | ||
.content(comment.getContent()) | ||
.createdAt(comment.getCreatedAt()) | ||
.userInfoVo(user.toUserInfoVo()) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
DuDoong-Api/src/main/java/band/gosrock/api/comment/model/response/RetrieveCommentDTO.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,24 @@ | ||
package band.gosrock.api.comment.model.response; | ||
|
||
|
||
import band.gosrock.domain.common.vo.CommentInfoVo; | ||
import band.gosrock.domain.domains.comment.domain.Comment; | ||
import java.util.Objects; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class RetrieveCommentDTO { | ||
|
||
private final CommentInfoVo commentInfo; | ||
|
||
private final Boolean isMine; | ||
|
||
public static RetrieveCommentDTO of(Comment comment, Long currentUserId) { | ||
return RetrieveCommentDTO.builder() | ||
.commentInfo(comment.toCommentInfoVo()) | ||
.isMine(Objects.equals(comment.getUser().getId(), currentUserId)) | ||
.build(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...pi/src/main/java/band/gosrock/api/comment/model/response/RetrieveCommentListResponse.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,27 @@ | ||
package band.gosrock.api.comment.model.response; | ||
|
||
|
||
import band.gosrock.domain.domains.comment.domain.Comment; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.data.domain.Slice; | ||
|
||
@Getter | ||
@Builder | ||
public class RetrieveCommentListResponse { | ||
|
||
private final Boolean hasNext; | ||
|
||
private final List<RetrieveCommentDTO> comments; | ||
|
||
public static RetrieveCommentListResponse of(Slice<Comment> comments, Long currentUserId) { | ||
return RetrieveCommentListResponse.builder() | ||
.hasNext(comments.hasNext()) | ||
.comments( | ||
comments.stream() | ||
.map(comment -> RetrieveCommentDTO.of(comment, currentUserId)) | ||
.toList()) | ||
.build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
DuDoong-Api/src/main/java/band/gosrock/api/comment/service/CreateCommentUseCase.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,37 @@ | ||
package band.gosrock.api.comment.service; | ||
|
||
|
||
import band.gosrock.api.comment.mapper.CommentMapper; | ||
import band.gosrock.api.comment.model.request.CreateCommentRequest; | ||
import band.gosrock.api.comment.model.response.CreateCommentResponse; | ||
import band.gosrock.api.common.UserUtils; | ||
import band.gosrock.common.annotation.UseCase; | ||
import band.gosrock.domain.domains.comment.adaptor.CommentAdaptor; | ||
import band.gosrock.domain.domains.comment.domain.Comment; | ||
import band.gosrock.domain.domains.event.adaptor.EventAdaptor; | ||
import band.gosrock.domain.domains.event.domain.Event; | ||
import band.gosrock.domain.domains.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class CreateCommentUseCase { | ||
|
||
private final UserUtils userUtils; | ||
|
||
private final CommentMapper commentMapper; | ||
|
||
private final CommentAdaptor commentAdaptor; | ||
|
||
private final EventAdaptor eventAdaptor; | ||
|
||
@Transactional | ||
public CreateCommentResponse execute(Long eventId, CreateCommentRequest createDTO) { | ||
User currentUser = userUtils.getCurrentUser(); | ||
Event event = eventAdaptor.findById(eventId); | ||
Comment comment = | ||
commentAdaptor.save(commentMapper.toEntity(currentUser, event, createDTO)); | ||
return commentMapper.toCreateCommentResponse(comment, currentUser); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
DuDoong-Api/src/main/java/band/gosrock/api/comment/service/RetrieveCommentUseCase.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,29 @@ | ||
package band.gosrock.api.comment.service; | ||
|
||
|
||
import band.gosrock.api.comment.mapper.CommentMapper; | ||
import band.gosrock.api.comment.model.response.RetrieveCommentListResponse; | ||
import band.gosrock.api.common.UserUtils; | ||
import band.gosrock.common.annotation.UseCase; | ||
import band.gosrock.domain.domains.comment.dto.condition.CommentCondition; | ||
import band.gosrock.domain.domains.event.adaptor.EventAdaptor; | ||
import band.gosrock.domain.domains.event.domain.Event; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@UseCase | ||
@RequiredArgsConstructor | ||
public class RetrieveCommentUseCase { | ||
|
||
private final CommentMapper commentMapper; | ||
|
||
private final EventAdaptor eventAdaptor; | ||
|
||
private final UserUtils userUtils; | ||
|
||
public RetrieveCommentListResponse execute(Long eventId, Long lastId) { | ||
Event event = eventAdaptor.findById(eventId); | ||
Long currentUserId = userUtils.getCurrentUserId(); | ||
CommentCondition commentCondition = new CommentCondition(event.getId(), lastId); | ||
return commentMapper.toRetrieveCommentListResponse(commentCondition, currentUserId); | ||
} | ||
} |
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
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
Oops, something went wrong.