Skip to content

Commit

Permalink
#273 [feat] 초대링크 및 첫 글감 생성 로직
Browse files Browse the repository at this point in the history
  • Loading branch information
parkheeddong committed Mar 27, 2024
1 parent dc5d4be commit 3064abf
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public enum SuccessMessage {
POST_CREATE_SUCCESS(HttpStatus.OK.value(), "글 생성이 완료되었습니다."),
TEMPORARY_POST_CREATE_SUCCESS(HttpStatus.OK.value(), "임시저장 글 생성이 완료되었습니다."),
MOIM_CREATE_SUCCESS(HttpStatus.OK.value(), "글모임 생성이 완료되었습니다."),
TOPIC_CREATE_SUCCESS(HttpStatus.CREATED.value(), "글감 생성이 완료되었습니다."),
;

final int status;
Expand Down
2 changes: 2 additions & 0 deletions module-domain/src/main/java/com/mile/moim/domain/Moim.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class Moim extends BaseTimeEntity {
@Setter
private String idUrl;
private boolean isPublic;
@Setter
private String invitationCode;

public void modifyMoimInfo(
final MoimInfoModifyRequest moimInfoModifyRequest
Expand Down
42 changes: 39 additions & 3 deletions module-domain/src/main/java/com/mile/moim/service/MoimService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.mile.moim.service.dto.MoimTopicResponse;
import com.mile.moim.service.dto.PopularWriterListResponse;
import com.mile.moim.service.dto.TemporaryPostExistResponse;
import com.mile.moim.service.dto.TopicCreateRequest;
import com.mile.moim.service.dto.TopicListResponse;
import com.mile.moim.service.dto.WriterMemberJoinRequest;
import com.mile.moim.service.dto.WriterNameConflictCheckResponse;
Expand All @@ -33,6 +34,7 @@
import com.mile.utils.SecureUrlUtil;
import com.mile.writername.domain.WriterName;
import com.mile.writername.service.WriterNameService;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -192,20 +194,54 @@ public MoimNameConflictCheckResponse validateMoimName(
return MoimNameConflictCheckResponse.of(!moimRepository.existsByName(moimName));
}

public String createTopic(
final Long moimId,
final Long userId,
final TopicCreateRequest createRequest
) {
Moim moim = findById(moimId);
authenticateOwnerOfMoim(moim, userId);
return topicService.createTopicOfMoim(moim, createRequest).toString();
}

@Transactional
public MoimCreateResponse createMoim(
final Long userId,
final MoimCreateRequest createRequest
) {
Moim moim = moimRepository.saveAndFlush(Moim.create(createRequest));
User user = userService.findById(userId);

setMoimOwner(moim, user, createRequest);
String link = generateInviteLink(moim);
setFirstTopic(moim, userId, createRequest);

return MoimCreateResponse.of(moim.getIdUrl(), link);
}

private void setMoimOwner(
final Moim moim,
final User user,
final MoimCreateRequest createRequest
) {
WriterMemberJoinRequest joinRequest = WriterMemberJoinRequest.of(createRequest.writerName(), createRequest.writerNameDescription());
WriterName owner = writerNameService.getById(writerNameService.createWriterName(user, moim, joinRequest));
moim.setOwner(owner);
moim.setIdUrl(secureUrlUtil.encodeUrl(moim.getId()));
String link = "초대링크"; // 초대링크 로직 넣기
// Topic 생성 로직 넣기
return MoimCreateResponse.of(moim.getIdUrl(), link);
}

private String generateInviteLink(Moim moim) {
String inviteLink = UUID.randomUUID().toString() + moim.getIdUrl();
moim.setInvitationCode(inviteLink);
return inviteLink;
}

private void setFirstTopic(
final Moim moim,
final Long userId,
final MoimCreateRequest createRequest
) {
TopicCreateRequest topicRequest = TopicCreateRequest.of(createRequest.topic(), createRequest.topicTag(), createRequest.topicDescription());
createTopic(moim.getId(), userId, topicRequest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mile.moim.service.dto;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.NotBlank;
public record TopicCreateRequest(
@Max(value = 15, message = "글감은 최대 15자 이내로 작성해주세요.")
@NotBlank(message = "글감 제목이 비어있습니다.")
String topicName,
@Max(value = 5, message = "글감 태그는 최대 5자 이내로 작성해주세요.")
@NotBlank(message = "글감 태그가 비어있습니다.")
String topicTag,
@Max(value = 5, message = "글감 설명은 최대 90자 이내로 작성해주세요.")
@NotBlank(message = "글감 설명은 비어있습니다.")
String topicDescription
) {
public static TopicCreateRequest of(
final String topicName,
final String topicTag,
final String topicDescription
) {
return new TopicCreateRequest(topicName, topicTag, topicDescription);
}
}
31 changes: 30 additions & 1 deletion module-domain/src/main/java/com/mile/topic/domain/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import com.mile.config.BaseTimeEntity;
import com.mile.moim.domain.Moim;
import com.mile.moim.service.dto.TopicCreateRequest;
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.Builder;
import lombok.Getter;
import lombok.Setter;



@Entity
@Getter
Expand All @@ -18,8 +23,32 @@ public class Topic extends BaseTimeEntity {
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Moim moim;
@Setter
private String idUrl;
private String keyword;
private String content;
private String description;
}

@Builder
private Topic(final Moim moim,
final String content,
final String keyword,
final String description) {
this.moim = moim;
this.content = content;
this.keyword = keyword;
this.description = description;
}

public static Topic create(
final Moim moim,
final TopicCreateRequest topicCreateRequest
) {
return Topic.builder()
.moim(moim)
.content(topicCreateRequest.topicName())
.keyword(topicCreateRequest.topicTag())
.description(topicCreateRequest.topicDescription())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mile.exception.model.ForbiddenException;
import com.mile.exception.model.NotFoundException;
import com.mile.moim.domain.Moim;
import com.mile.moim.service.dto.TopicCreateRequest;
import com.mile.post.service.PostGetService;
import com.mile.post.service.dto.PostListResponse;
import com.mile.topic.domain.Topic;
Expand All @@ -18,13 +19,15 @@
import com.mile.topic.service.dto.TopicResponse;
import com.mile.user.domain.User;
import com.mile.user.service.UserService;
import com.mile.utils.SecureUrlUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
Expand All @@ -34,6 +37,7 @@ public class TopicService {
private final CommentService commentService;
private final UserService userService;
private final PostGetService postGetService;
private final SecureUrlUtil secureUrlUtil;

public List<ContentResponse> getContentsFromMoim(
final Long moimId
Expand Down Expand Up @@ -144,4 +148,15 @@ public TopicDetailResponse getTopicDetail(
authenticateTopicWithUser(topic, userService.findById(userId));
return TopicDetailResponse.of(topic);
}


@Transactional
public Long createTopicOfMoim(
final Moim moim,
final TopicCreateRequest createRequest
) {
Topic topic = topicRepository.saveAndFlush(Topic.create(moim, createRequest));
topic.setIdUrl(secureUrlUtil.encodeUrl(topic.getId()));
return topic.getId();
}
}

0 comments on commit 3064abf

Please sign in to comment.