<commit_before>﻿using Obsidian.Application.Commanding.ApplicationCommands;
using Obsidian.Domain;
using Obsidian.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Obsidian.Application.Commanding.CommandHandlers
{
    public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand, Guid>
    {
        private readonly IUserRepository _repo;

        public CreateUserCommandHandler(IUserRepository repo)
        {
            _repo = repo;
        }

        public async Task<CommandResult<Guid>> HandleAsync(CreateUserCommand command)
        {
            if (_repo.FindByUserNameAsync(command.Dto.UserName) != null)
            {
                return new CommandResult<Guid>(false, new InvalidOperationException($"User of user name {command.Dto.UserName} already exists."), Guid.Empty);
            }
            var user = User.Create(Guid.NewGuid(), command.Dto.UserName);
            user.SetPassword(command.Dto.Password);
            await _repo.AddAsync(user);<commit_msg>fixed create user precondiction<commit_after>﻿using Obsidian.Application.Commanding.ApplicationCommands;
using Obsidian.Domain;
using Obsidian.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Obsidian.Application.Commanding.CommandHandlers
{
    public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand, Guid>
    {
        private readonly IUserRepository _repo;

        public CreateUserCommandHandler(IUserRepository repo)
        {
            _repo = repo;
        }

        public async Task<CommandResult<Guid>> HandleAsync(CreateUserCommand command)
        {
            if (await _repo.FindByUserNameAsync(command.Dto.UserName) != null)
            {
                return new CommandResult<Guid>(false, new InvalidOperationException($"User of user name {command.Dto.UserName} already exists."), Guid.Empty);
            }
            var user = User.Create(Guid.NewGuid(), command.Dto.UserName);
            user.SetPassword(command.Dto.Password);
            await _repo.AddAsync(user);
{'fraction_non_alphanumeric': 0.08747697974217311, 'fraction_numerical': 0.0, 'mean_word_length': 3.2194174757281555, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7394892', 'n_tokens_mistral': 576, 'n_tokens_neox': 566, 'n_words': 117}