diff --git a/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java b/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java index 368af43..d3c7e81 100644 --- a/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java +++ b/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java @@ -46,7 +46,7 @@ public String getType() { @Transactional @Override - public ReadyResponse payReady(Long userId, PayRequest payRequest) { + public ReadyResponse payReady(String userId, PayRequest payRequest) { Map parameters = new HashMap<>(); parameters.put("cid", "TC0ONETIME"); // 가맹점 코드(테스트용) @@ -85,7 +85,7 @@ public ReadyResponse payReady(Long userId, PayRequest payRequest) { @Transactional @Override - public ApproveResponse payApprove(Long userId, String tid, String pgToken) { + public ApproveResponse payApprove(String userId, String tid, String pgToken) { Map parameters = new HashMap<>(); parameters.put("cid", "TC0ONETIME"); // 가맹점 코드(테스트용) parameters.put("tid", tid); // 결제 고유번호 diff --git a/src/main/java/com/jangburich/domain/payment/application/PaymentProcessingService.java b/src/main/java/com/jangburich/domain/payment/application/PaymentProcessingService.java index b6df411..6f6186a 100644 --- a/src/main/java/com/jangburich/domain/payment/application/PaymentProcessingService.java +++ b/src/main/java/com/jangburich/domain/payment/application/PaymentProcessingService.java @@ -13,12 +13,12 @@ public class PaymentProcessingService { private final PaymentServiceStrategy paymentServiceStrategy; - public ReadyResponse processPayment(Long userId, PayRequest payRequest) { + public ReadyResponse processPayment(String userId, PayRequest payRequest) { PaymentService paymentService = paymentServiceStrategy.getPaymentService(payRequest.paymentType()); return paymentService.payReady(userId, payRequest); } - public ApproveResponse processSuccess(Long userId, String tid, String pgToken) { + public ApproveResponse processSuccess(String userId, String tid, String pgToken) { PaymentService paymentService = paymentServiceStrategy.getPaymentService("kakao"); return paymentService.payApprove(userId, tid, pgToken); } diff --git a/src/main/java/com/jangburich/domain/payment/application/PaymentService.java b/src/main/java/com/jangburich/domain/payment/application/PaymentService.java index 136ff70..743361c 100644 --- a/src/main/java/com/jangburich/domain/payment/application/PaymentService.java +++ b/src/main/java/com/jangburich/domain/payment/application/PaymentService.java @@ -6,6 +6,6 @@ public interface PaymentService { String getType(); - ReadyResponse payReady(Long userId, PayRequest payRequest); - ApproveResponse payApprove(Long userId, String tid, String pgToken); + ReadyResponse payReady(String userId, PayRequest payRequest); + ApproveResponse payApprove(String userId, String tid, String pgToken); } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/team/application/TeamService.java b/src/main/java/com/jangburich/domain/team/application/TeamService.java index af234d1..28374e5 100644 --- a/src/main/java/com/jangburich/domain/team/application/TeamService.java +++ b/src/main/java/com/jangburich/domain/team/application/TeamService.java @@ -1,5 +1,15 @@ package com.jangburich.domain.team.application; +import com.jangburich.domain.team.domain.Team; +import com.jangburich.domain.team.domain.TeamLeader; +import com.jangburich.domain.team.domain.TeamType; +import com.jangburich.domain.team.domain.UserTeam; +import com.jangburich.domain.team.domain.repository.TeamRepository; +import com.jangburich.domain.team.domain.repository.UserTeamRepository; +import com.jangburich.domain.team.dto.request.RegisterTeamRequest; +import com.jangburich.domain.user.domain.User; +import com.jangburich.domain.user.domain.repository.UserRepository; +import com.jangburich.global.payload.Message; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -9,5 +19,35 @@ @RequiredArgsConstructor public class TeamService { + private static final int ZERO = 0; + private final TeamRepository teamRepository; + private final UserRepository userRepository; + private final UserTeamRepository userTeamRepository; + + @Transactional + public Message registerTeam(String userId, RegisterTeamRequest registerTeamRequest) { + User user = userRepository.findByProviderId(userId) + .orElseThrow(() -> new NullPointerException()); + + Team team = Team.builder() + .name(registerTeamRequest.teamName()) + .description(registerTeamRequest.description()) + .teamLeader(new TeamLeader(user.getUserId(), registerTeamRequest.teamLeaderAccountNumber(), + registerTeamRequest.bankName())) + .point(ZERO) + .memberLimit(registerTeamRequest.memberLimit()) + .teamType(TeamType.valueOf(registerTeamRequest.teamType())) + .build(); + + System.out.println("222"); + teamRepository.save(team); + + UserTeam userTeam = UserTeam.of(user, team); + userTeamRepository.save(userTeam); + + return Message.builder() + .message("팀 생성이 완료되었습니다.") + .build(); + } } diff --git a/src/main/java/com/jangburich/domain/team/domain/Team.java b/src/main/java/com/jangburich/domain/team/domain/Team.java index 621a694..8c3806e 100644 --- a/src/main/java/com/jangburich/domain/team/domain/Team.java +++ b/src/main/java/com/jangburich/domain/team/domain/Team.java @@ -3,19 +3,16 @@ import jakarta.persistence.Embedded; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import java.util.HashSet; -import java.util.Set; import com.jangburich.domain.common.BaseEntity; -import com.jangburich.domain.user.domain.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.ManyToMany; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -51,10 +48,20 @@ public class Team extends BaseEntity { @Column(name = "team_type") private TeamType teamType; - @ManyToMany(mappedBy = "teams") - private Set users = new HashSet<>(); - public void updatePoint(Integer point) { this.point += point; } + + + @Builder + public Team(String name, String description, String secretCode, TeamLeader teamLeader, Integer point, + Integer memberLimit, TeamType teamType) { + this.name = name; + this.description = description; + this.secretCode = secretCode; + this.teamLeader = teamLeader; + this.point = point; + this.memberLimit = memberLimit; + this.teamType = teamType; + } } diff --git a/src/main/java/com/jangburich/domain/team/domain/TeamLeader.java b/src/main/java/com/jangburich/domain/team/domain/TeamLeader.java index 1bdba9c..bc3357f 100644 --- a/src/main/java/com/jangburich/domain/team/domain/TeamLeader.java +++ b/src/main/java/com/jangburich/domain/team/domain/TeamLeader.java @@ -11,10 +11,12 @@ public class TeamLeader { private Long user_id; private String accountNumber; + private String bankName; - public TeamLeader(Long user_id, String accountNumber) { + public TeamLeader(Long user_id, String accountNumber, String bankName) { this.user_id = user_id; this.accountNumber = accountNumber; + this.bankName = bankName; } public boolean isSameLeader(Long userId) { diff --git a/src/main/java/com/jangburich/domain/team/domain/UserTeam.java b/src/main/java/com/jangburich/domain/team/domain/UserTeam.java new file mode 100644 index 0000000..de746a6 --- /dev/null +++ b/src/main/java/com/jangburich/domain/team/domain/UserTeam.java @@ -0,0 +1,46 @@ +package com.jangburich.domain.team.domain; + +import com.jangburich.domain.common.BaseEntity; +import com.jangburich.domain.user.domain.User; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class UserTeam extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", updatable = false) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_id") + private Team team; + + public UserTeam(User user, Team team) { + this.user = user; + this.team = team; + } + + public static UserTeam of(User user, Team team) { + if (user == null || team == null) { + throw new IllegalArgumentException("유저와 팀은 null이 될 수 없습니다."); + } + return new UserTeam(user, team); + } +} diff --git a/src/main/java/com/jangburich/domain/team/domain/repository/UserTeamRepository.java b/src/main/java/com/jangburich/domain/team/domain/repository/UserTeamRepository.java new file mode 100644 index 0000000..e7060be --- /dev/null +++ b/src/main/java/com/jangburich/domain/team/domain/repository/UserTeamRepository.java @@ -0,0 +1,7 @@ +package com.jangburich.domain.team.domain.repository; + +import com.jangburich.domain.team.domain.UserTeam; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserTeamRepository extends JpaRepository { +} diff --git a/src/main/java/com/jangburich/domain/team/dto/request/RegisterTeamRequest.java b/src/main/java/com/jangburich/domain/team/dto/request/RegisterTeamRequest.java index 993d7c4..a0f9eda 100644 --- a/src/main/java/com/jangburich/domain/team/dto/request/RegisterTeamRequest.java +++ b/src/main/java/com/jangburich/domain/team/dto/request/RegisterTeamRequest.java @@ -1,4 +1,12 @@ package com.jangburich.domain.team.dto.request; -public record RegisterTeamRequest() { +public record RegisterTeamRequest( + String teamType, + String teamName, + String description, + String secretCode, + String teamLeaderAccountNumber, + String bankName, + int memberLimit +) { } diff --git a/src/main/java/com/jangburich/domain/team/presentation/TeamController.java b/src/main/java/com/jangburich/domain/team/presentation/TeamController.java index 5a51616..ecc88e8 100644 --- a/src/main/java/com/jangburich/domain/team/presentation/TeamController.java +++ b/src/main/java/com/jangburich/domain/team/presentation/TeamController.java @@ -4,6 +4,8 @@ import com.jangburich.domain.team.dto.request.RegisterTeamRequest; import com.jangburich.global.payload.Message; import com.jangburich.global.payload.ResponseCustom; +import com.jangburich.utils.parser.AuthenticationParser; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.security.core.Authentication; @@ -20,11 +22,12 @@ public class TeamController { private final TeamService teamService; + @Operation(summary = "팀 생성", description = "팀을 생성한다. 팀 리더는 생성자") @PostMapping public ResponseCustom registerTeam( Authentication authentication, @RequestBody RegisterTeamRequest registerTeamRequest ) { - return ResponseCustom.OK(); + return ResponseCustom.OK(teamService.registerTeam(AuthenticationParser.parseUserId(authentication), registerTeamRequest)); } } diff --git a/src/main/java/com/jangburich/domain/user/domain/User.java b/src/main/java/com/jangburich/domain/user/domain/User.java index 55eacb6..20ddfbf 100644 --- a/src/main/java/com/jangburich/domain/user/domain/User.java +++ b/src/main/java/com/jangburich/domain/user/domain/User.java @@ -56,14 +56,6 @@ public class User extends BaseEntity { private String role; - @ManyToMany - @JoinTable( - name = "user_team", - joinColumns = @JoinColumn(name = "user_id"), - inverseJoinColumns = @JoinColumn(name = "team_id") - ) - private Set teams = new HashSet<>(); - public static User create(String userId, String nickname, String image, String role) { User newUser = new User(); newUser.setProviderId(userId); diff --git a/src/main/java/com/jangburich/utils/parser/AuthenticationParser.java b/src/main/java/com/jangburich/utils/parser/AuthenticationParser.java index b607042..e5949c9 100644 --- a/src/main/java/com/jangburich/utils/parser/AuthenticationParser.java +++ b/src/main/java/com/jangburich/utils/parser/AuthenticationParser.java @@ -6,8 +6,8 @@ public class AuthenticationParser { private AuthenticationParser(){} - public static Long parseUserId(Authentication authentication) { + public static String parseUserId(Authentication authentication) { CustomOAuthUser principal = (CustomOAuthUser) authentication.getPrincipal(); - return Long.parseLong(principal.getUserId()); + return principal.getUserId(); } }