Merge pull request #4 from txgruppi/get-org-account

Added GET /orgs/:orgId/accounts/:accountI API endpoint
This commit is contained in:
Patrick Nagurny
2019-04-01 12:21:29 -04:00
committed by GitHub
14 changed files with 266 additions and 71 deletions

93
.gitignore vendored
View File

@@ -1,3 +1,96 @@
# Created by https://www.gitignore.io/api/vim,linux,macos,windows
# Edit at https://www.gitignore.io/?templates=vim,linux,macos,windows
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/vim,linux,macos,windows
### Custom ###
config.json
*.crt
*.key

View File

@@ -2,23 +2,24 @@ package api
import (
"encoding/json"
"github.com/ant0ine/go-json-rest/rest"
"github.com/openaccounting/oa-server/core/model"
"github.com/openaccounting/oa-server/core/model/types"
"io/ioutil"
"net/http"
"strconv"
"time"
"github.com/ant0ine/go-json-rest/rest"
"github.com/openaccounting/oa-server/core/model"
"github.com/openaccounting/oa-server/core/model/types"
)
/**
* @api {get} /orgs/:orgId/accounts Get Accounts by Org id
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetOrgAccounts
* @apiGroup Account
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the Account.
* @apiSuccess {String} orgId Id of the Org.
@@ -83,14 +84,85 @@ func GetOrgAccounts(w rest.ResponseWriter, r *rest.Request) {
w.WriteJson(&accounts)
}
/**
* @api {get} /orgs/:orgId/accounts/:accountId Get Acount by Org id and Account id
* @apiVersion 1.2.0
* @apiName GetOrgAccount
* @apiGroup Account
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the Account.
* @apiSuccess {String} orgId Id of the Org.
* @apiSuccess {Date} inserted Date Account was created
* @apiSuccess {Date} updated Date Account was updated
* @apiSuccess {String} name Name of the Account.
* @apiSuccess {String} parent Id of the parent Account.
* @apiSuccess {String} currency Three letter currency code.
* @apiSuccess {Number} precision How many digits the currency goes out to.
* @apiSuccess {Boolean} debitBalance True if Account has a debit balance.
* @apiSuccess {Number} balance Current Account balance in this Account's currency
* @apiSuccess {Number} nativeBalance Current Account balance in the Org's currency
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "id": "22222222222222222222222222222222",
* "orgId": "11111111111111111111111111111111",
* "inserted": "2018-09-11T18:05:04.420Z",
* "updated": "2018-09-11T18:05:04.420Z",
* "name": "Cash",
* "parent": "11111111111111111111111111111111",
* "currency": "USD",
* "precision": 2,
* "debitBalance": true,
* "balance": 10000,
* "nativeBalance": 10000
* }
*
* @apiUse NotAuthorizedError
* @apiUse InternalServerError
*/
func GetOrgAccount(w rest.ResponseWriter, r *rest.Request) {
user := r.Env["USER"].(*types.User)
orgId := r.PathParam("orgId")
accountId := r.PathParam("accountId")
// TODO how do we make date an optional parameter
// instead of resorting to this hack?
date := time.Date(2100, time.January, 1, 0, 0, 0, 0, time.UTC)
dateParam := r.URL.Query().Get("date")
if dateParam != "" {
dateParamNumeric, err := strconv.ParseInt(dateParam, 10, 64)
if err != nil {
rest.Error(w, "invalid date", 400)
return
}
date = time.Unix(0, dateParamNumeric*1000000)
}
accounts, err := model.Instance.GetAccountWithBalance(orgId, accountId, user.Id, "", date)
if err != nil {
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteJson(&accounts)
}
/**
* @api {post} /orgs/:orgId/accounts Create a new Account
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PostAccount
* @apiGroup Account
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} id Id 32 character hex string
* @apiParam {String} name Name of the Account.
@@ -198,12 +270,12 @@ func PostAccounts(w rest.ResponseWriter, r *rest.Request, content []byte) {
/**
* @api {put} /orgs/:orgId/accounts/:accountId Modify an Account
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PutAccount
* @apiGroup Account
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} id Id 32 character hex string
* @apiParam {String} name Name of the Account.
@@ -273,12 +345,12 @@ func PutAccount(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {delete} /orgs/:orgId/accounts/:accountId Delete an Account
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName DeleteAccount
* @apiGroup Account
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK

View File

@@ -7,6 +7,9 @@ import (
/**
* Changelog
*
* 1.2.0
* - add `GET /orgs/:orgId/accounts/:accountId
*
* 1.1.0
* - add `GET /health-check`
*

View File

@@ -9,12 +9,12 @@ import (
/**
* @api {get} /apikeys Get API keys
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetApiKeys
* @apiGroup ApiKey
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the ApiKey.
* @apiSuccess {Date} inserted Date ApiKey was created
@@ -52,11 +52,11 @@ func GetApiKeys(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {post} /apikeys Create a new API key
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PostApiKey
* @apiGroup ApiKey
*
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
* @apiHeader {String} Authorization HTTP Basic Auth
*
* @apiParam {String} id 32 character hex string
@@ -105,11 +105,11 @@ func PostApiKey(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {put} /apikeys Modify an API key
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PutApiKey
* @apiGroup ApiKey
*
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
* @apiHeader {String} Authorization HTTP Basic Auth
*
* @apiParam {String} id 32 character hex string
@@ -160,12 +160,12 @@ func PutApiKey(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {delete} /apikeys/:apiKeyId Delete an API key
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName DeleteApiKey
* @apiGroup ApiKey
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK

View File

@@ -9,12 +9,12 @@ import (
/**
* @api {get} /org/:orgId Get Org by id
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetOrg
* @apiGroup Org
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the Org.
* @apiSuccess {Date} inserted Date Org was created
@@ -53,12 +53,12 @@ func GetOrg(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {get} /orgs Get a User's Orgs
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetOrgs
* @apiGroup Org
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the Org.
* @apiSuccess {Date} inserted Date Org was created
@@ -98,12 +98,12 @@ func GetOrgs(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {post} /orgs Create a new Org
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PostOrg
* @apiGroup Org
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} id Id 32 character hex string
* @apiParam {String} name Name of the Org.
@@ -152,12 +152,12 @@ func PostOrg(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {put} /orgs/:orgId Modify an Org
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PutOrg
* @apiGroup Org
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} name Name of the Org.
*
@@ -207,12 +207,12 @@ func PutOrg(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {post} /orgs/:orgId/invites Invite a user to an Org
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PostInvite
* @apiGroup Org
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} email Email address of user
*
@@ -263,12 +263,12 @@ func PostInvite(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {put} /orgs/:orgId/invites/:inviteId Accept an invitation
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PutInvite
* @apiGroup Org
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} accepted true
*
@@ -320,12 +320,12 @@ func PutInvite(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {get} /orgs/:orgId/invites Get Org invites
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetInvites
* @apiGroup Org
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the Invite
* @apiSuccess {orgId} id Id of the Org
@@ -366,12 +366,12 @@ func GetInvites(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {delete} /orgs/:orgId/invites/:inviteId Delete Invite
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName DeleteInvite
* @apiGroup Org
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK

View File

@@ -11,12 +11,12 @@ import (
/**
* @api {get} /org/:orgId/prices Get prices nearest in time or by currency
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetPrices
* @apiGroup Price
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {Number} nearestDate Milliseconds since epoch
* @apiParam {String} currency Currency code
@@ -93,12 +93,12 @@ func GetPrices(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {post} /orgs/:orgId/prices Create a new Price
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PostPrice
* @apiGroup Price
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} id Id 32 character hex string.
* @apiParam {String} orgId Id of the Org.
@@ -155,12 +155,12 @@ func PostPrice(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {delete} /orgs/:orgId/prices/:priceId Delete a Price
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName DeletePrice
* @apiGroup Price
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK

View File

@@ -22,6 +22,7 @@ func GetRouter(auth *AuthMiddleware, prefix string) (rest.App, error) {
rest.Delete(prefix+"/orgs/:orgId/ledgers/:accountId", auth.RequireAuth(DeleteAccount)),
rest.Get(prefix+"/orgs/:orgId/ledgers/:accountId/transactions", auth.RequireAuth(GetTransactionsByAccount)),
rest.Get(prefix+"/orgs/:orgId/accounts", auth.RequireAuth(GetOrgAccounts)),
rest.Get(prefix+"/orgs/:orgId/accounts/:accountId", auth.RequireAuth(GetOrgAccount)),
rest.Post(prefix+"/orgs/:orgId/accounts", auth.RequireAuth(PostAccount)),
rest.Put(prefix+"/orgs/:orgId/accounts/:accountId", auth.RequireAuth(PutAccount)),
rest.Delete(prefix+"/orgs/:orgId/accounts/:accountId", auth.RequireAuth(DeleteAccount)),

View File

@@ -9,11 +9,11 @@ import (
/**
* @api {post} /sessions Create a new Session
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PostSession
* @apiGroup Session
*
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
* @apiHeader {String} Authorization HTTP Basic Auth
*
* @apiParam {String} id 32 character hex string
@@ -59,12 +59,12 @@ func PostSession(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {delete} /sessions/:sessionId Log out of a Session
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName DeleteSession
* @apiGroup Session
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK

View File

@@ -7,12 +7,12 @@ import (
/**
* @api {get} /health-check Get system health status
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetSystemHealthStatus
* @apiGroup SystemHealth
*
*
* @apiHeader {String} Accept-Version: 1.1.0 semver versioning
* @apiHeader {String} Accept-Version: 1.2.0 semver versioning
*
* @apiSuccess {String} database Database status: "ok"; "fail"
* @apiSuccess {String} api API status: "ok"

View File

@@ -9,12 +9,12 @@ import (
/**
* @api {get} /orgs/:orgId/accounts/:accountId/transactions Get Transactions by Account Id
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetAccountTransactions
* @apiGroup Transaction
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the Transaction.
* @apiSuccess {String} orgId Id of the Org.
@@ -85,12 +85,12 @@ func GetTransactionsByAccount(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {get} /orgs/:orgId/transactions Get Transactions by Org Id
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetOrgTransactions
* @apiGroup Transaction
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the Transaction.
* @apiSuccess {String} orgId Id of the Org.
@@ -160,12 +160,12 @@ func GetTransactionsByOrg(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {post} /orgs/:orgId/transactions Create a new Transaction
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PostTransaction
* @apiGroup Transaction
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} id Id 32 character hex string
* @apiParam {Date} date Date of the Transaction
@@ -246,12 +246,12 @@ func PostTransaction(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {put} /orgs/:orgId/transactions/:transactionId Modify a Transaction
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PutTransaction
* @apiGroup Transaction
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} id 32 character hex string
* @apiParam {Date} date Date of the Transaction
@@ -333,12 +333,12 @@ func PutTransaction(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {delete} /orgs/:orgId/transactions/:transactionId Delete a Transaction
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName DeleteTransaction
* @apiGroup Transaction
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK

View File

@@ -22,12 +22,12 @@ type ResetPasswordParams struct {
/**
* @api {get} /user Get Authenticated User
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName GetUser
* @apiGroup User
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiSuccess {String} id Id of the User.
* @apiSuccess {Date} inserted Date User was created
@@ -64,11 +64,11 @@ func GetUser(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {post} /users Create a new User
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PostUser
* @apiGroup User
*
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} id 32 character hex string
* @apiParam {String} firstName First name of the User.
@@ -123,12 +123,12 @@ func PostUser(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {put} /user Modify User
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName PutUser
* @apiGroup User
*
* @apiHeader {String} Authorization HTTP Basic Auth
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} password New password
* @apiParam {String} code Password reset code. (Instead of Authorization header)
@@ -204,11 +204,11 @@ func PutUser(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {post} /user/verify Verify user email address
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName VerifyUser
* @apiGroup User
*
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} code Email verification code
*
@@ -238,11 +238,11 @@ func VerifyUser(w rest.ResponseWriter, r *rest.Request) {
/**
* @api {post} /user/reset-password Send reset password email
* @apiVersion 1.1.0
* @apiVersion 1.2.0
* @apiName ResetPassword
* @apiGroup User
*
* @apiHeader {String} Accept-Version ^1.1.0 semver versioning
* @apiHeader {String} Accept-Version ^1.2.0 semver versioning
*
* @apiParam {String} email Email address for user
*

View File

@@ -31,7 +31,7 @@ func (mw *VersionMiddleware) MiddlewareFunc(handler rest.HandlerFunc) rest.Handl
rest.Error(writer, "Invalid version", http.StatusBadRequest)
}
serverVersion, _ := semver.NewVersion("1.1.0")
serverVersion, _ := semver.NewVersion("1.2.0")
// Pre-release versions
compatVersion, _ := semver.NewVersion("0.1.8")

View File

@@ -3,10 +3,11 @@ package model
import (
"errors"
"fmt"
"github.com/openaccounting/oa-server/core/model/types"
"github.com/openaccounting/oa-server/core/ws"
"sort"
"time"
"github.com/openaccounting/oa-server/core/model/types"
"github.com/openaccounting/oa-server/core/ws"
)
type AccountInterface interface {
@@ -15,6 +16,8 @@ type AccountInterface interface {
DeleteAccount(id string, userId string, orgId string) error
GetAccounts(orgId string, userId string, tokenId string) ([]*types.Account, error)
GetAccountsWithBalances(orgId string, userId string, tokenId string, date time.Time) ([]*types.Account, error)
GetAccount(orgId, accId, userId, tokenId string) (*types.Account, error)
GetAccountWithBalance(orgId, accId, userId, tokenId string, date time.Time) (*types.Account, error)
}
type ByName []*types.Account
@@ -253,6 +256,21 @@ func (model *Model) getAccounts(orgId string, userId string, tokenId string, dat
return filtered, nil
}
func (model *Model) getAccount(orgId, accId, userId, tokenId string, date time.Time, withBalances bool) (*types.Account, error) {
accounts, err := model.getAccounts(orgId, userId, tokenId, date, withBalances)
if err != nil {
return nil, err
}
for _, account := range accounts {
if account.Id == accId {
return account, nil
}
}
return nil, nil
}
func (model *Model) GetAccounts(orgId string, userId string, tokenId string) ([]*types.Account, error) {
return model.getAccounts(orgId, userId, tokenId, time.Time{}, false)
}
@@ -261,6 +279,14 @@ func (model *Model) GetAccountsWithBalances(orgId string, userId string, tokenId
return model.getAccounts(orgId, userId, tokenId, date, true)
}
func (model *Model) GetAccount(orgId, accId, userId, tokenId string) (*types.Account, error) {
return model.getAccount(orgId, accId, userId, tokenId, time.Time{}, false)
}
func (model *Model) GetAccountWithBalance(orgId, accId, userId, tokenId string, date time.Time) (*types.Account, error) {
return model.getAccount(orgId, accId, userId, tokenId, date, true)
}
func (model *Model) getAllAccounts(orgId string) ([]*types.Account, error) {
return model.db.GetAccountsByOrgId(orgId)
}

View File

@@ -14,7 +14,7 @@ import (
"sync"
)
const version = "1.1.0"
const version = "1.2.0"
//var upgrader = websocket.Upgrader{} // use default options
var txSubscriptions = make(map[string][]*websocket.Conn)