Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Commit c732954

Browse files
Feature/login UI and controller (#14)
2 parents a6c593f + bd32979 commit c732954

22 files changed

+678
-245
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
<div align="center">
2+
13
# 🦉Owlly
24

3-
[![wakatime](https://wakatime.com/badge/user/e56daee8-7aae-4b0e-814c-b6bb7f5f841c/project/c15254fd-0a5e-4b66-b897-5ed473191817.svg)](https://wakatime.com/badge/user/e56daee8-7aae-4b0e-814c-b6bb7f5f841c/project/c15254fd-0a5e-4b66-b897-5ed473191817) ![lint-and-format](https://github.com/asunlabs/owlly/actions/workflows/lint-and-format.yml/badge.svg) ![assign](https://github.com/asunlabs/owlly/actions/workflows/release.yml/badge.svg) ![GitHub last commit](https://img.shields.io/github/last-commit/asunlabs/owlly)
5+
[![wakatime](https://wakatime.com/badge/user/e56daee8-7aae-4b0e-814c-b6bb7f5f841c/project/c15254fd-0a5e-4b66-b897-5ed473191817.svg)](https://wakatime.com/badge/user/e56daee8-7aae-4b0e-814c-b6bb7f5f841c/project/c15254fd-0a5e-4b66-b897-5ed473191817) ![GitHub last commit](https://img.shields.io/github/last-commit/asunlabs/owlly) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
6+
7+
![lint-and-format](https://github.com/asunlabs/owlly/actions/workflows/lint-and-format.yml/badge.svg) ![assign](https://github.com/asunlabs/owlly/actions/workflows/release.yml/badge.svg)
48

59
A file-based .env change notifier for your slack team.
610

711
<img src="https://user-images.githubusercontent.com/83855174/202204929-9eff7a48-84bc-4673-b721-f3b81403ee83.gif" alt="demo" width="100%" />
812

13+
</div>
14+
915
## Table of Contents
1016

1117
- [Owlly](#owlly)

app.go

+8-39
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package main
22

33
import (
44
"context"
5-
"log"
6-
7-
"owlly/v2/core"
8-
9-
"github.com/asunlabs/owlly/config"
105
"github.com/fatih/color"
11-
"github.com/wailsapp/wails/v2/pkg/runtime"
6+
config "github.com/asunlabs/owlly/config"
7+
core "owlly/v2/core"
8+
// account "github.com/asunlabs/owlly/core/account"
9+
bot "owlly/v2/core/bot"
1210
)
1311

1412
// ==================================================================== //
@@ -46,7 +44,7 @@ func NewOwlly() *Owlly {
4644
return &Owlly{}
4745
}
4846

49-
// @dev set controller for Wails
47+
// @dev Go/Js binding
5048
func (o *Owlly) InitEnvBot() bool {
5149
if ok := core.InitEnvBot_(); ok {
5250
return true
@@ -55,43 +53,14 @@ func (o *Owlly) InitEnvBot() bool {
5553
return false
5654
}
5755

58-
// TODO split service(provider) and controller like Nestjs
5956
func (o *Owlly) CreateEnvBotConfig(botConfig config.ModelEnvBot) {
60-
config.CreateEnvBotConfig(botConfig)
57+
bot.CreateEnvBotConfig(botConfig)
6158
}
6259

6360
// ==================================================================== //
6461
// ======================= Wails event listener ======================= //
6562
// ==================================================================== //
6663
// @dev runtime context should be obtained from the OnStartup or OnDomReady hooks.
6764
func EventListener(ctx context.Context) {
68-
runtime.EventsOn(ctx, config.SLACK_EVENT["update"], func(optionalData ...interface{}) {
69-
_newConfig := make(map[int]string)
70-
71-
var newConfig config.ModelEnvBot
72-
73-
for k, v := range optionalData {
74-
switch _v := v.(type) {
75-
case string:
76-
_newConfig[k] = _v
77-
default:
78-
log.Fatal("app.go:EventListener: Invalid config data type")
79-
}
80-
}
81-
82-
newConfig.TriggerName = _newConfig[0]
83-
newConfig.SlackBotOauthToken = _newConfig[1]
84-
newConfig.SlackChannelID = _newConfig[2]
85-
newConfig.SlackUserID = _newConfig[3]
86-
newConfig.SlackUserName = _newConfig[4]
87-
88-
// Read config info from frontend and do DB operation
89-
config.New(
90-
newConfig.TriggerName,
91-
newConfig.SlackBotOauthToken,
92-
newConfig.SlackChannelID,
93-
newConfig.SlackUserID,
94-
newConfig.SlackUserName,
95-
)
96-
})
97-
}
65+
bot.HandleSlackUpdate(ctx)
66+
}

config/db.go

-104
This file was deleted.

config/model.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
type ModelEmailUser struct {
1313
gorm.Model
1414
Email string `gorm:"unique;not null" json:"email"`
15-
Password string `gorm:"not null" json:"password"`
16-
Username string `gorm:"not null" json:"username"`
15+
Password string `gorm:"not null" json:"password"`
16+
Username string `gorm:"not null" json:"username"`
1717
}
1818

1919
type ModelWalletUser struct {
@@ -23,10 +23,10 @@ type ModelWalletUser struct {
2323
}
2424

2525
type ModelEnvBot struct {
26-
gorm.Model
27-
TriggerName string `gorm:"not null" json:"triggerName"`
26+
gorm.Model
27+
TriggerName string `gorm:"not null" json:"triggerName"`
2828
SlackBotOauthToken string `gorm:"unique;not null" json:"slackBotOauthToken"`
29-
SlackChannelID string `gorm:"not null" json:"slackChannelID"`
30-
SlackUserID string `gorm:"not null" json:"slackUserID"`
31-
SlackUserName string `gorm:"not null" json:"slackUserName"`
29+
SlackChannelID string `gorm:"not null" json:"slackChannelID"`
30+
SlackUserID string `gorm:"not null" json:"slackUserID"`
31+
SlackUserName string `gorm:"not null" json:"slackUserName"`
3232
}

config/setup.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package config
22

33
import (
4-
"errors"
5-
64
"github.com/fatih/color"
5+
"gorm.io/driver/sqlite"
76
"gorm.io/gorm"
87
)
98

109
var (
11-
EnvBot *ModelEnvBot
10+
DB_HANDLE *gorm.DB
11+
EnvBot *ModelEnvBot
12+
DATABASE_NAME = "owlly.db"
1213
SLACK_EVENT = map[string]string{
1314
"update": "SLACK_UPDATE_EVENT",
1415
"delete": "SLACK_DELETE_EVENT",
@@ -20,6 +21,22 @@ var (
2021
}
2122
)
2223

24+
// ==================================================================== //
25+
// ========================= Init SQLite3 DB ========================== //
26+
// ==================================================================== //
27+
func ConnectDB() (bool, string) {
28+
_db, oErr := gorm.Open(sqlite.Open(DATABASE_NAME), &gorm.Config{})
29+
30+
if oErr != nil {
31+
return false, oErr.Error()
32+
}
33+
34+
_db.AutoMigrate(&ModelEmailUser{}, &ModelWalletUser{}, &ModelEnvBot{})
35+
DB_HANDLE = _db
36+
37+
return true, ""
38+
}
39+
2340
// @dev get event values from front end and update config
2441
func New(
2542
triggerName string,
@@ -37,12 +54,5 @@ func New(
3754
_EnvBot.SlackUserName = slackUserName
3855

3956
EnvBot = &_EnvBot
40-
41-
// TODO fix gorm UNIQUE constraint failed
42-
if rErr := DB_HANDLE.Where("id = ?", EnvBot.ID).First(EnvBot).Error; errors.Is(rErr, gorm.ErrRecordNotFound) {
43-
CreateEnvBotConfig(*EnvBot)
44-
} else {
45-
UpdateEnvBotConfig(*EnvBot)
46-
}
4757
color.Cyan("Setup.go: Envbot properly configured")
4858
}

core/account/account.controller.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package account
2+
3+
import (
4+
"context"
5+
6+
"github.com/asunlabs/owlly/config"
7+
"github.com/wailsapp/wails/v2/pkg/runtime"
8+
)
9+
10+
// TODO add sign in, sign up event
11+
func ListenEmailSignUp(ctx context.Context) {
12+
runtime.EventsOn(ctx, config.AUTH_EVENT["sign-up"], func(optionalData ...interface{}) {
13+
var newEmailUser config.ModelEmailUser
14+
CreateEmailUser(newEmailUser)
15+
})
16+
}

0 commit comments

Comments
 (0)