Skip to content

Commit

Permalink
add new
Browse files Browse the repository at this point in the history
  • Loading branch information
idprm committed Aug 5, 2024
1 parent affe252 commit 261c568
Show file tree
Hide file tree
Showing 58 changed files with 1,212 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jobs:
matrix:
include:
- dockerfile: ./Dockerfile.listener
image: idprm/ussd-listener-service
image: idprm/fb-alert-listener-service
- dockerfile: ./Dockerfile.scraper
image: idprm/fb-alert-scraper-service

permissions:
contents: read
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.listener
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COPY . .
RUN go mod download
RUN go mod verify

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /football .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /fb-alert .

FROM scratch

Expand All @@ -24,6 +24,6 @@ COPY --from=golang /etc/passwd /etc/passwd
COPY --from=golang /etc/group /etc/group
COPY --from=golang /bin/sh /bin/sh

COPY --from=golang /football .
COPY --from=golang /fb-alert .

CMD ["/football", "listener"]
CMD ["/fb-alert", "listener"]
29 changes: 29 additions & 0 deletions Dockerfile.scraper
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM golang:1.22-alpine as golang

RUN apk --no-cache add tzdata

RUN apk --update add ca-certificates

LABEL author="Indra Pramana"

RUN mkdir -p /logs/http

WORKDIR /app
COPY . .

RUN go mod download
RUN go mod verify

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /fb-alert .

FROM scratch

COPY --from=golang /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=golang /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=golang /etc/passwd /etc/passwd
COPY --from=golang /etc/group /etc/group
COPY --from=golang /bin/sh /bin/sh

COPY --from=golang /fb-alert .

CMD ["/fb-alert", "scraper"]
6 changes: 6 additions & 0 deletions cmd/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ var listenerCmd = &cobra.Command{
// TODO: Add migrations
db.AutoMigrate(
&entity.Ussd{},
&entity.League{},
&entity.Season{},
&entity.Team{},
&entity.Fixture{},
&entity.Home{},
&entity.Away{},
)

r := routeUrlListener(db)
Expand Down
11 changes: 11 additions & 0 deletions internal/domain/entity/away.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package entity

type Away struct {
ID int64 `json:"id,omitempty"`
FixtureID int64 `json:"fixture_id"`
Fixture *Fixture `json:"fixture"`
TeamID int64 `json:"team_id"`
Team *Team `json:"team"`
Goal int `json:"goal"`
IsWinner bool `gorm:"type:bool;default:false" json:"is_winner"`
}
7 changes: 6 additions & 1 deletion internal/domain/entity/content.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package entity

type COntent struct {
type Content struct {
ID int `gorm:"primaryKey" json:"id"`
ServiceID int `json:"service_id"`
Service *Service `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"service,omitempty"`
Key string `gorm:"size:50" json:"key"`
Value string `gorm:"size:150" json:"value"`
}
9 changes: 9 additions & 0 deletions internal/domain/entity/fixture.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package entity

type Fixture struct {
ID int64 `gorm:"primaryKey" json:"id"`
Referee string `json:"referee"`
Timezone string `json:"timezone"`
Date string `json:"date"`
TimeStamp int `json:"timestamp"`
HomeID int64 `json:"home_id"`
Home *Home `json:"home"`
AwayID int64 `json:"away_id"`
Away *Away `json:"away"`
}
11 changes: 11 additions & 0 deletions internal/domain/entity/home.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package entity

type Home struct {
ID int64 `gorm:"primaryKey" json:"id"`
FixtureID int64 `json:"fixture_id"`
Fixture *Fixture `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"fixture,omitempty"`
TeamID int64 `json:"team_id"`
Team *Team `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"team,omitempty"`
Goal int `gorm:"size:10" json:"goal"`
IsWinner bool `gorm:"type:bool;default:false" json:"is_winner"`
}
5 changes: 5 additions & 0 deletions internal/domain/entity/league.go
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
package entity

type League struct {
ID int64 `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
}
1 change: 1 addition & 0 deletions internal/domain/entity/livescore.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package entity

type Livescore struct {
ID int64 `gorm:"primaryKey" json:"id"`
}
3 changes: 3 additions & 0 deletions internal/domain/entity/news.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package entity

type News struct {
ID int64 `gorm:"primaryKey" json:"id"`
FixtureID int64 `json:"fixture_id"`
Fixture *Fixture `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"fixture,omitempty"`
}
35 changes: 35 additions & 0 deletions internal/domain/entity/pagination.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package entity

type Pagination struct {
Limit int `json:"limit,omitempty" query:"limit"`
Page int `json:"page,omitempty" query:"page"`
Sort string `json:"sort,omitempty" query:"sort"`
TotalRows int64 `json:"total_rows"`
TotalPages int `json:"total_pages"`
Rows interface{} `json:"rows"`
}

func (p *Pagination) GetOffset() int {
return (p.GetPage() - 1) * p.GetLimit()
}

func (p *Pagination) GetLimit() int {
if p.Limit == 0 {
p.Limit = 10
}
return p.Limit
}

func (p *Pagination) GetPage() int {
if p.Page == 0 {
p.Page = 1
}
return p.Page
}

func (p *Pagination) GetSort() string {
if p.Sort == "" {
p.Sort = "Id desc"
}
return p.Sort
}
4 changes: 0 additions & 4 deletions internal/domain/entity/player.go

This file was deleted.

7 changes: 7 additions & 0 deletions internal/domain/entity/prediction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package entity

type Prediction struct {
ID int64 `gorm:"primaryKey" json:"id"`
FixtureID int64 `json:"fixture_id"`
Fixture *Fixture `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"fixture,omitempty"`
}
11 changes: 11 additions & 0 deletions internal/domain/entity/reward.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package entity

type Reward struct {
ID int64 `gorm:"primaryKey" json:"id"`
FixtureID int64 `json:"fixture_id"`
Fixture *Fixture `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"fixture,omitempty"`
SubscriptionID int64 `json:"subscription_id"`
Subscription *Subscription `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"subscription,omitempty"`
Msisdn string `gorm:"size:15;not null" json:"msisdn"`
Amount float64 `gorm:"size:8;default:0" json:"amount"`
}
1 change: 1 addition & 0 deletions internal/domain/entity/schedule.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package entity

type Schedule struct {
ID int64 `gorm:"primaryKey" json:"id"`
}
1 change: 1 addition & 0 deletions internal/domain/entity/season.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package entity

type Season struct {
ID int64 `gorm:"primaryKey" json:"id"`
}
2 changes: 2 additions & 0 deletions internal/domain/entity/service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package entity

type Service struct {
ID int `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
}
5 changes: 0 additions & 5 deletions internal/domain/entity/subscriber.go

This file was deleted.

8 changes: 8 additions & 0 deletions internal/domain/entity/subscription.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package entity

type Subscription struct {
ID int64 `gorm:"primaryKey" json:"id"`
ServiceID int `json:"service_id"`
Service *Service `json:"service"`
Msisdn string `gorm:"size:15;not null" json:"msisdn"`
}
23 changes: 23 additions & 0 deletions internal/domain/entity/team.go
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
package entity

type Team struct {
ID int64 `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Logo string `json:"logo"`
}

func (e *Team) GetId() int64 {
return e.ID
}

func (e *Team) GetName() string {
return e.Name
}

func (e *Team) GetSlug() string {
return e.Slug
}

func (e *Team) GetLogo() string {
return e.Logo
}
10 changes: 10 additions & 0 deletions internal/domain/entity/transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package entity

type Transaction struct {
ID int64 `gorm:"primaryKey" json:"id"`
SubscriptionID int64 `json:"subscription_id"`
Subscription *Subscription `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"subscription,omitempty"`
ServiceID int `json:"service_id"`
Service *Service `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"service,omitempty"`
Msisdn string `gorm:"size:15;not null" json:"msisdn"`
}
2 changes: 1 addition & 1 deletion internal/domain/entity/ussd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package entity

type Ussd struct {
ID int64 `json:"id"`
ID int64 `gorm:"primaryKey" json:"id"`
Msisdn string `json:"msisdn"`
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package model

type ApiFbResponse struct {
League *LeagueResponse `json:"league"`
Country *CountryResponse `json:"country"`
Seasson *[]SeassonResponse `json:"seasons"`
}

type LeagueResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Expand Down
77 changes: 77 additions & 0 deletions internal/domain/repository/away_repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package repository

import (
"github.com/idprm/go-football-alert/internal/domain/entity"
"gorm.io/gorm"
)

type AwayRepository struct {
db *gorm.DB
}

func NewAwayRepository(db *gorm.DB) *AwayRepository {
return &AwayRepository{
db: db,
}
}

type IAwayRepository interface {
CountByTeamId(int) (int64, error)
GetAllPaginate(*entity.Pagination) (*entity.Pagination, error)
GetByTeamId(string) (*entity.Away, error)
Save(*entity.Away) (*entity.Away, error)
Update(*entity.Away) (*entity.Away, error)
Delete(*entity.Away) error
}

func (r *AwayRepository) CountByTeamId(teamId int) (int64, error) {
var count int64
err := r.db.Model(&entity.Away{}).Where("team_id = ?", teamId).Count(&count).Error
if err != nil {
return count, err
}
return count, nil
}

func (r *AwayRepository) GetAllPaginate(pagination *entity.Pagination) (*entity.Pagination, error) {
var aways []*entity.Away
err := r.db.Scopes(Paginate(aways, pagination, r.db)).Preload("Team").Find(&aways).Error
if err != nil {
return nil, err
}
pagination.Rows = aways
return pagination, nil
}

func (r *AwayRepository) GetByTeamId(teamId int) (*entity.Away, error) {
var away entity.Away
err := r.db.Where("team_id = ?", teamId).Preload("Team").Take(&away).Error
if err != nil {
return nil, err
}
return &away, nil
}

func (r *AwayRepository) Save(away *entity.Away) (*entity.Away, error) {
err := r.db.Create(&away).Error
if err != nil {
return nil, err
}
return away, nil
}

func (r *AwayRepository) Update(away *entity.Away) (*entity.Away, error) {
err := r.db.Where("id = ?", away.ID).Updates(&away).Error
if err != nil {
return nil, err
}
return away, nil
}

func (r *AwayRepository) Delete(p *entity.Away) error {
err := r.db.Delete(&p, p.ID).Error
if err != nil {
return err
}
return nil
}
Loading

0 comments on commit 261c568

Please sign in to comment.