-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kervin Christianata
committed
Mar 17, 2022
1 parent
e5d26a8
commit eef81cf
Showing
9 changed files
with
359 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.envrc | ||
bin/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package data | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/kervinch/internal/validator" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type BannerTemp struct { | ||
ID int64 `json:"id" gorm:"primaryKey"` | ||
ImageURL string `json:"image_url"` | ||
Title string `json:"title"` | ||
Deeplink string `json:"deeplink"` | ||
OutboundURL string `json:"outbound_url"` | ||
IsActive bool `json:"is_active"` | ||
CreatedAt time.Time `json:"-"` | ||
UpdatedAt time.Time `json:"-"` | ||
} | ||
|
||
func GormValidateBanner(v *validator.Validator, banner *Banner) { | ||
v.Check(banner.ImageURL != "", "image_url", "must be provided") | ||
v.Check(banner.Title != "", "title", "must be provided") | ||
v.Check(len(banner.Title) <= 500, "title", "must not be more than 500 bytes long") | ||
v.Check(len(banner.Deeplink) <= 500, "deeplink", "must not be more than 500 bytes long") | ||
v.Check(len(banner.OutboundURL) <= 500, "outbound_url", "must not be more than 500 bytes long") | ||
} | ||
|
||
type GormBannerModel struct { | ||
DB *gorm.DB | ||
} | ||
|
||
// ==================================================================================== | ||
// Backoffice Functions | ||
// ==================================================================================== | ||
|
||
func (g GormBannerModel) GetAll() ([]*Banner, error) { | ||
var banners []*Banner | ||
|
||
err := g.DB.Find(&banners).Error | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return banners, nil | ||
} | ||
|
||
// ==================================================================================== | ||
// Business Functions | ||
// ==================================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters