From f89589d0dba057ab6aa179f307801572e51b32a6 Mon Sep 17 00:00:00 2001 From: Darko Luketic <2694548+dalu@users.noreply.github.com> Date: Tue, 3 Apr 2018 22:11:59 +0200 Subject: [PATCH] added time --- angular/.angular-cli.json | 3 +-- angular/src/_variables.scss | 1 + angular/src/app/app.component.ts | 2 +- angular/src/app/app.module.ts | 32 +++++++++++++++++++++++--------- angular/src/styles.scss | 4 +++- api/handler/data.go | 23 +++++++++++++++++++++++ api/repo/data.go | 16 ++++++++++++++++ model/data.go | 7 ++++++- 8 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 angular/src/_variables.scss diff --git a/angular/.angular-cli.json b/angular/.angular-cli.json index 497ac5b..e98e3e1 100644 --- a/angular/.angular-cli.json +++ b/angular/.angular-cli.json @@ -20,8 +20,7 @@ "prefix": "icod", "styles": [ "styles.scss", - "../node_modules/font-awesome/css/font-awesome.min.css", - "../node_modules/primeng/resources/themes/omega/theme.css", + "../node_modules/primeng/resources/themes/darkness/theme.css", "../node_modules/primeng/resources/primeng.min.css" ], "scripts": [], diff --git a/angular/src/_variables.scss b/angular/src/_variables.scss new file mode 100644 index 0000000..26c100d --- /dev/null +++ b/angular/src/_variables.scss @@ -0,0 +1 @@ +$fa-font-path : '../node_modules/font-awesome/fonts'; diff --git a/angular/src/app/app.component.ts b/angular/src/app/app.component.ts index 58f633c..75b7873 100644 --- a/angular/src/app/app.component.ts +++ b/angular/src/app/app.component.ts @@ -6,5 +6,5 @@ import { Component } from '@angular/core'; styleUrls: ['./app.component.scss'] }) export class AppComponent { - title = 'icod'; + } diff --git a/angular/src/app/app.module.ts b/angular/src/app/app.module.ts index 8936daa..bb76d1e 100644 --- a/angular/src/app/app.module.ts +++ b/angular/src/app/app.module.ts @@ -1,23 +1,37 @@ -import { BrowserModule } from '@angular/platform-browser'; -import { NgModule } from '@angular/core'; +import {BrowserModule} from '@angular/platform-browser'; +import {NgModule} from '@angular/core'; -import { AppRoutingModule } from './app-routing.module'; +import {AppRoutingModule} from './app-routing.module'; -import { ServiceWorkerModule } from '@angular/service-worker'; -import { AppComponent } from './app.component'; +import {ServiceWorkerModule} from '@angular/service-worker'; +import {AppComponent} from './app.component'; -import { environment } from '../environments/environment'; +import {environment} from '../environments/environment'; +import {FormsModule} from '@angular/forms'; +import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; +import {HttpClientModule} from '@angular/common/http'; +import {SplitButtonModule, ToolbarModule} from 'primeng/primeng'; +import {MenuModule} from 'primeng/menu'; +import { DataComponent } from './components/data/data.component'; @NgModule({ declarations: [ - AppComponent + AppComponent, + DataComponent ], imports: [ BrowserModule, AppRoutingModule, - ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }) + ServiceWorkerModule.register('/ngsw-worker.js', {enabled: environment.production}), + FormsModule, + BrowserAnimationsModule, + HttpClientModule, + ToolbarModule, + SplitButtonModule, + MenuModule, ], providers: [], bootstrap: [AppComponent] }) -export class AppModule { } +export class AppModule { +} diff --git a/angular/src/styles.scss b/angular/src/styles.scss index 19b0ca9..2cc48cf 100644 --- a/angular/src/styles.scss +++ b/angular/src/styles.scss @@ -1 +1,3 @@ -@import "~bootstrap/scss/bootstrap"; +/*@import "~bootstrap/scss/bootstrap";*/ +@import "variables"; +@import "~font-awesome/scss/font-awesome"; diff --git a/api/handler/data.go b/api/handler/data.go index 1d85dce..5635158 100644 --- a/api/handler/data.go +++ b/api/handler/data.go @@ -3,6 +3,8 @@ package handler import ( "strconv" + "time" + "git.icod.de/dalu/refdata/api/repo" "git.icod.de/dalu/refdata/model" "github.com/gin-gonic/gin" @@ -57,6 +59,7 @@ func (h *Handler) ListData(cx *gin.Context) { age := cx.Query("age") price := cx.Query("price") enabled := cx.Query("enabled") + when := cx.Query("when") // string if name == "1" { @@ -109,6 +112,7 @@ func (h *Handler) ListData(cx *gin.Context) { if price == "1" { p.Price = true p.PriceQuery = repo.DataPriceQuery{} + p.PriceQuery.Operation = cx.Query("price.operation") from, e := strconv.ParseFloat(cx.Query("age.from"), 64) if e != nil { cx.AbortWithStatus(400) @@ -136,6 +140,25 @@ func (h *Handler) ListData(cx *gin.Context) { } } + // time + if when == "1" { + p.When = true + p.WhenQuery = repo.DataWhenQuery{} + p.WhenQuery.Operation = cx.Query("when.operation") + from, e := time.Parse(time.RFC3339, cx.Query("when.from")) + if e != nil { + cx.AbortWithStatus(400) + return + } + to, e := time.Parse(time.RFC3339, cx.Query("when.to")) + if e != nil { + cx.AbortWithStatus(400) + return + } + p.WhenQuery.From = from + p.WhenQuery.To = to + } + m, e := h.dataRepo.List(p) if e != nil { cx.AbortWithError(500, e) diff --git a/api/repo/data.go b/api/repo/data.go index f494ff0..a61ee5a 100644 --- a/api/repo/data.go +++ b/api/repo/data.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" + "time" + "git.icod.de/dalu/refdata/model" "github.com/globalsign/mgo" "github.com/globalsign/mgo/bson" @@ -54,6 +56,18 @@ type DataEnabledQuery struct { Query bool } +// refid +type DataRefIdQuery struct { + Query string +} + +// time +type DataWhenQuery struct { + Operation string + From time.Time + To time.Time +} + type DataParams struct { Start int // list only Limit int // list only @@ -66,6 +80,7 @@ type DataParams struct { Age bool Price bool Enabled bool + When bool IdQuery DataIdQuery // get only NameQuery DataNameQuery @@ -74,6 +89,7 @@ type DataParams struct { AgeQuery DataAgeQuery PriceQuery DataPriceQuery EnabledQuery DataEnabledQuery + WhenQuery DataWhenQuery } type DataRepository struct { diff --git a/model/data.go b/model/data.go index 13c10a4..2af78e8 100644 --- a/model/data.go +++ b/model/data.go @@ -1,6 +1,10 @@ package model -import "github.com/globalsign/mgo/bson" +import ( + "time" + + "github.com/globalsign/mgo/bson" +) type Data struct { Id bson.ObjectId `bson:"_id,omitempty" json:"id"` @@ -9,4 +13,5 @@ type Data struct { Location string `bson:"location" json:"location"` Age float64 `bson:"age,omitempty" json:"age,omitempty"` Price float64 `bson:"price,omitempty" json:"price,omitempty"` + When time.Time `bson:"when" json:"when"` }