Skip to content

Commit

Permalink
chore: prettier code style
Browse files Browse the repository at this point in the history
  • Loading branch information
rulanugrh committed Mar 22, 2024
1 parent 872c852 commit fad88ed
Show file tree
Hide file tree
Showing 25 changed files with 208 additions and 221 deletions.
18 changes: 9 additions & 9 deletions api/http/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ type AdminInterface interface {

type admin struct {
service service.AdminInterface
gauge *pkg.Data
gauge *pkg.Data
}

func NewAdmin(service service.AdminInterface, gauge *pkg.Data) AdminInterface {
return &admin{
service: service,
gauge: gauge,
gauge: gauge,
}
}

func(a *admin) Penyakit(w http.ResponseWriter, r *http.Request) {
func (a *admin) Penyakit(w http.ResponseWriter, r *http.Request) {
var req domain.Penyakit
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
Expand Down Expand Up @@ -66,7 +66,7 @@ func(a *admin) Penyakit(w http.ResponseWriter, r *http.Request) {
return
}

func(a *admin) Obat(w http.ResponseWriter, r *http.Request) {
func (a *admin) Obat(w http.ResponseWriter, r *http.Request) {
var req domain.Obat
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
Expand Down Expand Up @@ -96,7 +96,7 @@ func(a *admin) Obat(w http.ResponseWriter, r *http.Request) {
return
}

func(a *admin) UpdateObat(w http.ResponseWriter, r *http.Request) {
func (a *admin) UpdateObat(w http.ResponseWriter, r *http.Request) {
var req domain.Obat
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
Expand Down Expand Up @@ -131,7 +131,7 @@ func(a *admin) UpdateObat(w http.ResponseWriter, r *http.Request) {
return
}

func(a *admin) DeleteObat(w http.ResponseWriter, r *http.Request) {
func (a *admin) DeleteObat(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(strings.TrimPrefix(r.URL.Path, "/api/admin/delete/obat/"))
if err != nil {
w.WriteHeader(500)
Expand All @@ -154,7 +154,7 @@ func(a *admin) DeleteObat(w http.ResponseWriter, r *http.Request) {
return
}

func(a *admin) DeletePenyakit(w http.ResponseWriter, r *http.Request) {
func (a *admin) DeletePenyakit(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(strings.TrimPrefix(r.URL.Path, "/api/admin/delete/penyakit/"))
if err != nil {
w.WriteHeader(500)
Expand All @@ -177,7 +177,7 @@ func(a *admin) DeletePenyakit(w http.ResponseWriter, r *http.Request) {
return
}

func(a *admin) Reported(w http.ResponseWriter, r *http.Request) {
func (a *admin) Reported(w http.ResponseWriter, r *http.Request) {
data, err := a.service.Reported()
if err != nil {
a.gauge.KunjunganHistory.With(prometheus.Labels{"code": "400", "method": "GET", "type": "get"}).Observe(time.Since(time.Now()).Seconds())
Expand All @@ -196,7 +196,7 @@ func(a *admin) Reported(w http.ResponseWriter, r *http.Request) {
return
}

func(a *admin) ListAllUser(w http.ResponseWriter, r *http.Request) {
func (a *admin) ListAllUser(w http.ResponseWriter, r *http.Request) {
data, err := a.service.ListAllUser()
if err != nil {
a.gauge.UserHistory.With(prometheus.Labels{"code": "400", "method": "GET", "type": "get"}).Observe(time.Since(time.Now()).Seconds())
Expand Down
8 changes: 4 additions & 4 deletions api/http/kunjungan.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ type KunjunganInterface interface {

type kunjungan struct {
service service.KunjunganInterface
gauge *pkg.Data
gauge *pkg.Data
}

func NewKunjungan(service service.KunjunganInterface, gauge *pkg.Data) KunjunganInterface {
return &kunjungan{
service: service,
gauge: gauge,
gauge: gauge,
}
}

func(k *kunjungan) Create(w http.ResponseWriter, r *http.Request) {
func (k *kunjungan) Create(w http.ResponseWriter, r *http.Request) {
var req domain.Kunjungan
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
Expand Down Expand Up @@ -60,7 +60,7 @@ func(k *kunjungan) Create(w http.ResponseWriter, r *http.Request) {
return
}

func(k *kunjungan) Find(w http.ResponseWriter, r *http.Request) {
func (k *kunjungan) Find(w http.ResponseWriter, r *http.Request) {
id, err := middleware.GetUserID(r)
if err != nil {
k.gauge.KunjunganHistory.With(prometheus.Labels{"code": "401", "method": "GET", "type": "getByID"}).Observe(time.Since(time.Now()).Seconds())
Expand Down
8 changes: 4 additions & 4 deletions api/http/obat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ type ObatInterface interface {

type obat struct {
service service.ObatInterface
gauge *pkg.Data
gauge *pkg.Data
}

func NewObat(service service.ObatInterface, gauge *pkg.Data) ObatInterface {
return &obat{
service: service,
gauge: gauge,
gauge: gauge,
}
}

func(o *obat) FindID(w http.ResponseWriter, r *http.Request) {
func (o *obat) FindID(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(strings.TrimPrefix(r.URL.Path, "/api/obat/find/"))
if err != nil {
w.WriteHeader(500)
Expand All @@ -54,7 +54,7 @@ func(o *obat) FindID(w http.ResponseWriter, r *http.Request) {
return
}

func(o *obat) FindAll(w http.ResponseWriter, r *http.Request) {
func (o *obat) FindAll(w http.ResponseWriter, r *http.Request) {
data, err := o.service.FindAll()
if err != nil {
o.gauge.ObatHistory.With(prometheus.Labels{"code": "400", "method": "GET", "type": "get"}).Observe(time.Since(time.Now()).Seconds())
Expand Down
10 changes: 5 additions & 5 deletions api/http/penyakit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ type PenyakitInterface interface {

type penyakit struct {
service service.PenyakitInterface
gauge *pkg.Data
gauge *pkg.Data
}

func NewPenyakit(service service.PenyakitInterface, gauge *pkg.Data) PenyakitInterface {
return &penyakit{
service: service,
gauge: gauge,
gauge: gauge,
}
}

func(p *penyakit) FindAll(w http.ResponseWriter, r *http.Request) {
func (p *penyakit) FindAll(w http.ResponseWriter, r *http.Request) {
data, err := p.service.FindAll()
if err != nil {
p.gauge.PenyakitHistory.With(prometheus.Labels{"code": "400", "method": "GET", "type": "get"}).Observe(time.Since(time.Now()).Seconds())
Expand All @@ -48,8 +48,8 @@ func(p *penyakit) FindAll(w http.ResponseWriter, r *http.Request) {
w.Write(response)
}

func(p *penyakit) FindID(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(strings.TrimPrefix(r.URL.Path, "/api/penyakit/find/"))
func (p *penyakit) FindID(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(strings.TrimPrefix(r.URL.Path, "/api/penyakit/find/"))
if err != nil {
w.WriteHeader(500)
return
Expand Down
15 changes: 7 additions & 8 deletions api/http/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ type UserInterface interface {

type user struct {
service service.UserInterface
gauge *pkg.Data
gauge *pkg.Data
}

func NewUser(service service.UserInterface, gauge *pkg.Data) UserInterface {
return &user{
service: service,
gauge: gauge,
gauge: gauge,
}
}

func(u *user) Register(w http.ResponseWriter, r *http.Request) {
func (u *user) Register(w http.ResponseWriter, r *http.Request) {
var req domain.UserRegister
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
Expand Down Expand Up @@ -64,7 +64,7 @@ func(u *user) Register(w http.ResponseWriter, r *http.Request) {
return
}

func(u *user) Login(w http.ResponseWriter, r *http.Request) {
func (u *user) Login(w http.ResponseWriter, r *http.Request) {
var req domain.UserLogin
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
Expand Down Expand Up @@ -102,7 +102,7 @@ func(u *user) Login(w http.ResponseWriter, r *http.Request) {
return
}

func(u *user) Update(w http.ResponseWriter, r *http.Request) {
func (u *user) Update(w http.ResponseWriter, r *http.Request) {
var req domain.User
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
Expand Down Expand Up @@ -134,7 +134,6 @@ func(u *user) Update(w http.ResponseWriter, r *http.Request) {
return
}


u.gauge.UserHistory.With(prometheus.Labels{"code": "200", "method": "PUT", "type": "update"}).Observe(time.Since(time.Now()).Seconds())
u.gauge.UserUpgrade.With(prometheus.Labels{"type": "update"}).Inc()

Expand All @@ -143,7 +142,7 @@ func(u *user) Update(w http.ResponseWriter, r *http.Request) {
return
}

func(u *user) GotDoctor(w http.ResponseWriter, r *http.Request) {
func (u *user) GotDoctor(w http.ResponseWriter, r *http.Request) {
data, err := u.service.GotDoctor()
if err != nil {
u.gauge.UserHistory.With(prometheus.Labels{"code": "400", "method": "GET", "type": "get"}).Observe(time.Since(time.Now()).Seconds())
Expand All @@ -162,7 +161,7 @@ func(u *user) GotDoctor(w http.ResponseWriter, r *http.Request) {
return
}

func(u *user) GotNurse(w http.ResponseWriter, r *http.Request) {
func (u *user) GotNurse(w http.ResponseWriter, r *http.Request) {
data, err := u.service.GotNurse()
if err != nil {
u.gauge.UserHistory.With(prometheus.Labels{"code": "400", "method": "GET", "type": "get"}).Observe(time.Since(time.Now()).Seconds())
Expand Down
5 changes: 3 additions & 2 deletions internal/config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ type App struct {
Password string
}
}

var app *App

func GetConfig() *App {
if app == nil {
app = initConfig()
}

return app
}

Expand Down Expand Up @@ -87,4 +88,4 @@ func initConfig() *App {
conf.App.Host = os.Getenv("APP_HOST")

return &conf
}
}
2 changes: 1 addition & 1 deletion internal/config/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (m *MongoDB) NewMongo() {
)

client := options.Client().ApplyURI(dsn).SetServerAPIOptions(serverApi)
ctx, cancel := context.WithTimeout(context.Background(), 20 * time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

cli, err := mongo.Connect(ctx, client)
Expand Down
30 changes: 15 additions & 15 deletions internal/config/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
)

type Postgres struct {
DB *gorm.DB
DB *gorm.DB
conf *App
}

func InitializePostgres(conf *App) *Postgres {
return &Postgres{conf: conf}
}

func (p *Postgres) NewConnection() {
func (p *Postgres) NewConnection() {
dsn := fmt.Sprintf("postgresql://%s:%s@%s:%s/%s?sslmode=disable&TimeZone=Asia/Jakarta",
p.conf.Postges.User,
p.conf.Postges.Pass,
Expand Down Expand Up @@ -50,41 +50,41 @@ func (p *Postgres) Migration() {
func (p *Postgres) Seeder() error {
roles := append([]domain.Role{},
domain.Role{
Name: "Admin",
Name: "Admin",
Descriptions: "this is role admin",
},
domain.Role{
Name: "Doctor",
Name: "Doctor",
Descriptions: "this is role doctor",
},
domain.Role{
Name: "Nurse",
Name: "Nurse",
Descriptions: "this is role nurse",
},
domain.Role{
Name: "User",
Name: "User",
Descriptions: "this is role for user",
})
})

err := p.DB.Create(&roles).Error
if err != nil {
return err
}

password, err:= bcrypt.GenerateFromPassword([]byte(p.conf.Admin.Password), 14)
password, err := bcrypt.GenerateFromPassword([]byte(p.conf.Admin.Password), 14)
if err != nil {
return err
}

user := domain.User{
FName: "Admini",
LName: "-",
Email: p.conf.Admin.Email,
FName: "Admini",
LName: "-",
Email: p.conf.Admin.Email,
Password: string(password),
Address: "-",
Age: 0,
RoleID: 1,
TTL: time.Now(),
Address: "-",
Age: 0,
RoleID: 1,
TTL: time.Now(),
}

err = p.DB.Create(&user).Error
Expand Down
2 changes: 1 addition & 1 deletion internal/entity/domain/kunjungan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "gorm.io/gorm"
type Kunjungan struct {
gorm.Model
UserID uint `json:"user_id" form:"user_id" validate:"required"`
Doctor string `json:"doctor" from:"doctor" validate:"required"`
Doctor string `json:"doctor" from:"doctor" validate:"required"`
PenyakitID []uint `json:"penyakit_id" form:"penyakit_id" validate:"required"`
User User `json:"user" gorm:"foreignKey:UserID;references:ID"`
Penyakit []Penyakit `json:"penyakit" gorm:"foreignKey:PenyakitID;references:ID"`
Expand Down
9 changes: 0 additions & 9 deletions internal/entity/domain/role.go

This file was deleted.

6 changes: 6 additions & 0 deletions internal/entity/domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ type UserLogin struct {
Email string `json:"email" form:"email" validate:"required,email"`
Password string `json:"password" form:"password" validate:"required"`
}

type Role struct {
gorm.Model
Name string `json:"name"`
Descriptions string `json:"desc"`
}
2 changes: 1 addition & 1 deletion internal/entity/web/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ type ObatUpdated struct {
Description string `json:"string"`
Price int32 `json:"price"`
QtyAvailable uint8 `json:"qty_available"`
}
}

0 comments on commit fad88ed

Please sign in to comment.