Skip to content

Commit

Permalink
Merge pull request #182 from 9oormthon-univ/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
HyunWoo9930 authored Nov 28, 2024
2 parents 1c6c2bd + 0dc3c7c commit 931057b
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public Message prepay(String userId, PrepayRequest prepayRequest) {
storeTeam.setPersonalAllocatedPoint(prepayRequest.personalAllocatedAmount());
storeTeam.recharge(prepayRequest.prepayAmount());


return Message.builder()
.message("맀μž₯ μ„ κ²°μ œκ°€ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
.build();
Expand All @@ -122,4 +121,4 @@ public PrepaymentInfoResponse getPrepayInfo(String userId, Long storeId, Long te
prepaymentInfoResponse.setWallet(user.getPoint());
return prepaymentInfoResponse;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -19,6 +20,7 @@
import com.jangburich.domain.team.dto.response.MyTeamResponse;
import com.jangburich.domain.team.dto.response.TeamCodeResponse;
import com.jangburich.domain.team.dto.response.TeamMemberResponse;
import com.jangburich.domain.team.dto.response.TeamSecretCodeResponse;
import com.jangburich.domain.user.domain.User;
import com.jangburich.domain.user.repository.UserRepository;
import com.jangburich.global.payload.Message;
Expand All @@ -38,7 +40,7 @@ public class TeamService {
private final UserTeamRepository userTeamRepository;

@Transactional
public Message registerTeam(String userId, RegisterTeamRequest registerTeamRequest) {
public TeamSecretCodeResponse registerTeam(String userId, RegisterTeamRequest registerTeamRequest) {
User user = userRepository.findByProviderId(userId)
.orElseThrow(() -> new NullPointerException());

Expand All @@ -47,19 +49,19 @@ public Message registerTeam(String userId, RegisterTeamRequest registerTeamReque
.description(registerTeamRequest.description())
.teamLeader(new TeamLeader(user.getUserId(), registerTeamRequest.teamLeaderAccountNumber(),
registerTeamRequest.bankName()))
.secretCode(registerTeamRequest.secretCode())
.point(ZERO)
.teamType(TeamType.valueOf(registerTeamRequest.teamType()))
.build();

teamRepository.save(team);
Team saved = teamRepository.save(team);

UserTeam userTeam = UserTeam.of(user, team);
userTeamRepository.save(userTeam);

return Message.builder()
.message("νŒ€ 생성이 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
.build();
TeamSecretCodeResponse teamSecretCodeResponse = new TeamSecretCodeResponse();
teamSecretCodeResponse.setUuid(saved.getSecretCode());

return teamSecretCodeResponse;
}

@Transactional
Expand Down Expand Up @@ -134,15 +136,13 @@ public MyTeamDetailsResponse getTeamDetailsById(String userId, Long teamId) {

if (!team.getTeamLeader().getUser_id().equals(user.getUserId())) {
// 일반 ꡬ성원
MyTeamDetailsResponse myTeamDetailsAsMember = teamRepository.findMyTeamDetailsAsMember(user.getUserId(),
return teamRepository.findMyTeamDetailsAsMember(user.getUserId(),
teamId);
return myTeamDetailsAsMember;
}
// νŒ€ 리더일 λ•Œ
MyTeamDetailsResponse myTeamDetailsAsLeader = teamRepository.findMyTeamDetailsAsLeader(user.getUserId(),
teamId);

return myTeamDetailsAsLeader;
return teamRepository.findMyTeamDetailsAsLeader(user.getUserId(),
teamId);
}

public List<TeamMemberResponse> getTeamMembers(String userId, Long teamId) {
Expand Down
87 changes: 47 additions & 40 deletions src/main/java/com/jangburich/domain/team/domain/Team.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.jangburich.domain.team.domain;

import jakarta.persistence.Embedded;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import java.util.UUID;

import com.jangburich.domain.common.BaseEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.PrePersist;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -21,55 +23,60 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Team extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", updatable = false)
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", updatable = false)
private Long id;

@Column(name = "name")
private String name;
@Column(name = "name")
private String name;

@Column(name = "description")
private String description;
@Column(name = "description")
private String description;

@Column(name = "secret_code")
private String secretCode;
@Column(name = "secret_code", updatable = false, unique = true)
private String secretCode;

@Embedded
private TeamLeader teamLeader;
@Embedded
private TeamLeader teamLeader;

@Column(name = "point")
private Integer point;
@Column(name = "point")
private Integer point;

@Enumerated(EnumType.STRING)
@Column(name = "team_type")
private TeamType teamType;
@Enumerated(EnumType.STRING)
@Column(name = "team_type")
private TeamType teamType;

public void updatePoint(Integer point) {
this.point += point;
}
public void updatePoint(Integer point) {
this.point += point;
}

public void validateJoinCode(String joinCode) {
if (!this.secretCode.equals(joinCode)) {
throw new IllegalArgumentException("μœ νš¨ν•˜μ§€ μ•Šμ€ μž…μž₯ μ½”λ“œμž…λ‹ˆλ‹€.");
}
}


@Builder
public Team(String name, String description, String secretCode, TeamLeader teamLeader, Integer point,
TeamType teamType) {
this.name = name;
this.description = description;
this.secretCode = secretCode;
this.teamLeader = teamLeader;
this.point = point;
this.teamType = teamType;
}

public void validateIsTeamLeader(Long userId, Long userId1) {
if (!userId.equals(userId1)) {
throw new IllegalArgumentException("νŒ€μ˜ 리더가 μ•„λ‹Œ μ‚¬λžŒμ€ μ„ κ²°μ œλ₯Ό ν•  수 μ—†μŠ΅λ‹ˆλ‹€.");
}
}
@PrePersist
private void generateSecretCode() {
if (this.secretCode == null) {
this.secretCode = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
}
}

@Builder
public Team(String name, String description, TeamLeader teamLeader, Integer point,
TeamType teamType) {
this.name = name;
this.description = description;
this.teamLeader = teamLeader;
this.point = point;
this.teamType = teamType;
}

public void validateIsTeamLeader(Long userId, Long userId1) {
if (!userId.equals(userId1)) {
throw new IllegalArgumentException("νŒ€μ˜ 리더가 μ•„λ‹Œ μ‚¬λžŒμ€ μ„ κ²°μ œλ₯Ό ν•  수 μ—†μŠ΅λ‹ˆλ‹€.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,35 @@ public MyTeamDetailsResponse findMyTeamDetailsAsMember(Long userId, Long teamId)
.fetch();

return queryFactory
.selectDistinct(new QMyTeamDetailsResponse(
storeTeam.team.id,
storeTeam.team.name,
storeTeam.team.description,
Expressions.constant(-1),
storeTeam.remainPoint,
storeTeam.personalAllocatedPoint,
pointTransaction.transactionedPoint.sum(),
Expressions.constant(prepayedStores),
Expressions.constant(images),
Expressions.constant(images.size()),
Expressions.constant(todayPayments),
Expressions.constant(todayPayments.size())
))
.from(storeTeam)
.leftJoin(team).on(storeTeam.team.id.eq(teamId))
.leftJoin(userTeam).on(userTeam.team.id.eq(storeTeam.team.id))
.leftJoin(pointTransaction).on(pointTransaction.transactionType.eq(TransactionType.FOOD_PURCHASE),
pointTransaction.user.userId.eq(userId))
.where(storeTeam.team.id.eq(teamId))
.fetchOne();
.selectDistinct(new QMyTeamDetailsResponse(
storeTeam.team.id,
storeTeam.team.name,
storeTeam.team.description,
Expressions.constant(-1),
storeTeam.remainPoint,
storeTeam.personalAllocatedPoint,
pointTransaction.transactionedPoint.sum(),
Expressions.constant(prepayedStores),
Expressions.constant(images),
Expressions.constant(images.size()),
Expressions.constant(todayPayments),
Expressions.constant(todayPayments.size())
))
.from(storeTeam)
.leftJoin(team).on(storeTeam.team.id.eq(teamId))
.leftJoin(userTeam).on(userTeam.team.id.eq(storeTeam.team.id))
.leftJoin(pointTransaction).on(pointTransaction.transactionType.eq(TransactionType.FOOD_PURCHASE),
pointTransaction.user.userId.eq(userId))
.where(storeTeam.team.id.eq(teamId))
.groupBy(
storeTeam.team.id,
storeTeam.team.name,
storeTeam.team.description,
storeTeam.remainPoint,
storeTeam.personalAllocatedPoint
)
.fetchOne();

}

@Override
Expand Down Expand Up @@ -139,26 +147,34 @@ public MyTeamDetailsResponse findMyTeamDetailsAsLeader(Long userId, Long teamId)


return queryFactory
.selectDistinct(new QMyTeamDetailsResponse(
storeTeam.team.id,
storeTeam.team.name,
storeTeam.team.description,
storeTeam.point,
storeTeam.remainPoint,
Expressions.constant(-1),
pointTransaction.transactionedPoint.sum(),
Expressions.constant(prepayedStores),
Expressions.constant(images),
Expressions.constant(images.size()),
Expressions.constant(todayPayments),
Expressions.constant(todayPayments.size())
))
.from(storeTeam)
.leftJoin(team).on(storeTeam.team.id.eq(teamId))
.leftJoin(userTeam).on(userTeam.team.id.eq(storeTeam.team.id))
.leftJoin(pointTransaction).on(pointTransaction.transactionType.eq(TransactionType.FOOD_PURCHASE),
pointTransaction.user.userId.eq(userId))
.where(storeTeam.team.id.eq(teamId))
.fetchOne();
.selectDistinct(new QMyTeamDetailsResponse(
storeTeam.team.id,
storeTeam.team.name,
storeTeam.team.description,
storeTeam.point,
storeTeam.remainPoint,
Expressions.constant(-1),
pointTransaction.transactionedPoint.sum(),
Expressions.constant(prepayedStores),
Expressions.constant(images),
Expressions.constant(images.size()),
Expressions.constant(todayPayments),
Expressions.constant(todayPayments.size())
))
.from(storeTeam)
.leftJoin(team).on(storeTeam.team.id.eq(teamId))
.leftJoin(userTeam).on(userTeam.team.id.eq(storeTeam.team.id))
.leftJoin(pointTransaction).on(pointTransaction.transactionType.eq(TransactionType.FOOD_PURCHASE),
pointTransaction.user.userId.eq(userId))
.where(storeTeam.team.id.eq(teamId))
.groupBy(
storeTeam.team.id,
storeTeam.team.name,
storeTeam.team.description,
storeTeam.point,
storeTeam.remainPoint
)
.fetchOne();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import com.jangburich.domain.user.domain.User;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface TeamRepository extends JpaRepository<Team, Long>, TeamQueryDslRepository {
Optional<Team> findBySecretCode(String joinCode);
Optional<Team> findBySecretCode(String secretCode);


@Query("SELECT t FROM Team t JOIN UserTeam ut ON ut.team = t WHERE ut.user = :user AND t.status = :status")
Optional<List<Team>> findAllByUserAndStatus(@Param("user") User user, @Param("status") Status status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public record RegisterTeamRequest(
String teamType,
String teamName,
String description,
String secretCode,
String teamLeaderAccountNumber,
String bankName,
int memberLimit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jangburich.domain.team.dto.response;

import java.util.UUID;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@RequiredArgsConstructor
public class TeamSecretCodeResponse {
private String uuid;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jangburich.domain.team.presentation;

import java.util.List;
import java.util.UUID;

import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -17,6 +18,7 @@
import com.jangburich.domain.team.dto.response.MyTeamResponse;
import com.jangburich.domain.team.dto.response.TeamCodeResponse;
import com.jangburich.domain.team.dto.response.TeamMemberResponse;
import com.jangburich.domain.team.dto.response.TeamSecretCodeResponse;
import com.jangburich.global.payload.Message;
import com.jangburich.global.payload.ResponseCustom;
import com.jangburich.utils.parser.AuthenticationParser;
Expand All @@ -35,7 +37,7 @@ public class TeamController {

@Operation(summary = "νŒ€ 생성", description = "νŒ€μ„ μƒμ„±ν•œλ‹€. νŒ€ λ¦¬λ”λŠ” μƒμ„±μž")
@PostMapping
public ResponseCustom<Message> registerTeam(
public ResponseCustom<TeamSecretCodeResponse> registerTeam(
Authentication authentication,
@RequestBody RegisterTeamRequest registerTeamRequest
) {
Expand Down

0 comments on commit 931057b

Please sign in to comment.