Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MyAktion Go
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sercan Yesildal
MyAktion Go
Commits
cf5a3a64
Commit
cf5a3a64
authored
2 years ago
by
Sercan Yesildal
Browse files
Options
Downloads
Patches
Plain Diff
added db services
parent
673a05ea
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/myaktion/service/campaign.go
+30
-25
30 additions, 25 deletions
src/myaktion/service/campaign.go
src/myaktion/service/donation.go
+8
-10
8 additions, 10 deletions
src/myaktion/service/donation.go
with
38 additions
and
35 deletions
src/myaktion/service/campaign.go
+
30
−
25
View file @
cf5a3a64
package
service
package
service
import
(
import
(
"fmt"
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"gitlab.reutlingen-university.de/yesildas/myaktion-go/src/myaktion/db"
"gitlab.reutlingen-university.de/yesildas/myaktion-go/src/myaktion/db"
...
@@ -31,14 +29,16 @@ func CreateCampaign(campaign *model.Campaign) error {
...
@@ -31,14 +29,16 @@ func CreateCampaign(campaign *model.Campaign) error {
}
}
func
GetCampaign
(
id
uint
)
(
*
model
.
Campaign
,
error
)
{
func
GetCampaign
(
id
uint
)
(
*
model
.
Campaign
,
error
)
{
if
campaign
,
ok
:=
campaignStore
[
id
];
!
ok
{
var
campaign
model
.
Campaign
log
.
Info
(
"Campaign with ID %d not found."
,
id
)
result
:=
db
.
DB
.
Preload
(
"Donations"
)
.
First
(
&
campaign
,
id
)
return
nil
,
fmt
.
Errorf
(
"campaign with id %d not found"
,
id
)
if
result
.
Error
!=
nil
{
}
else
{
log
.
Info
(
"Campaign retrieving failed."
)
log
.
Infof
(
"Successfully retrieved campaign with ID %v."
,
campaign
.
ID
)
return
nil
,
result
.
Error
log
.
Tracef
(
"Retrieved: "
,
*
campaign
)
return
campaign
,
nil
}
}
log
.
Infof
(
"Successfully retrieved campaign with ID %v."
,
campaign
.
ID
)
log
.
Tracef
(
"Retrieved: "
,
campaign
)
return
&
campaign
,
nil
}
}
func
GetCampaigns
()
([]
model
.
Campaign
,
error
)
{
func
GetCampaigns
()
([]
model
.
Campaign
,
error
)
{
...
@@ -54,25 +54,30 @@ func GetCampaigns() ([]model.Campaign, error) {
...
@@ -54,25 +54,30 @@ func GetCampaigns() ([]model.Campaign, error) {
}
}
func
UpdateCampaign
(
id
uint
,
campaign
*
model
.
Campaign
)
(
*
model
.
Campaign
,
error
)
{
func
UpdateCampaign
(
id
uint
,
campaign
*
model
.
Campaign
)
(
*
model
.
Campaign
,
error
)
{
if
storeCampaign
,
ok
:=
campaignStore
[
id
];
!
ok
{
var
campaignData
model
.
Campaign
log
.
Info
(
"Campaign with ID %d not found."
,
id
)
result
:=
db
.
DB
.
Preload
(
"Donations"
)
.
First
(
&
campaignData
,
id
)
return
nil
,
fmt
.
Errorf
(
"campaign with id %d not found"
,
id
)
if
result
.
Error
!=
nil
{
}
else
{
log
.
Info
(
"Campaign retrieving failed."
)
*
storeCampaign
=
*
campaign
return
nil
,
result
.
Error
storeCampaign
.
ID
=
id
}
log
.
Infof
(
"Successfully updated campaign with ID %d."
,
id
)
result
=
db
.
DB
.
Model
(
&
campaignData
)
.
Updates
(
&
campaign
)
log
.
Tracef
(
"Updated: %v"
,
storeCampaign
)
if
result
.
Error
!=
nil
{
return
storeCampaign
,
nil
log
.
Info
(
"Campaign updating failed."
)
return
nil
,
result
.
Error
}
}
log
.
Infof
(
"Successfully updated campaign with ID %d."
,
id
)
log
.
Tracef
(
"Updated: %v"
,
campaignData
)
return
&
campaignData
,
nil
}
}
func
DeleteCampaign
(
id
uint
)
error
{
func
DeleteCampaign
(
id
uint
)
error
{
if
campaign
,
ok
:=
campaignStore
[
id
];
!
ok
{
result
:=
db
.
DB
.
Preload
(
"Donations"
)
.
Delete
(
&
model
.
Campaign
{},
id
)
log
.
Info
(
"Campaign with ID %d not found."
,
id
)
if
result
.
Error
!=
nil
{
return
fmt
.
Errorf
(
"campaign with id %d not found"
,
id
)
log
.
Info
(
"Campaign delete failed."
)
}
else
{
return
result
.
Error
delete
(
campaignStore
,
id
)
log
.
Infof
(
"Successfully deleted campaign with ID %v."
,
campaign
.
ID
)
return
nil
}
}
log
.
Infof
(
"Successfully deleted campaign with ID %v."
,
id
)
return
nil
}
}
This diff is collapsed.
Click to expand it.
src/myaktion/service/donation.go
+
8
−
10
View file @
cf5a3a64
package
service
package
service
import
(
import
(
"fmt"
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"gitlab.reutlingen-university.de/yesildas/myaktion-go/src/myaktion/db"
"gitlab.reutlingen-university.de/yesildas/myaktion-go/src/myaktion/model"
"gitlab.reutlingen-university.de/yesildas/myaktion-go/src/myaktion/model"
)
)
func
AddDonation
(
campaignId
uint
,
donation
*
model
.
Donation
)
error
{
func
AddDonation
(
campaignId
uint
,
donation
*
model
.
Donation
)
error
{
campaign
,
err
:=
GetCampaign
(
campaignId
)
donation
.
CampaignID
=
campaignId
if
err
!=
nil
{
result
:=
db
.
DB
.
Create
(
donation
)
log
.
Info
(
"Campaign with ID %d not found."
,
campaignId
)
if
result
.
Error
!=
nil
{
return
fmt
.
Errorf
(
"campaign with id %d not found"
,
campaignId
)
log
.
Info
(
"Donation creation failed."
)
}
return
result
.
Error
if
campaign
.
Donations
==
nil
{
campaign
.
Donations
=
[]
model
.
Donation
{}
}
}
campaign
.
Donations
=
append
(
campaign
.
Donations
,
*
donation
)
log
.
Info
(
"Successfully stored new donation"
)
log
.
Tracef
(
"Stored: %v"
,
donation
)
return
nil
return
nil
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment