Skip to content

Commit

Permalink
#21 Add basic contents page
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rauh committed May 3, 2023
1 parent beec520 commit 357297e
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 81 deletions.
3 changes: 2 additions & 1 deletion Dockerfile-debug
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM docker.io/golang:1.20 AS build
WORKDIR /go/src
COPY cmd/mb3server/src ./cmd/mb3server/src
COPY cmd/mb3server/main.go ./cmd/mb3server
COPY pkg ./pkg
COPY go.mod .

ENV CGO_ENABLED=0
Expand All @@ -16,5 +17,5 @@ VOLUME /var/log
COPY --from=build /go/src/mb3server ./
COPY --from=build /go/bin/dlv /
EXPOSE 8080/tcp 40000
CMD ["/dlv", "--log", "--log-dest", "/var/log/delve.log", "--log-output", "rpc","--listen=:40000", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "./mb3server"]
CMD ["/dlv", "--log", "--log-dest", "/var/log/delve.log", "--log-output", "debugger","--listen=:40000", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "./mb3server"]

16 changes: 8 additions & 8 deletions api/schemas/FilterOptions.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
components:
schemas:
StringCount:
type: object
properties:
values:
type: array
items:
type: array
items:
type: object
properties:
value:
type: string
count:
type: integer
minimum: 0
count:
type: integer
minimum: 0
FilterOptions:
type: object
properties:
Expand Down
3 changes: 1 addition & 2 deletions cmd/mb3server/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ api/openapi.yaml
main.go
src/api.go
src/api_default.go
src/api_default_service.go
src/error.go
src/helpers.go
src/impl.go
Expand Down Expand Up @@ -38,5 +37,5 @@ src/model_ms_focused_ion_inner.go
src/model_search_result.go
src/model_search_result_data_inner.go
src/model_search_result_data_inner_spectra_inner.go
src/model_string_count.go
src/model_string_count_inner.go
src/routers.go
2 changes: 1 addition & 1 deletion cmd/mb3server/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.0
6.5.0
86 changes: 48 additions & 38 deletions cmd/mb3server/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -594,59 +594,58 @@ components:
result_count: 0
timestamp: timestamp
compound_start:
values:
- values
- values
count: 0
- count: 0
value: value
- count: 0
value: value
contributor:
values:
- values
- values
count: 0
- count: 0
value: value
- count: 0
value: value
ms_type:
values:
- values
- values
count: 0
- count: 0
value: value
- count: 0
value: value
ion_mode:
values:
- values
- values
count: 0
- count: 0
value: value
- count: 0
value: value
instrument_type:
values:
- values
- values
count: 0
- count: 0
value: value
- count: 0
value: value
properties:
metadata:
$ref: '#/components/schemas/Metadata'
contributor:
$ref: '#/components/schemas/StringCount'
items:
$ref: '#/components/schemas/StringCount_inner'
type: array
instrument_type:
$ref: '#/components/schemas/StringCount'
items:
$ref: '#/components/schemas/StringCount_inner'
type: array
ms_type:
$ref: '#/components/schemas/StringCount'
items:
$ref: '#/components/schemas/StringCount_inner'
type: array
ion_mode:
$ref: '#/components/schemas/StringCount'
items:
$ref: '#/components/schemas/StringCount_inner'
type: array
compound_start:
$ref: '#/components/schemas/StringCount'
type: object
StringCount:
example:
values:
- values
- values
count: 0
properties:
values:
items:
type: string
$ref: '#/components/schemas/StringCount_inner'
type: array
count:
minimum: 0
type: integer
type: object
StringCount:
items:
$ref: '#/components/schemas/StringCount_inner'
type: array
Authors:
items:
$ref: '#/components/schemas/Authors_inner'
Expand Down Expand Up @@ -1154,6 +1153,17 @@ components:
default: 100
type: integer
type: object
StringCount_inner:
example:
count: 0
value: value
properties:
value:
type: string
count:
minimum: 0
type: integer
type: object
Authors_inner:
description: Name of the author or affiliation
example:
Expand Down
4 changes: 3 additions & 1 deletion cmd/mb3server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ package main
import (
"log"
"net/http"
"time"

mb3server "github.com/MassBank/MassBank3/cmd/mb3server/src"
)

func main() {
log.Printf("Server started")

time.Sleep(5 * time.Second)
log.Printf("Server started 5")
DefaultApiService := mb3server.NewDefaultApiService()
DefaultApiController := mb3server.NewDefaultApiController(DefaultApiService)

Expand Down
81 changes: 81 additions & 0 deletions cmd/mb3server/src/api-impl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package mb3server

import (
"github.com/MassBank/MassBank3/pkg/database"
"log"
"os"
)

var db database.MB3Database = nil

func initDB() error {
if db == nil {
var mongo_uri = os.Getenv("MONGO_URI")
var mongo_name = os.Getenv("MONGO_DB_NAME")
log.Println("MongoDB URI: ", mongo_uri)
log.Println("Database_Name", mongo_name)
var err error = nil
var config = database.DBConfig{
Database: database.MongoDB,
DbUser: "",
DbPwd: "",
DbHost: "",
DbName: os.Getenv("MONGO_DB_NAME"),
DbPort: 0,
DbConnStr: os.Getenv("MONGO_URI"),
}

db, err = database.NewMongoDB(config)
if err != nil {
return err
}
err = db.Connect()
if err != nil {
return err
}
}
return db.Ping()

}

func GetBrowseOptions() (*BrowseOptions, error) {
if err := initDB(); err != nil {
return nil, err
}
vals, err := db.GetUniqueValues(database.Filters{})
if err != nil {
return nil, err
}
var result = BrowseOptions{}
result.Metadata = Metadata{
Version: "",
Timestamp: "",
GitCommit: "",
SpectraCount: 0,
CompoundCount: 0,
IsomerCount: 0,
ResultCount: 0,
Page: 0,
Limit: 0,
}
for _, val := range vals.IonMode {
result.IonMode = append(result.IonMode, StringCountInner{
Value: val.Val,
Count: int32(val.Count),
})
}
for _, val := range vals.MSType {
result.MsType = append(result.MsType, StringCountInner{
Value: val.Val,
Count: int32(val.Count),
})
}
for _, val := range vals.InstrumentType {
result.InstrumentType = append(result.InstrumentType, StringCountInner{
Value: val.Val,
Count: int32(val.Count),
})
}

return &result, nil
}
22 changes: 10 additions & 12 deletions cmd/mb3server/src/api_default_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,22 @@ func NewDefaultApiService() DefaultApiServicer {

// GetBrowseOptions - get browse options
func (s *DefaultApiService) GetBrowseOptions(ctx context.Context) (ImplResponse, error) {
// TODO - update GetBrowseOptions with the required logic for this service method.
// Add api_default_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.

//TODO: Uncomment the next line to return response Response(200, BrowseOptions{}) or use other options such as http.Ok ...
//return Response(200, BrowseOptions{}), nil

return Response(http.StatusNotImplemented, nil), errors.New("GetBrowseOptions method not implemented")
opt, err := GetBrowseOptions()
if err != nil {
return Response(http.StatusInternalServerError, nil), errors.New("Could not get results")
}
return Response(http.StatusOK, opt), nil
}

// GetFilterOptions - get filter options
func (s *DefaultApiService) GetFilterOptions(ctx context.Context) (ImplResponse, error) {
// TODO - update GetFilterOptions with the required logic for this service method.
// Add api_default_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.

//TODO: Uncomment the next line to return response Response(200, FilterOptions{}) or use other options such as http.Ok ...
//return Response(200, FilterOptions{}), nil
opt, err := GetBrowseOptions()
if err != nil {
return Response(http.StatusInternalServerError, nil), errors.New("Could not get results")
}
return Response(http.StatusOK, opt), nil

return Response(http.StatusNotImplemented, nil), errors.New("GetFilterOptions method not implemented")
}

// GetMetadata - get massbank metadata
Expand Down
40 changes: 25 additions & 15 deletions cmd/mb3server/src/model_browse_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,46 @@ package mb3server
type BrowseOptions struct {
Metadata Metadata `json:"metadata,omitempty"`

Contributor StringCount `json:"contributor,omitempty"`
Contributor []StringCountInner `json:"contributor,omitempty"`

InstrumentType StringCount `json:"instrument_type,omitempty"`
InstrumentType []StringCountInner `json:"instrument_type,omitempty"`

MsType StringCount `json:"ms_type,omitempty"`
MsType []StringCountInner `json:"ms_type,omitempty"`

IonMode StringCount `json:"ion_mode,omitempty"`
IonMode []StringCountInner `json:"ion_mode,omitempty"`

CompoundStart StringCount `json:"compound_start,omitempty"`
CompoundStart []StringCountInner `json:"compound_start,omitempty"`
}

// AssertBrowseOptionsRequired checks if the required fields are not zero-ed
func AssertBrowseOptionsRequired(obj BrowseOptions) error {
if err := AssertMetadataRequired(obj.Metadata); err != nil {
return err
}
if err := AssertStringCountRequired(obj.Contributor); err != nil {
return err
for _, el := range obj.Contributor {
if err := AssertStringCountInnerRequired(el); err != nil {
return err
}
}
if err := AssertStringCountRequired(obj.InstrumentType); err != nil {
return err
for _, el := range obj.InstrumentType {
if err := AssertStringCountInnerRequired(el); err != nil {
return err
}
}
if err := AssertStringCountRequired(obj.MsType); err != nil {
return err
for _, el := range obj.MsType {
if err := AssertStringCountInnerRequired(el); err != nil {
return err
}
}
if err := AssertStringCountRequired(obj.IonMode); err != nil {
return err
for _, el := range obj.IonMode {
if err := AssertStringCountInnerRequired(el); err != nil {
return err
}
}
if err := AssertStringCountRequired(obj.CompoundStart); err != nil {
return err
for _, el := range obj.CompoundStart {
if err := AssertStringCountInnerRequired(el); err != nil {
return err
}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mb3server/src/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func parseBoolParameter(param string, required bool) (bool, error) {
return false, err
}

return val, nil
return bool(val), nil
}

// parseInt64ArrayParameter parses a string parameter containing array of values to []int64.
Expand Down
4 changes: 3 additions & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ services:
ports:
- "${MB3_API_PORT}:8080"
environment:
MONGO_URI: "mongodb://${MONGODB_USER}:${MONGODB_PWD}@mongo:27017"
MONGO_URI: "mongodb://${MONGODB_USER}:${MONGODB_PWD}@mongodb:27017"
MONGO_DB_NAME: "massbank3"
depends_on:
- mongodb
- postgres

mb3frontend:
restart: always
environment:
VITE_SERVER_API_URL: "http://localhost:8081"
Loading

0 comments on commit 357297e

Please sign in to comment.