Commit d77062e9 by Tuukka Kivilahti

initial commit for apollo

1 parent d7ffbd70
...@@ -29,8 +29,14 @@ ...@@ -29,8 +29,14 @@
"@angular/router": "^5.2.9", "@angular/router": "^5.2.9",
"@ngx-translate/core": "^9.0.0", "@ngx-translate/core": "^9.0.0",
"@ngx-translate/http-loader": "^2.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", "bootstrap": "^4.0.0",
"core-js": "^2.5.1", "core-js": "^2.5.1",
"graphql": "^0.13.2",
"graphql-tag": "^2.9.2",
"ngx-bootstrap": "^2.0.2", "ngx-bootstrap": "^2.0.2",
"rxjs": "^5.5.0", "rxjs": "^5.5.0",
"ts-helpers": "^1.1.1", "ts-helpers": "^1.1.1",
......
...@@ -16,6 +16,9 @@ import { NgModule } from '@angular/core'; ...@@ -16,6 +16,9 @@ import { NgModule } from '@angular/core';
import {LoginModule} from './modules/login/login.module'; import {LoginModule} from './modules/login/login.module';
import {LeftMenuModule} from './menu/left-menu/left-menu.module'; import {LeftMenuModule} from './menu/left-menu/left-menu.module';
import { FrontpageComponent } from './components/frontpage/frontpage.component'; 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({ @NgModule({
declarations: [ declarations: [
...@@ -32,6 +35,10 @@ import { FrontpageComponent } from './components/frontpage/frontpage.component'; ...@@ -32,6 +35,10 @@ import { FrontpageComponent } from './components/frontpage/frontpage.component';
LoginModule, LoginModule,
LeftMenuModule, LeftMenuModule,
HttpClientModule,
ApolloModule,
HttpLinkModule,
AlertModule.forRoot(), AlertModule.forRoot(),
...@@ -50,6 +57,7 @@ import { FrontpageComponent } from './components/frontpage/frontpage.component'; ...@@ -50,6 +57,7 @@ import { FrontpageComponent } from './components/frontpage/frontpage.component';
LocaleService, LocaleService,
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
UserService, UserService,
{ provide: APOLLO_OPTIONS, useFactory: createApollo, deps: [HttpLink]},
], ],
bootstrap: [AppComponent] bootstrap: [AppComponent]
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {MoyaLocale} from './moya-locale.model'; import {MoyaLocale} from './moya-locale.model';
import {MOYA_BASE_URL} from '../../shared/tools/moya-rest.tool';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/catch';
import {TranslateService} from '@ngx-translate/core'; import {TranslateService} from '@ngx-translate/core';
import {MOYA_REST_URL} from "../../shared/config/moya.config";
export const ENGLISH = 'en'; export const ENGLISH = 'en';
...@@ -69,7 +69,7 @@ export class LocaleService { ...@@ -69,7 +69,7 @@ export class LocaleService {
return new Observable<string>(x => x.next(this.selectedLocale)); 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 => .catch(x =>
Observable.of({} as MoyaLocale) Observable.of({} as MoyaLocale)
) )
...@@ -107,7 +107,7 @@ export class LocaleService { ...@@ -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. // 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); localStorage.setItem(LOCALSTORAGE_NAME, locale);
return 'ok'; return 'ok';
}).subscribe(); }).subscribe();
......
...@@ -8,7 +8,7 @@ import 'rxjs/add/operator/switchMap'; ...@@ -8,7 +8,7 @@ import 'rxjs/add/operator/switchMap';
import 'rxjs/add/observable/forkJoin'; import 'rxjs/add/observable/forkJoin';
import 'rxjs/add/operator/first'; import 'rxjs/add/operator/first';
import {HttpClient} from '@angular/common/http'; 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() @Injectable()
export class ViplistService { export class ViplistService {
...@@ -25,11 +25,11 @@ export class ViplistService { ...@@ -25,11 +25,11 @@ export class ViplistService {
public get(searchString?: string): Observable<Array<Vip>> { public get(searchString?: string): Observable<Array<Vip>> {
if (!searchString) { 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)))); .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)))); .switchMap(v => Observable.forkJoin(...(v as Array<any>).map(x => this.hostPopulator(x))));
} }
...@@ -46,7 +46,7 @@ export class ViplistService { ...@@ -46,7 +46,7 @@ export class ViplistService {
throw new Error('TODO: errori, tyhmä vippi'); 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() .first()
.toPromise(); .toPromise();
...@@ -55,13 +55,13 @@ export class ViplistService { ...@@ -55,13 +55,13 @@ export class ViplistService {
public getWithId(id: number): Observable<Vip> { 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> { 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'; ...@@ -3,7 +3,7 @@ import {User} from '../models/user.model';
import {CacheService} from './cache.service'; import {CacheService} from './cache.service';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {MOYA_BASE_URL} from '../tools/moya-rest.tool'; import {MOYA_REST_URL} from "../config/moya.config";
@Injectable() @Injectable()
...@@ -17,7 +17,7 @@ export class UserService { ...@@ -17,7 +17,7 @@ export class UserService {
return Observable.throw('There should be userid'); 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, return this.cacheService.cacheObservable('moya:UserService', path,
this.http.get<User>(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 { ...@@ -55,6 +55,9 @@ public class MoyaGraphQLServlet extends HttpServlet {
private PermissionBeanLocal permbean; private PermissionBeanLocal permbean;
@EJB @EJB
private VipBeanLocal vipBean;
@EJB
private RoleBeanLocal rolebean; private RoleBeanLocal rolebean;
@EJB @EJB
private AllergyBeanLocal allergybean; private AllergyBeanLocal allergybean;
...@@ -455,6 +458,20 @@ public class MoyaGraphQLServlet extends HttpServlet { ...@@ -455,6 +458,20 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addField(Discount_.meta); 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); EntityGQLBuilder<LanEvent> b = builder.createEntity(SIMPLE_EVENT_TYPE_NAME);
...@@ -465,8 +482,6 @@ public class MoyaGraphQLServlet extends HttpServlet { ...@@ -465,8 +482,6 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addField(LanEvent_.ticketSalesBegin); 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_.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); b.addField(LanEvent_.meta);
} }
{ {
EntityGQLBuilder<Compo> b = builder.createEntity(Compo.class); EntityGQLBuilder<Compo> b = builder.createEntity(Compo.class);
...@@ -552,6 +567,7 @@ public class MoyaGraphQLServlet extends HttpServlet { ...@@ -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(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.addListField(Compo.class).dataFetcher(environment -> votebean.getCompoList(true).stream().sorted(ENTITY_ID_SORTER).collect(toList()));
b.addField(LanEvent_.id); b.addField(LanEvent_.id);
b.addListField(Vip.class).dataFetcher(enviroment -> vipBean.getAvailableVips());
} }
return builder; return builder;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!