Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

#3 그룹 팔로워 신청 기능 개발 #6

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.maru.seeTogether.api.v1.group.accout.groupFollower;

import me.maru.seeTogether.service.group.accout.groupFollower.create.GroupFollowerCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/v1")
public class GroupFollowerCreateController {

private final Logger logger = LoggerFactory.getLogger(GroupFollowerCreateController.class);

@Autowired
private final GroupFollowerCreator groupFollowerCreator;

public GroupFollowerCreateController(final GroupFollowerCreator groupFollowerCreator) {
this.groupFollowerCreator = groupFollowerCreator;
}

@PostMapping(value = "/groupFollower")
public ResponseEntity<GroupFollowerCreateResponse> create(final GroupFollowerCreateRequest groupFollowerCreateRequest){
logger.info("api/v1/groupFollower request : {}", groupFollowerCreateRequest.toString());
final var groupFollowerCreateResponse = groupFollowerCreator.create(groupFollowerCreateRequest);
logger.info("api/v1/groupFollower response : {}", groupFollowerCreateResponse.toString());
return ResponseEntity.status(201).body(groupFollowerCreateResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package me.maru.seeTogether.api.v1.group.accout.groupFollower;

import lombok.Getter;
import javax.validation.constraints.NotNull;

@Getter
public class GroupFollowerCreateRequest {
@NotNull
private Long userId;
@NotNull
private Long ottProductId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.maru.seeTogether.api.v1.group.accout.groupFollower;

import lombok.Builder;

import java.time.LocalDateTime;

public class GroupFollowerCreateResponse {
private final String productName;
private final String ottId;
private final String ottPassword;
private final Integer currentParticipantsSize;
private final LocalDateTime createdAt;

@Builder
public GroupFollowerCreateResponse(final String productName, final String ottId, final String ottPassword, final Integer currentParticipantsSize, final LocalDateTime createdAt) {
this.productName = productName;
this.ottId = ottId;
this.ottPassword = ottPassword;
this.currentParticipantsSize = currentParticipantsSize;
this.createdAt = createdAt;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.maru.seeTogether.api.v1.payment.create;

import me.maru.seeTogether.service.payment.create.CardInfoCreator;
import me.maru.seeTogether.service.payment.card.create.CardInfoCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.maru.seeTogether.api.v1.payment.query;

import me.maru.seeTogether.service.payment.query.CardInfoReader;
import me.maru.seeTogether.service.payment.card.query.CardInfoReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.maru.seeTogether.api.v1.payment.create.CardInfoCreateRequest;
import me.maru.seeTogether.api.v1.payment.create.CardInfoCreateResponse;
import me.maru.seeTogether.service.payment.update.CardInfoUpdater;
import me.maru.seeTogether.service.payment.card.update.CardInfoUpdater;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/me/maru/seeTogether/domain/group/ProductGroup.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.maru.seeTogether.domain.group;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import me.maru.seeTogether.domain.product.OttProduct;

import javax.persistence.*;
Expand All @@ -17,15 +19,31 @@ public class ProductGroup {
@JoinColumn(name = "ott_product_id", referencedColumnName = "ott_product_id")
private OttProduct ottProduct;

@Getter
@Setter
@Column(name = "current_participants_size")
private Integer currentParticipantsSize;
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 숫자는 어떤 의미의 숫자인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

current_participants_size 현재 그룹의 몇 명의 인원이 들어가 있는지 나타내는 숫자입니다. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

뭔가 참여자 수를 세어 넣을 수 있다면 좋을 것 같은데 지금 구조로는 어렵군요
참여자와 참여자 수를 각각 다루고 있어서 데이터가 꼬이지 않도록 신경을 써야겠어요 ㅎㅎ


@Column(name = "delete_yn")
private Boolean delete;

public ProductGroup() {}

@Builder
public ProductGroup(Long productGroupId, OttProduct ottProduct, Integer currentParticipantsSize) {
public ProductGroup(Long productGroupId, OttProduct ottProduct, Integer currentParticipantsSize, Boolean delete) {
this.productGroupId = productGroupId;
this.ottProduct = ottProduct;
this.currentParticipantsSize = currentParticipantsSize;
this.delete = delete;
}

@Override
public String toString() {
return "ProductGroup{" +
"productGroupId=" + productGroupId +
", ottProduct=" + ottProduct +
", currentParticipantsSize=" + currentParticipantsSize +
", delete=" + delete +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.maru.seeTogether.domain.group.account;

import lombok.Builder;
import lombok.Getter;
import me.maru.seeTogether.domain.group.ProductGroup;

import javax.persistence.*;
Expand All @@ -17,19 +18,25 @@ public class GroupAccount {
@JoinColumn(name = "product_group_id", referencedColumnName = "product_group_id")
private ProductGroup productGroup;

@Getter
@Column(name = "ott_id")
private String ottId;

@Getter
@Column(name = "ott_password")
private String ottPassword;

@Column(name = "delete_yn")
private Boolean delete;

public GroupAccount() {}

@Builder
public GroupAccount(Long groupAccountId, ProductGroup productGroup, String ottId, String ottPassword) {
public GroupAccount(Long groupAccountId, ProductGroup productGroup, String ottId, String ottPassword, Boolean delete) {
this.groupAccountId = groupAccountId;
this.productGroup = productGroup;
this.ottId = ottId;
this.ottPassword = ottPassword;
this.delete = delete;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public class GroupFollower {
private LocalDateTime deletedAt;

@Column(name = "delete_yn")
private Boolean deleteYn;
private Boolean delete;

public GroupFollower() {}

@Builder
public GroupFollower(Long groupFollowerId, User user, ProductGroup productGroup, LocalDateTime createdAt, LocalDateTime deletedAt, Boolean deleteYn) {
public GroupFollower(Long groupFollowerId, User user, ProductGroup productGroup, LocalDateTime createdAt, LocalDateTime deletedAt, Boolean delete) {
this.groupFollowerId = groupFollowerId;
this.user = user;
this.productGroup = productGroup;
this.createdAt = createdAt;
this.deletedAt = deletedAt;
this.deleteYn = deleteYn;
this.delete = delete;
}
}
20 changes: 19 additions & 1 deletion src/main/java/me/maru/seeTogether/domain/product/OttProduct.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package me.maru.seeTogether.domain.product;

import lombok.Builder;
import lombok.Getter;

import javax.persistence.*;
import java.time.LocalDateTime;

Expand All @@ -11,9 +14,11 @@ public class OttProduct {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long ottProductId;

@Getter
@Column(name = "product_name")
private String productName;

@Getter
@Column(name = "total_participants_size")
private Integer totalParticipantsSize;

Expand All @@ -24,5 +29,18 @@ public class OttProduct {
private LocalDateTime deletedAt;

@Column(name = "delete_yn")
private Boolean deleteYn;
private Boolean delete;

@Builder
public OttProduct(Long ottProductId, String productName, Integer totalParticipantsSize, LocalDateTime createdAt, LocalDateTime deletedAt, Boolean delete) {
this.ottProductId = ottProductId;
this.productName = productName;
this.totalParticipantsSize = totalParticipantsSize;
this.createdAt = createdAt;
this.deletedAt = deletedAt;
this.delete = delete;
}

public OttProduct() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.maru.seeTogether.repository.group;

import me.maru.seeTogether.domain.group.ProductGroup;
import me.maru.seeTogether.domain.group.account.GroupAccount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface GroupAccountRepository extends JpaRepository<GroupAccount, Long> {
Optional<GroupAccount> findGroupAccountByProductGroupAndDelete(ProductGroup productGroup, Boolean delete);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.maru.seeTogether.repository.group;

import me.maru.seeTogether.domain.group.ProductGroup;
import me.maru.seeTogether.domain.product.OttProduct;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ProductGroupRepository extends JpaRepository<ProductGroup, Long> {
Optional<ProductGroup> findTopByOttProductAndCurrentParticipantsSizeBeforeAndDelete(OttProduct ottProduct, Integer currentParticipantsSize, Boolean delete);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import java.util.Optional;

public interface CardInfoRepository extends JpaRepository<CardInfo, Long> {
Optional<CardInfo> findCardInfoByUserAndDeleteYn(User user, boolean deleteYn);
Optional<CardInfo> findCardInfoByUserAndDeleteYn(User user, boolean delete);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.maru.seeTogether.repository.product;

import me.maru.seeTogether.domain.product.OttProduct;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface OttProductRepository extends JpaRepository<OttProduct, Long> {
Optional<OttProduct> findOttProductByOttProductIdAndDelete(Long ottProductId, Boolean delete);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.maru.seeTogether.service.group.accout.groupFollower.create;

import me.maru.seeTogether.api.v1.group.accout.groupFollower.GroupFollowerCreateRequest;
import me.maru.seeTogether.api.v1.group.accout.groupFollower.GroupFollowerCreateResponse;

public interface GroupFollowerCreator {
GroupFollowerCreateResponse create(GroupFollowerCreateRequest groupFollowerCreateRequest);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package me.maru.seeTogether.service.group.accout.groupFollower.create;
Copy link
Collaborator

Choose a reason for hiding this comment

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

impl 들은 /impl 패키지로 분리해보세요. 구현과 스펙을 구분하기 좋습니다


import me.maru.seeTogether.api.v1.group.accout.groupFollower.GroupFollowerCreateRequest;
import me.maru.seeTogether.api.v1.group.accout.groupFollower.GroupFollowerCreateResponse;
import me.maru.seeTogether.domain.group.account.GroupAccount;
import me.maru.seeTogether.repository.group.GroupAccountRepository;
import me.maru.seeTogether.repository.group.ProductGroupRepository;
import me.maru.seeTogether.repository.payment.CardInfoRepository;
import me.maru.seeTogether.repository.product.OttProductRepository;
import me.maru.seeTogether.repository.user.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.NoSuchElementException;

@Service
public class GroupFollowerCreatorImpl implements GroupFollowerCreator{

private final CardInfoRepository cardInfoRepository;
private final UserRepository userRepository;
private final ProductGroupRepository productGroupRepository;
private final OttProductRepository ottProductRepository;
private final GroupAccountRepository groupAccountRepository;

@Autowired
public GroupFollowerCreatorImpl(CardInfoRepository cardInfoRepository, UserRepository userRepository, ProductGroupRepository productGroupRepository, OttProductRepository ottProductRepository, GroupAccountRepository groupAccountRepository) {
this.cardInfoRepository = cardInfoRepository;
this.userRepository = userRepository;
this.productGroupRepository = productGroupRepository;
this.ottProductRepository = ottProductRepository;
this.groupAccountRepository = groupAccountRepository;
}

@Override
public GroupFollowerCreateResponse create(GroupFollowerCreateRequest groupFollowerCreateRequest) {
final var user = userRepository.findById(groupFollowerCreateRequest.getUserId())
.orElseThrow(() -> new UsernameNotFoundException("서버에 등록된 유저가 아닙니다."));

final var cardInfo = cardInfoRepository.findCardInfoByUserAndDeleteYn(user, false).orElseThrow(
() -> new NoSuchElementException("카드가 등록되어있지 않는 유저입니다."));

final var ottProduct = ottProductRepository.findOttProductByOttProductIdAndDelete(groupFollowerCreateRequest.getOttProductId(), false)
.orElseThrow(() -> new IllegalArgumentException("해당 OTT 아이디는 등록되어있지 않습니다."));
final var productGroup = productGroupRepository.findTopByOttProductAndCurrentParticipantsSizeBeforeAndDelete(ottProduct, ottProduct.getTotalParticipantsSize(), false)
.orElseThrow(() -> new NoSuchElementException("제공되는 그룹이 존재하지 않습니다."));

// TODO:결제진행 은 PG사를 mocking 하고싶다.

productGroup.setCurrentParticipantsSize(productGroup.getCurrentParticipantsSize() + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

get/set 으로 진행하기 보다는 "증가" 를 수행하는 역할을 정의해보는게 좋을 것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네 알겠습니다. !

productGroupRepository.save(productGroup);

final var groupAccount= groupAccountRepository.findGroupAccountByProductGroupAndDelete(productGroup, false)
.orElseThrow(() -> new NoSuchElementException("해당 아이디가 존재하지 않습니다."));

// TODO : id 와 password 를 getter 를 이용한 방식은 고쳐야함.
return GroupFollowerCreateResponse.builder()
.productName(ottProduct.getProductName())
.ottId(groupAccount.getOttId())
.ottPassword(groupAccount.getOttPassword())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.maru.seeTogether.service.payment.create;
package me.maru.seeTogether.service.payment.card.create;

import me.maru.seeTogether.api.v1.payment.create.CardInfoCreateRequest;
import me.maru.seeTogether.api.v1.payment.create.CardInfoCreateResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.maru.seeTogether.service.payment.create;
package me.maru.seeTogether.service.payment.card.create;

import me.maru.seeTogether.api.v1.payment.create.CardInfoCreateRequest;
import me.maru.seeTogether.api.v1.payment.create.CardInfoCreateResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.maru.seeTogether.service.payment.query;
package me.maru.seeTogether.service.payment.card.query;

import me.maru.seeTogether.api.v1.payment.query.CardInfoQueryResponse;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package me.maru.seeTogether.service.payment.query;
package me.maru.seeTogether.service.payment.card.query;

import me.maru.seeTogether.api.v1.payment.query.CardInfoQueryResponse;
import me.maru.seeTogether.domain.payment.card.CardInfo;
import me.maru.seeTogether.domain.user.User;
import me.maru.seeTogether.repository.payment.CardInfoRepository;
import me.maru.seeTogether.repository.user.UserRepository;
import me.maru.seeTogether.util.SecurityUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.maru.seeTogether.service.payment.update;
package me.maru.seeTogether.service.payment.card.update;

import me.maru.seeTogether.api.v1.payment.create.CardInfoCreateRequest;
import me.maru.seeTogether.api.v1.payment.create.CardInfoCreateResponse;
Expand Down
Loading