public CircleJoinOutputData Handle(CircleJoinInputData inputData)
        {
            using var transaction = new TransactionScope();

            var memberId = new UserId(inputData.MemberId);
            var member   = userRepository.Find(memberId);

            if (member == null)
            {
                throw new UserNotFoundException(memberId, "ユーザが見つかりませんでした。");
            }

            var id     = new CircleId(inputData.CircleId);
            var circle = circleRepository.Find(id);

            if (circle == null)
            {
                throw new CircleNotFoundException(id, "サークルが見つかりませんでした。");
            }

            var fullSpec = new CircleFullSpecification(userRepository);

            if (fullSpec.IsSatisfiedBy(circle))
            {
                throw new CircleFullException(id, "サークルに所属しているメンバーが上限に達しています。");
            }

            circle.Join(member, fullSpec);
            circleRepository.Save(circle);

            transaction.Complete();

            return(new CircleJoinOutputData());
        }
Beispiel #2
0
        public CircleJoinOutputData Handle(CircleJoinInputData inputData)
        {
            using var transaction = new TransactionScope();

            var memberId = new UserId(inputData.MemberId);
            var member   = userRepository.Find(memberId);

            if (member == null)
            {
                throw new UserNotFoundException(memberId, "서클에 가입할 사용자를 찾지 못했음");
            }

            var id     = new CircleId(inputData.CircleId);
            var circle = circleRepository.Find(id);

            if (circle == null)
            {
                throw new CircleNotFoundException(id, "가입할 서클을 찾지 못했음");
            }

            var fullSpec = new CircleFullSpecification(userRepository);

            if (fullSpec.IsSatisfiedBy(circle))
            {
                throw new CircleFullException(id, "서클에 소속 가능한 최대 인원을 초과함");
            }

            circle.Join(member, fullSpec);
            circleRepository.Save(circle);

            transaction.Complete();

            return(new CircleJoinOutputData());
        }
Beispiel #3
0
        public void JoinMember(string id, [FromBody] CircleJoinMemberRequestModel request)
        {
            var command = new CircleJoinInputData(id, request.AddUserId);

            bus.Handle(command);
        }