public CircleCreateResult Create(CircleCreateCommand command) { using (var transaction = new TransactionScope()) { var ownerId = new UserId(command.OwnerId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new UserNotFoundException(ownerId, "서클장이 될 사용자가 없음"); } var name = new CircleName(command.Name); var circle = circleFactory.Create(name, owner); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "이미 등록된 서클임"); } circleRepository.Save(circle); transaction.Complete(); return(new CircleCreateResult(circle.Id.Value)); } }
public void CreateCircle(string userId, string circleName) { using (var transaction = new TransactionScope()) { var ownerId = new UserId(userId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new Exception("owner not found. userId: " + userId); } var circle = owner.CreateCircle(circleFactory, circleName); circleRepository.Save(circle); transaction.Complete(); } }
public void Join(CircleJoinCommand command) { var circleId = new CircleId(command.CircleId); var circle = circleRepository.Find(circleId); var owner = userRepository.Find(circle.Owner); var members = userRepository.Find(circle.Members); var circleMembers = new CircleMembers(circle.Id, owner, members); var circleFullSpec = new CircleMembersFullSpecification(); if (circleFullSpec.IsSatisfiedBy(circleMembers)) { throw new CircleFullException(circleId); } var memberId = new UserId(command.UserId); var member = userRepository.Find(memberId); if (member == null) { throw new UserNotFoundException(memberId, "사용자를 찾지 못했음"); } circle.Join(member); circleRepository.Save(circle); }
public void Join(CircleJoinCommand command) { var circleId = new CircleId(command.CircleId); var circle = circleRepository.Find(circleId); var users = userRepository.Find(circle.Members); // サークルに所属しているプレミアムユーザの人数により上限が変わる var premiumUserNumber = users.Count(user => user.IsPremium); var circleUpperLimit = premiumUserNumber < 10 ? 30 : 50; if (circle.CountMembers() >= circleUpperLimit) { throw new CircleFullException(circleId); } var memberId = new UserId(command.UserId); var member = userRepository.Find(memberId); if (member == null) { throw new UserNotFoundException(memberId, "ユーザが見つかりませんでした。"); } circle.Join(member); circleRepository.Save(circle); }
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()); }
public Task <Unit> Handle(CircleJoinMemberCommand command, CancellationToken cancellationToken) { using var transaction = new TransactionScope(); var circle = _circleRepository.Find(new CircleId(command.CircleId)); if (circle is null) { throw new CircleNotFoundException("サークルが見つかりませんでした。"); } var user = _userRepository.Find(new UserId(command.UserId)); if (user is null) { throw new UserNotFoundException("追加対象のユーザーが見つかりませんでした。"); } circle.Join(user); _circleRepository.Save(circle); transaction.Complete(); return(Task.FromResult(Unit.Value)); }
public CircleUpdateOutputData Handle(CircleUpdateInputData inputData) { using var transaction = new TransactionScope(); var id = new CircleId(inputData.Id); var circle = circleRepository.Find(id); if (circle == null) { throw new CircleNotFoundException(id); } if (inputData.Name != null) { var name = new CircleName(inputData.Name); circle.ChangeName(name); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "이미 등록된 서클임"); } } circleRepository.Save(circle); transaction.Complete(); return(new CircleUpdateOutputData()); }
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()); }
public void Join(CircleJoinCommand command) { var circleId = new CircleId(command.CircleId); var circle = circleRepository.Find(circleId); var users = userRepository.Find(circle.Members); // 서클에 소속된 프리미엄 사용자의 수에 따라 최대 인원이 결정됨 var premiumUserNumber = users.Count(user => user.IsPremium); var circleUpperLimit = premiumUserNumber < 10 ? 30 : 50; if (circle.CountMembers() >= circleUpperLimit) { throw new CircleFullException(circleId); } var memberId = new UserId(command.UserId); var member = userRepository.Find(memberId); if (member == null) { throw new UserNotFoundException(memberId, "사용자를 찾지 못했음"); } circle.Join(member); circleRepository.Save(circle); }
public CircleCreateOutputData Handle(CircleCreateInputData inputData) { using var transaction = new TransactionScope(); var ownerId = new UserId(inputData.OwnerId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new UserNotFoundException(ownerId, "サークルのオーナーとなるユーザが見つかりませんでした。"); } var name = new CircleName(inputData.Name); var circle = circleFactory.Create(name, owner); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "サークルは既に存在しています。"); } circleRepository.Save(circle); transaction.Complete(); return(new CircleCreateOutputData(circle.Id.Value)); }
public void Create(CircleCreateCommand command) { var ownerId = new UserId(command.UserId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new Exception("サークルオーナーとなるユーザーが見つかりませんでした。"); } var name = new CircleName(command.Name); var circle = circleFactory.Create(name, owner); if (circleService.Exists(circle)) { throw new Exception("サークルは既に存在しています。"); } circleRepository.Save(circle); }
public void Create(CircleCreateCommand command) { using (var transaction = new TransactionScope()) { var ownerId = new UserId(command.UserId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new UserNotFoundException(ownerId, "サークルのオーナーとなるユーザが見つかりませんでした。"); } var name = new CircleName(command.Name); var circle = circleFactory.Create(name, owner); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "サークルは既に存在しています。"); } circleRepository.Save(circle); transaction.Complete(); } }
public Task <Unit> Handle(CircleUpdateCommand command, CancellationToken cancellationToken) { using var transaction = new TransactionScope(); var circle = _circleRepository.Find(new CircleId(command.Id)); if (command.Name != null) { circle.ChangeName(new CircleName(command.Name)); if (_circleService.Exists(circle)) { throw new CanNotCircleRegisterException($"{ command.Name } は既に存在します。"); } } _circleRepository.Save(circle); transaction.Complete(); return(Task.FromResult(Unit.Value)); }
public void Join(CircleJoinCommand command) { var circleId = new CircleId(command.CircleId); var circle = circleRepository.Find(circleId); var circleFullSpecification = new CircleFullSpecification(userRepository); if (circleFullSpecification.IsSatisfiedBy(circle)) { throw new CircleFullException(circleId); } var memberId = new UserId(command.UserId); var member = userRepository.Find(memberId); if (member == null) { throw new UserNotFoundException(memberId, "ユーザが見つかりませんでした。"); } circle.Join(member); circleRepository.Save(circle); }
public Task <CircleRegisterOutputData> Handle(CircleRegisterCommand command, CancellationToken cancellationToken) { using var transaction = new TransactionScope(); var circle = _circleFactory.Create(command.Name, command.OwnerId); if (_circleService.Exists(circle)) { throw new CanNotCircleRegisterException($"{command.Name} は既に存在します。"); } var owner = _userRepository.Find(circle.Owner); if (owner is null) { throw new UserNotFoundException($"IDが {command.OwnerId} のユーザーは存在しません。"); } _circleRepository.Save(circle); transaction.Complete(); return(Task.FromResult(new CircleRegisterOutputData(circle.Id.Value))); }