Commit d77062e9 by Tuukka Kivilahti

initial commit for apollo

1 parent d7ffbd70
......@@ -29,8 +29,14 @@
"@angular/router": "^5.2.9",
"@ngx-translate/core": "^9.0.0",
"@ngx-translate/http-loader": "^2.0.0",
"apollo-angular": "^1.1.2",
"apollo-angular-link-http": "^1.1.1",
"apollo-cache-inmemory": "^1.2.6",
"apollo-client": "^2.3.7",
"bootstrap": "^4.0.0",
"core-js": "^2.5.1",
"graphql": "^0.13.2",
"graphql-tag": "^2.9.2",
"ngx-bootstrap": "^2.0.2",
"rxjs": "^5.5.0",
"ts-helpers": "^1.1.1",
......
......@@ -16,6 +16,9 @@ import { NgModule } from '@angular/core';
import {LoginModule} from './modules/login/login.module';
import {LeftMenuModule} from './menu/left-menu/left-menu.module';
import { FrontpageComponent } from './components/frontpage/frontpage.component';
import {HttpLink, HttpLinkModule} from "apollo-angular-link-http";
import {APOLLO_OPTIONS, ApolloModule} from "apollo-angular";
import {createApollo} from "./shared/config/moya.config";
@NgModule({
declarations: [
......@@ -32,6 +35,10 @@ import { FrontpageComponent } from './components/frontpage/frontpage.component';
LoginModule,
LeftMenuModule,
HttpClientModule,
ApolloModule,
HttpLinkModule,
AlertModule.forRoot(),
......@@ -50,6 +57,7 @@ import { FrontpageComponent } from './components/frontpage/frontpage.component';
LocaleService,
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
UserService,
{ provide: APOLLO_OPTIONS, useFactory: createApollo, deps: [HttpLink]},
],
bootstrap: [AppComponent]
......
import { Injectable } from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {MoyaLocale} from './moya-locale.model';
import {MOYA_BASE_URL} from '../../shared/tools/moya-rest.tool';
import {HttpClient} from '@angular/common/http';
import 'rxjs/add/operator/catch';
import {TranslateService} from '@ngx-translate/core';
import {MOYA_REST_URL} from "../../shared/config/moya.config";
export const ENGLISH = 'en';
......@@ -69,7 +69,7 @@ export class LocaleService {
return new Observable<string>(x => x.next(this.selectedLocale));
}
return this.http.get<MoyaLocale>(MOYA_BASE_URL + '/v3/locale/')
return this.http.get<MoyaLocale>(MOYA_REST_URL + '/v3/locale/')
.catch(x =>
Observable.of({} as MoyaLocale)
)
......@@ -107,7 +107,7 @@ export class LocaleService {
};
// let's save locale to database, if it fails, we save it into localstorage. No errors to show for user.
this.http.post(MOYA_BASE_URL + '/v3/locale/', newLocale).catch(x => {
this.http.post(MOYA_REST_URL + '/v3/locale/', newLocale).catch(x => {
localStorage.setItem(LOCALSTORAGE_NAME, locale);
return 'ok';
}).subscribe();
......
......@@ -8,7 +8,7 @@ import 'rxjs/add/operator/switchMap';
import 'rxjs/add/observable/forkJoin';
import 'rxjs/add/operator/first';
import {HttpClient} from '@angular/common/http';
import {MOYA_BASE_URL} from '../../shared/tools/moya-rest.tool';
import {MOYA_REST_URL} from "../../shared/config/moya.config";
@Injectable()
export class ViplistService {
......@@ -25,11 +25,11 @@ export class ViplistService {
public get(searchString?: string): Observable<Array<Vip>> {
if (!searchString) {
return this.http.get(MOYA_BASE_URL + 'v3/vip/all')
return this.http.get(MOYA_REST_URL + 'v3/vip/all')
.switchMap(res => Observable.forkJoin(...(res as Array<any>).map(apiRow => this.hostPopulator(apiRow))));
}
return this.http.get(MOYA_BASE_URL + 'v3/vip/search/' + searchString)
return this.http.get(MOYA_REST_URL + 'v3/vip/search/' + searchString)
.switchMap(v => Observable.forkJoin(...(v as Array<any>).map(x => this.hostPopulator(x))));
}
......@@ -46,7 +46,7 @@ export class ViplistService {
throw new Error('TODO: errori, tyhmä vippi');
}
const res: any = await this.http.delete(MOYA_BASE_URL + 'v3/vip/' + vip.id)
const res: any = await this.http.delete(MOYA_REST_URL + 'v3/vip/' + vip.id)
.first()
.toPromise();
......@@ -55,13 +55,13 @@ export class ViplistService {
public getWithId(id: number): Observable<Vip> {
return this.http.get(MOYA_BASE_URL + 'v3/vip/' + id).map(x => x as Vip);
return this.http.get(MOYA_REST_URL + 'v3/vip/' + id).map(x => x as Vip);
}
public create(vip: Vip): Observable<Vip> {
return this.http.post(MOYA_BASE_URL + 'v3/vip/create', vip).map(x => x as Vip);
return this.http.post(MOYA_REST_URL + 'v3/vip/create', vip).map(x => x as Vip);
}
......
import {InMemoryCache} from "apollo-cache-inmemory";
import {HttpLink} from "apollo-angular-link-http";
export const MOYA_BASE_URL = '/MoyaWeb/';
export const MOYA_REST_URL = MOYA_BASE_URL + 'rest/';
export function createApollo(httpLink: HttpLink) {
return {
link: httpLink.create({uri: MOYA_REST_URL + '/graphql'}),
cache: new InMemoryCache(),
};
}
......@@ -3,7 +3,7 @@ import {User} from '../models/user.model';
import {CacheService} from './cache.service';
import {Observable} from 'rxjs/Observable';
import {HttpClient} from '@angular/common/http';
import {MOYA_BASE_URL} from '../tools/moya-rest.tool';
import {MOYA_REST_URL} from "../config/moya.config";
@Injectable()
......@@ -17,7 +17,7 @@ export class UserService {
return Observable.throw('There should be userid');
}
const path = MOYA_BASE_URL + 'v2/user/' + id;
const path = MOYA_REST_URL + 'v2/user/' + id;
return this.cacheService.cacheObservable('moya:UserService', path,
this.http.get<User>(path)
......
export const MOYA_BASE_URL = '/MoyaWeb/rest/';
export abstract class MoyaRestTool {
/*
genUrl(subUrl: string, urlParams?: Map<string, string>): string {
let suffix = '';
if (urlParams) {
urlParams.forEach(function(value: string, key: string) {
if (suffix.length <= 0) {
suffix = '?';
} else {
suffix += '&';
}
suffix += key + '=' + value;
});
}
return '/MoyaWeb/rest/' + subUrl + suffix; // <-- TODO: kauneista
} */
}
......@@ -55,6 +55,9 @@ public class MoyaGraphQLServlet extends HttpServlet {
private PermissionBeanLocal permbean;
@EJB
private VipBeanLocal vipBean;
@EJB
private RoleBeanLocal rolebean;
@EJB
private AllergyBeanLocal allergybean;
......@@ -455,6 +458,20 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addField(Discount_.meta);
}
{
EntityGQLBuilder<Vip> b = builder.createEntity(Vip.class);
b.addField(Vip_.id);
b.addField(Vip_.created);
b.addField(Vip_.creator);
b.addField(Vip_.description);
b.addField(Vip_.event);
b.addField(Vip_.host);
b.addField(Vip_.products);
b.addField(Vip_.shortdescr);
}
{
EntityGQLBuilder<LanEvent> b = builder.createEntity(SIMPLE_EVENT_TYPE_NAME);
......@@ -465,8 +482,6 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addField(LanEvent_.ticketSalesBegin);
b.addField(LanEvent_.domains).type(GraphQLList.list(GraphQLString)).dataFetcher(environment -> ((LanEvent) environment.getSource()).getDomains().stream().sorted(ENTITY_ID_SORTER).map(d -> d.getDomain()).collect(toList()));
b.addField(LanEvent_.meta);
}
{
EntityGQLBuilder<Compo> b = builder.createEntity(Compo.class);
......@@ -552,6 +567,7 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addListField(Product.class).dataFetcher(environment -> productbean.findProductsForEvent().stream().sorted(ENTITY_ID_SORTER).collect(toList()));
b.addListField(Compo.class).dataFetcher(environment -> votebean.getCompoList(true).stream().sorted(ENTITY_ID_SORTER).collect(toList()));
b.addField(LanEvent_.id);
b.addListField(Vip.class).dataFetcher(enviroment -> vipBean.getAvailableVips());
}
return builder;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!