public ServicesInjection(IGlobalConfiguration globalConfig, IInjectionRepository repositories) { _invite = new InviteService(globalConfig); Match = new MatchService(globalConfig.OCR.ImageFileDirectory, repositories.Match); OCR = new MatchOCRService(globalConfig.OCR); PlayerPontuation = new PlayerPontuationService(repositories.PlayersResults, repositories.User, repositories.Match); UserChangesService = new UserChangesService(repositories.UserChange); Team = new TeamService(repositories.Team, _invite, repositories.User); TeamPontuation = new TeamPontuationService(repositories.TeamPontuation, repositories.Team, PlayerPontuation, null); SetupEvents(); }
public TeamModule(IBootstrapInjection injection) { _teamService = injection.Services.Team; _teamPontuationService = injection.Services.TeamPontuation; Get[EndpointConfigurationEnum.GET_TEAM] = p => { var teamId = p.teamId; return(Response.AsJson(new TeamDTO(_teamService.GetTeam(teamId)))); }; Post[EndpointConfigurationEnum.JOIN_TEAM] = p => { var token = p.token; var userId = p.userId; var teamid = p.teamId; _teamService.JoinTeam(userId, token, teamid); return(HttpStatusCode.OK); }; Get[EndpointConfigurationEnum.GET_TEAM_USER] = p => { var team = _teamService.GetTeamFromUser(p.userId); if (team == null) { return(HttpStatusCode.NotFound); } return(Response.AsJson(new TeamDTO(team))); }; Put[EndpointConfigurationEnum.GET_IMAGE_TEAM] = p => { var contentTypeRegex = new Regex("^multipart/form-data;\\s*boundary=(.*)$", RegexOptions.IgnoreCase); var boundary = contentTypeRegex.Match(Request.Headers.ContentType).Groups[1].Value; var multipart = new HttpMultipart(this.Request.Body, boundary); var bodyStream = multipart.GetBoundaries().First(b => b.Name == "image").Value; var teamId = p.teamId; _teamService.SubmitTeamImage(teamId, bodyStream); return(HttpStatusCode.OK); }; Get[EndpointConfigurationEnum.GET_IMAGE_TEAM] = p => { try { Stream imagem = _teamService.GetImage(p.teamId); if (imagem == null) { throw new ArgumentException("Não existe"); } return(Response.FromStream(imagem, "image/jpg")); } catch (ArgumentException) { return(HttpStatusCode.NotFound); } catch (Exception) { return(HttpStatusCode.InternalServerError); } }; Post[EndpointConfigurationEnum.CREATE_TEAM] = p => { try { var founderId = p.founderId.Value; var dto = JsonConvert.DeserializeObject <TeamDTO>(Request.Body.AsString()); _teamService.CreateTeam(founderId, dto.Id, dto.Alias); dto.Members.Where(c => c.Contains("@")).ToList() .ForEach(c => _teamService.InvitePlayer(c, dto.Id)); return(HttpStatusCode.OK); } catch (TeamAlreadyExistException ex) { return(Response.AsJson(new GenericErrorDTO(ex))); } catch (Exception ex) { return(Response.AsJson(new GenericErrorDTO(ex))); } }; Put[EndpointConfigurationEnum.INVITE_PLAYER_TEAM] = p => { if (p.email.ToString().Contains("@")) { _teamService.InvitePlayer(p.email.ToString(), p.teamId.ToString()); return(HttpStatusCode.Accepted); } else { return(HttpStatusCode.NotAcceptable); } }; Get[EndpointConfigurationEnum.GET_TEAM_PONTUATIONS] = p => { string id = p.teamId.ToString(); var result = _teamPontuationService.GetTeamPontuations(id).Select(c => new PlayerPontuationDTO(c)).ToList(); return(Response.AsJson(result)); }; }