public async Task <ActionResult <PersonResponse> > SearchForNonJudgePersonsByContactEmail([FromQuery] string contactEmail)
        {
            if (!contactEmail.IsValidEmail())
            {
                ModelState.AddModelError(nameof(contactEmail), $"Please provide a valid {nameof(contactEmail)}");
                return(BadRequest(ModelState));
            }

            var personQuery = new GetPersonByContactEmailQuery(contactEmail);
            var person      = await _queryHandler.Handle <GetPersonByContactEmailQuery, Person>(personQuery);

            if (person == null)
            {
                return(NotFound($"Person with {contactEmail} does not exist"));
            }

            var hearingsQuery = new GetHearingsByUsernameQuery(person.Username);
            var hearings      = await _queryHandler.Handle <GetHearingsByUsernameQuery, List <VideoHearing> >(hearingsQuery);

            var judicialHearings = hearings.SelectMany(v => v.Participants.Where(p => p.PersonId == person.Id))
                                   .Any(x => x.HearingRole.UserRole.IsJudge);

            if (judicialHearings)
            {
                return(Unauthorized("Only searches for non Judge persons are allowed"));
            }

            var mapper   = new PersonToResponseMapper();
            var response = mapper.MapPersonToResponse(person);

            return(Ok(response));
        }
        public async Task <IActionResult> PostPersonBySearchTerm(SearchTermRequest term)
        {
            var query      = new GetPersonBySearchTermQuery(term.Term);
            var personList = await _queryHandler.Handle <GetPersonBySearchTermQuery, List <Person> >(query);

            var mapper   = new PersonToResponseMapper();
            var response = personList.Select(x => mapper.MapPersonToResponse(x)).OrderBy(o => o.ContactEmail).ToList();

            return(Ok(response));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetStaffMemberBySearchTerm(string term)
        {
            if (term.Length < 3)
            {
                return(BadRequest("Search term must be atleast 3 charecters."));
            }

            var query           = new GetStaffMemberBySearchTermQuery(term);
            var staffMemberList = await _queryHandler.Handle <GetStaffMemberBySearchTermQuery, List <Person> >(query);

            if (staffMemberList.Count == 0)
            {
                return(NotFound());
            }
            var mapper   = new PersonToResponseMapper();
            var response = staffMemberList.Select(x => mapper.MapPersonToResponse(x)).OrderBy(o => o.ContactEmail).ToList();

            return(Ok(response));
        }
        public async Task <IActionResult> GetPersonByUsername(string username)
        {
            if (!username.IsValidEmail())
            {
                ModelState.AddModelError(nameof(username), $"Please provide a valid {nameof(username)}");
                return(BadRequest(ModelState));
            }

            var query  = new GetPersonByUsernameQuery(username);
            var person = await _queryHandler.Handle <GetPersonByUsernameQuery, Person>(query);

            if (person == null)
            {
                return(NotFound());
            }

            var mapper   = new PersonToResponseMapper();
            var response = mapper.MapPersonToResponse(person);

            return(Ok(response));
        }