Skip to content
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

feat: 응원톡 생성 및 리스트 가져오기 API 작성 #199

Merged
merged 9 commits into from
Jan 26, 2023
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);
}
}
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) {
Slice<Comment> comments = commentAdaptor.searchComment(commentCondition);
return RetrieveCommentListResponse.of(comments);
}
}
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.NotNull;
import javax.validation.constraints.Size;
import lombok.Getter;

@Getter
public class CreateCommentRequest {

@NotNull(message = "작성자 닉네임을 입력해주세요.")
@Size(min = 1, max = 15)
private String nickName;
sanbonai06 marked this conversation as resolved.
Show resolved Hide resolved

@NotNull(message = "댓글 내용을 입력해주세요.")
@Size(min = 1, max = 200)
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package band.gosrock.api.comment.model.response;


import band.gosrock.domain.common.vo.UserInfoVo;
import band.gosrock.domain.domains.comment.domain.Comment;
import band.gosrock.domain.domains.user.domain.User;
import com.fasterxml.jackson.annotation.JsonFormat;
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;

@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul")
private final LocalDateTime createdAt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DateFormat ....!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그 궁금한게 있었는데 저렇게 jsonFormat으로 엮는거랑 정확한 차이가 궁금했습니당 @gengminy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그 궁금한게 있었는데 저렇게 jsonFormat으로 엮는거랑 정확한 차이가 궁금했습니당 @gengminy

4줄짜리 1줄로 줄여서 깔끔하게 만들어줘요 기능은 똑같애요


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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package band.gosrock.api.comment.model.response;


import band.gosrock.domain.common.vo.CommentInfoVo;
import band.gosrock.domain.common.vo.UserInfoVo;
import band.gosrock.domain.domains.comment.domain.Comment;
import band.gosrock.domain.domains.user.domain.User;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class RetrieveCommentDTO {

private final CommentInfoVo commentInfo;

private final UserInfoVo userInfo;

public static RetrieveCommentDTO of(Comment comment, User user) {
return RetrieveCommentDTO.builder()
.commentInfo(comment.toCommentInfoVo())
.userInfo(user.toUserInfoVo())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

티켓 예매관리나 관리자쪽에서는 ( 호스트에게 노출되는 환경 )
전화번호 까지 주는게 괜찮은것 같긴한데,
응원톡( 여러 사용자들에게 노출되는 환경에 )
전화번호 까지 주는건 무리가 있지않나 싶긴하네유..
따로 publicUserInfo 처럼 만들어야할듯 해요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

응원톡 리스트를 가져가는데 굳이 user의 모든 정보를 줘야할까? 고민해서 처음에는 userId만 넘기는 식으로 생각해봤었어요. 이런 방식으로 가면 좀 이상할까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러게요 그냥 닉네임 정보받은거 내려주는게 맞지 않나 싶음

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

본인 글은 오른쪽에 떠야하는걸로 봐서 유저 정보는 내려주는게 맞지 않을까용

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanbonai06
isMine 같은 dto 필드 만들어서 true false만 내려주심될듯요!

.build();
}
}
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) {
return RetrieveCommentListResponse.builder()
.hasNext(comments.hasNext())
.comments(
comments.stream()
.map(comment -> RetrieveCommentDTO.of(comment, comment.getUser()))
.toList())
.build();
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package band.gosrock.api.comment.service;


import band.gosrock.api.comment.mapper.CommentMapper;
import band.gosrock.api.comment.model.response.RetrieveCommentListResponse;
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;

public RetrieveCommentListResponse execute(Long eventId, Long lastId) {
Event event = eventAdaptor.findById(eventId);
CommentCondition commentCondition = new CommentCondition(event.getId(), lastId);
return commentMapper.toRetrieveCommentListResponse(commentCondition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import band.gosrock.api.issuedTicket.dto.response.RetrieveIssuedTicketListResponse;
import band.gosrock.common.annotation.Mapper;
import band.gosrock.domain.domains.issuedTicket.adaptor.IssuedTicketAdaptor;
import band.gosrock.domain.domains.issuedTicket.dto.condtion.IssuedTicketCondition;
import band.gosrock.domain.domains.issuedTicket.dto.condition.IssuedTicketCondition;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import band.gosrock.api.issuedTicket.mapper.IssuedTicketMapper;
import band.gosrock.common.annotation.UseCase;
import band.gosrock.domain.domains.event.service.EventService;
import band.gosrock.domain.domains.issuedTicket.dto.condtion.IssuedTicketCondition;
import band.gosrock.domain.domains.issuedTicket.dto.condition.IssuedTicketCondition;
import band.gosrock.domain.domains.issuedTicket.service.IssuedTicketDomainService;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CreateOrderResponse execute(CreateOrderRequest createOrderRequest) {
Long cartId = createOrderRequest.getCartId();
if (couponId == null) {
return CreateOrderResponse.from(
createOrderService.WithOutCoupon(cartId, user.getId()), user.getProfile());
createOrderService.withOutCoupon(cartId, user.getId()), user.getProfile());
}
return CreateOrderResponse.from(
createOrderService.withCoupon(cartId, user.getId(), couponId), user.getProfile());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package band.gosrock.domain.common.vo;


import band.gosrock.domain.domains.comment.domain.Comment;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class CommentInfoVo {

private final Long commentId;

private final String nickName;

private final String content;

@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul")
private final LocalDateTime createdAt;

public static CommentInfoVo from(Comment comment) {
return CommentInfoVo.builder()
.commentId(comment.getId())
.nickName(comment.getNickName())
.content(comment.getContent())
.createdAt(comment.getCreatedAt())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class IssuedTicketInfoVo {
*/
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd hh:mm:ss",
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul")
private final LocalDateTime createdAt;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package band.gosrock.domain.domains.comment.adaptor;


import band.gosrock.common.annotation.Adaptor;
import band.gosrock.domain.domains.comment.domain.Comment;
import band.gosrock.domain.domains.comment.dto.condition.CommentCondition;
import band.gosrock.domain.domains.comment.repository.CommentRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;

@Adaptor
@RequiredArgsConstructor
public class CommentAdaptor {

private final CommentRepository commentRepository;

public Comment save(Comment comment) {
return commentRepository.save(comment);
}

public Slice<Comment> searchComment(CommentCondition commentCondition) {
PageRequest pageRequest = PageRequest.of(0, 20, Sort.by("createdAt").ascending());
return commentRepository.searchToPage(commentCondition, pageRequest);
}
}
Loading