Commit 8c88b25b by Tuukka Kivilahti

jotain unohtui

1 parent fd7b24d9
/**
* Created by tuukka on 04/02/17.
*/
export class VipProductDelivery {
/*
public Integer id;
public Integer delivererId;
public BigDecimal quantity;
public Date deliveryTime;
public String notes;
*/
id: number;
delivererId: number;
quantity: number;
deliveryTime: Date;
notes: string;
constructor() {}
}
import {VipProductDelivery} from "./vip-product-delivery.model";
/**
* Created by tuukka on 04/02/17.
*/
export class VipProduct {
/*
public Integer id;
public String name;
public Integer productId;
public String notes;
public BigDecimal quantity;
public BigDecimal delivered;
public List<VipProductDeliveryPojo> deliveries = new ArrayList<>();
*/
id: number;
name: string;
productId: number;
notes: string;
quantity: number;
delivered: number;
deliveries : VipProductDelivery[];
constructor() {}
}
import {VipProduct} from "./vip-product.model";
/**
* Created by tuukka on 04/02/17.
*/
export class Vip {
/*
public Integer id;
public String description;
public String shortdescr;
public Date created;
public Integer eventuserId;
public Integer creatorId;
public Integer hostId;
public List<VipProductPojo> products = new ArrayList<>();
*/
id: number;
description: string;
shortdescr: string;
created: Date;
eventuserId: number;
creatorId: number;
hostId: number;
products: VipProduct[];
constructor() {}
}
import {NgModule, ModuleWithProviders} from '@angular/core';
import { CommonModule } from '@angular/common';
import {HttpModule} from "@angular/http";
import {MoyaRestService} from "./services/moya-rest.service";
import {ViplistService} from "./services/viplist.service";
@NgModule({
imports: [
CommonModule,
HttpModule
],
declarations: []
})
export class MoyaRestModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: MoyaRestModule,
providers: [
MoyaRestService,
ViplistService
]
};
}
}
/* tslint:disable:no-unused-variable */
import { TestBed, async, inject } from '@angular/core/testing';
import { MoyaRestService } from './moya-rest.service';
describe('MoyaRestService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [MoyaRestService]
});
});
it('should ...', inject([MoyaRestService], (service: MoyaRestService) => {
expect(service).toBeTruthy();
}));
});
import { Injectable } from '@angular/core';
import {Http, Response} from "@angular/http";
import {Observable} from "rxjs";
@Injectable()
export class MoyaRestService {
constructor(private http: Http) { }
post(subUrl: string, body: any, pathParameters?: Map<string, string>): Observable<Response> {
return this.http.post(this.genUrl(subUrl, pathParameters), body)
.map(this.handleResponse)
.catch(this.handleException);
}
put(subUrl: string, body: any, pathParameters?: Map<string, string>): Observable<Response> {
return this.http.put(this.genUrl(subUrl, pathParameters), body)
.map(this.handleResponse)
.catch(this.handleException);
}
delete(subUrl: string, pathParameters?: Map<string, string>): Observable<Response> {
return this.http.delete(this.genUrl(subUrl, pathParameters))
.map(this.handleResponse)
.catch(this.handleException);
}
get(subUrl: string, pathParameters?: Map<string, string>): Observable<Response> {
return this.http.get(this.genUrl(subUrl, pathParameters))
.map(this.handleResponse)
.catch(this.handleException);
}
private 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
}
private handleResponse(res: Response) {
// basicly, 200 statuscodes means success
if(!(res.status >= 200 && res.status <= 299 )) {
console.log("statuscode not between 200 and 299", res.status);
// next stop: handlerException
throw res; // <-- javakoodarin aivot nyrjähtivät juuri ympäri
}
return res;
}
private handleException(error: Response | any) {
console.log("error on jira rest connection", error);
// TODO: add handlers to 403's and other "not logged in" or "invalid permissions" -statuscodes, and route them using some nice global parameter
return Observable.throw(error);
}
}
/* tslint:disable:no-unused-variable */
import { TestBed, async, inject } from '@angular/core/testing';
import { ViplistService } from './viplist.service';
describe('ViplistService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ViplistService]
});
});
it('should ...', inject([ViplistService], (service: ViplistService) => {
expect(service).toBeTruthy();
}));
});
import {Injectable} from '@angular/core';
import {MoyaRestService} from "./moya-rest.service";
import {Observable} from "rxjs";
import {Vip} from "../models/vip.model";
import {Response} from "@angular/http";
@Injectable()
export class ViplistService {
constructor(private moyaRestService: MoyaRestService) {
}
/**
* get vips
* @param searchString: searchString, skip to return all vips
*/
public get(searchString?: string): Observable<Array<Vip>> {
if (!searchString) {
return this.moyaRestService.get("v2/vip/all")
.map(v => v.json());
}
return this.moyaRestService.get("v2/vip/search/" + searchString)
.map(v => v.json());
}
/**
* Delete vip.
*
* @param vip
* @return Observable
*/
public async delete(vip: Vip): Promise<boolean> {
if (!vip.id)
throw new Error("TODO: errori, tyhmä vippi");
let res: Response = await this.moyaRestService.delete("v2/vip/" + vip.id)
.first()
.toPromise();
return res.ok;
}
public getWithId(id: number): Observable<Vip> {
return this.moyaRestService.get("v2/vip/" + id)
.map(v => v.json());
}
public create(vip: Vip): Observable<Vip> {
return this.moyaRestService.post("v2/vip/create", vip)
.map(v => v.json());
}
}
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { TestComponent } from './test.component';
describe('TestComponent', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TestComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!