Using a new database root directory

This commit is contained in:
Eduard Urbach 2019-09-09 08:46:43 +09:00
parent 6bfe81fdc3
commit 8bfb1e0b4d
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
10 changed files with 36 additions and 13 deletions

View File

@ -21,7 +21,8 @@ cd notify.moe
go mod download go mod download
make tools make tools
make assets make assets
go build make server
make db
./notify.moe ./notify.moe
``` ```

View File

@ -17,7 +17,8 @@ cd notify.moe
go mod download go mod download
make tools make tools
make assets make assets
go build make server
make db
./notify.moe ./notify.moe
``` ```

View File

@ -1,6 +1,8 @@
package arn package arn
import ( import (
"path"
"github.com/aerogo/api" "github.com/aerogo/api"
"github.com/aerogo/nano" "github.com/aerogo/nano"
"github.com/animenotifier/kitsu" "github.com/animenotifier/kitsu"
@ -9,7 +11,8 @@ import (
// Node represents the database node. // Node represents the database node.
var Node = nano.New(nano.Configuration{ var Node = nano.New(nano.Configuration{
Port: 5000, Port: 5000,
Directory: path.Join(Root, "db"),
}) })
// DB is the main database client. // DB is the main database client.
@ -67,5 +70,5 @@ var Kitsu = Node.Namespace("kitsu").RegisterTypes(
(*kitsu.Character)(nil), (*kitsu.Character)(nil),
) )
// API ... // API is used to install the REST API.
var API = api.New("/api/", DB) var API = api.New("/api/", DB)

View File

@ -24,8 +24,8 @@ func NewDraftIndex(userID UserID) *DraftIndex {
} }
} }
// GetID gets the ID for the given type name. // DraftID gets the ID for the given type name.
func (index *DraftIndex) GetID(typeName string) (string, error) { func (index *DraftIndex) DraftID(typeName string) (string, error) {
v := reflect.ValueOf(index).Elem() v := reflect.ValueOf(index).Elem()
fieldValue := v.FieldByName(typeName + "ID") fieldValue := v.FieldByName(typeName + "ID")
@ -36,8 +36,8 @@ func (index *DraftIndex) GetID(typeName string) (string, error) {
return fieldValue.String(), nil return fieldValue.String(), nil
} }
// SetID sets the ID for the given type name. // SetDraftID sets the ID for the given type name.
func (index *DraftIndex) SetID(typeName string, id string) error { func (index *DraftIndex) SetDraftID(typeName string, id string) error {
v := reflect.ValueOf(index).Elem() v := reflect.ValueOf(index).Elem()
fieldValue := v.FieldByName(typeName + "ID") fieldValue := v.FieldByName(typeName + "ID")
@ -49,6 +49,11 @@ func (index *DraftIndex) SetID(typeName string, id string) error {
return nil return nil
} }
// GetID returns the ID.
func (index *DraftIndex) GetID() string {
return index.UserID
}
// GetDraftIndex ... // GetDraftIndex ...
func GetDraftIndex(id string) (*DraftIndex, error) { func GetDraftIndex(id string) (*DraftIndex, error) {
obj, err := DB.Get("DraftIndex", id) obj, err := DB.Get("DraftIndex", id)

View File

@ -4,7 +4,8 @@ import "github.com/aerogo/api"
// Force interface implementations // Force interface implementations
var ( var (
_ api.Savable = (*DraftIndex)(nil) _ Identifiable = (*DraftIndex)(nil)
_ api.Savable = (*DraftIndex)(nil)
) )
// Save saves the index in the database. // Save saves the index in the database.

View File

@ -78,7 +78,7 @@ func publish(draft Publishable) error {
return err return err
} }
currentDraftID, _ := draftIndex.GetID(typ.Name()) currentDraftID, _ := draftIndex.DraftID(typ.Name())
if currentDraftID != draft.GetID() { if currentDraftID != draft.GetID() {
return errors.New(typ.Name() + " draft doesn't exist in the user draft index") return errors.New(typ.Name() + " draft doesn't exist in the user draft index")
@ -86,7 +86,7 @@ func publish(draft Publishable) error {
// Publish the object // Publish the object
draft.SetIsDraft(false) draft.SetIsDraft(false)
err = draftIndex.SetID(typ.Name(), "") err = draftIndex.SetDraftID(typ.Name(), "")
if err != nil { if err != nil {
return err return err
@ -113,14 +113,14 @@ func unpublish(draft Publishable) error {
return err return err
} }
draftIndexID, _ := draftIndex.GetID(typ.Name()) draftIndexID, _ := draftIndex.DraftID(typ.Name())
if draftIndexID != "" { if draftIndexID != "" {
return errors.New("You still have an unfinished draft") return errors.New("You still have an unfinished draft")
} }
draft.SetIsDraft(true) draft.SetIsDraft(true)
err = draftIndex.SetID(typ.Name(), draft.GetID()) err = draftIndex.SetDraftID(typ.Name(), draft.GetID())
if err != nil { if err != nil {
return err return err

View File

@ -107,6 +107,11 @@ func (list *UserFollows) UsersWhoFollowBack() []*User {
return friends return friends
} }
// GetID returns the ID.
func (list *UserFollows) GetID() string {
return list.UserID
}
// UserFollowerCountMap returns a map of user ID keys and their corresping number of followers as the value. // UserFollowerCountMap returns a map of user ID keys and their corresping number of followers as the value.
func UserFollowerCountMap() map[string]int { func UserFollowerCountMap() map[string]int {
followCount := map[string]int{} followCount := map[string]int{}

View File

@ -7,6 +7,7 @@ import (
// Force interface implementations // Force interface implementations
var ( var (
_ Identifiable = (*UserFollows)(nil)
_ IDCollection = (*UserFollows)(nil) _ IDCollection = (*UserFollows)(nil)
_ api.Editable = (*UserFollows)(nil) _ api.Editable = (*UserFollows)(nil)
) )

View File

@ -83,6 +83,11 @@ func (list *UserNotifications) Notifications() []*Notification {
return notifications return notifications
} }
// GetID returns the ID.
func (list *UserNotifications) GetID() string {
return list.UserID
}
// GetUserNotifications ... // GetUserNotifications ...
func GetUserNotifications(id UserID) (*UserNotifications, error) { func GetUserNotifications(id UserID) (*UserNotifications, error) {
obj, err := DB.Get("UserNotifications", id) obj, err := DB.Get("UserNotifications", id)

View File

@ -2,6 +2,7 @@ package arn
// Force interface implementations // Force interface implementations
var ( var (
_ Identifiable = (*UserNotifications)(nil)
_ IDCollection = (*UserNotifications)(nil) _ IDCollection = (*UserNotifications)(nil)
) )