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
import
(
"fmt"
log
"github.com/sirupsen/logrus"
"gitlab.reutlingen-university.de/yesildas/myaktion-go/src/myaktion/db"
...
...
@@ -31,14 +29,16 @@ func CreateCampaign(campaign *model.Campaign) error {
}
func
GetCampaign
(
id
uint
)
(
*
model
.
Campaign
,
error
)
{
if
campaign
,
ok
:=
campaignStore
[
id
];
!
ok
{
log
.
Info
(
"Campaign with ID %d not found."
,
id
)
return
nil
,
fmt
.
Errorf
(
"campaign with id %d not found"
,
id
)
}
else
{
log
.
Infof
(
"Successfully retrieved campaign with ID %v."
,
campaign
.
ID
)
log
.
Tracef
(
"Retrieved: "
,
*
campaign
)
return
campaign
,
nil
var
campaign
model
.
Campaign
result
:=
db
.
DB
.
Preload
(
"Donations"
)
.
First
(
&
campaign
,
id
)
if
result
.
Error
!=
nil
{
log
.
Info
(
"Campaign retrieving failed."
)
return
nil
,
result
.
Error
}
log
.
Infof
(
"Successfully retrieved campaign with ID %v."
,
campaign
.
ID
)
log
.
Tracef
(
"Retrieved: "
,
campaign
)
return
&
campaign
,
nil
}
func
GetCampaigns
()
([]
model
.
Campaign
,
error
)
{
...
...
@@ -54,25 +54,30 @@ func GetCampaigns() ([]model.Campaign, error) {
}
func
UpdateCampaign
(
id
uint
,
campaign
*
model
.
Campaign
)
(
*
model
.
Campaign
,
error
)
{
if
storeCampaign
,
ok
:=
campaignStore
[
id
];
!
ok
{
log
.
Info
(
"Campaign with ID %d not found."
,
id
)
return
nil
,
fmt
.
Errorf
(
"campaign with id %d not found"
,
id
)
}
else
{
*
storeCampaign
=
*
campaign
storeCampaign
.
ID
=
id
log
.
Infof
(
"Successfully updated campaign with ID %d."
,
id
)
log
.
Tracef
(
"Updated: %v"
,
storeCampaign
)
return
storeCampaign
,
nil
var
campaignData
model
.
Campaign
result
:=
db
.
DB
.
Preload
(
"Donations"
)
.
First
(
&
campaignData
,
id
)
if
result
.
Error
!=
nil
{
log
.
Info
(
"Campaign retrieving failed."
)
return
nil
,
result
.
Error
}
result
=
db
.
DB
.
Model
(
&
campaignData
)
.
Updates
(
&
campaign
)
if
result
.
Error
!=
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
{
if
campaign
,
ok
:=
campaignStore
[
id
];
!
ok
{
log
.
Info
(
"Campaign with ID %d not found."
,
id
)
return
fmt
.
Errorf
(
"campaign with id %d not found"
,
id
)
}
else
{
delete
(
campaignStore
,
id
)
log
.
Infof
(
"Successfully deleted campaign with ID %v."
,
campaign
.
ID
)
return
nil
result
:=
db
.
DB
.
Preload
(
"Donations"
)
.
Delete
(
&
model
.
Campaign
{},
id
)
if
result
.
Error
!=
nil
{
log
.
Info
(
"Campaign delete failed."
)
return
result
.
Error
}
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
import
(
"fmt"
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"
)
func
AddDonation
(
campaignId
uint
,
donation
*
model
.
Donation
)
error
{
campaign
,
err
:=
GetCampaign
(
campaignId
)
if
err
!=
nil
{
log
.
Info
(
"Campaign with ID %d not found."
,
campaignId
)
return
fmt
.
Errorf
(
"campaign with id %d not found"
,
campaignId
)
}
if
campaign
.
Donations
==
nil
{
campaign
.
Donations
=
[]
model
.
Donation
{}
donation
.
CampaignID
=
campaignId
result
:=
db
.
DB
.
Create
(
donation
)
if
result
.
Error
!=
nil
{
log
.
Info
(
"Donation creation failed."
)
return
result
.
Error
}
campaign
.
Donations
=
append
(
campaign
.
Donations
,
*
donation
)
log
.
Info
(
"Successfully stored new donation"
)
log
.
Tracef
(
"Stored: %v"
,
donation
)
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