Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
invinoveritas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
gbe
invinoveritas
Commits
ad96e662
Commit
ad96e662
authored
3 years ago
by
gbe
Browse files
Options
Downloads
Patches
Plain Diff
Redirect to newly created entries
parent
5defd672
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
handler-index.go
+1
-1
1 addition, 1 deletion
handler-index.go
vino.go
+21
-3
21 additions, 3 deletions
vino.go
with
22 additions
and
4 deletions
handler-index.go
+
1
−
1
View file @
ad96e662
...
...
@@ -94,5 +94,5 @@ func (h Handler) index(w http.ResponseWriter, r *http.Request) {
return
}
http
.
Redirect
(
w
,
r
,
"/
"
,
http
.
StatusSeeOther
)
// TODO: Is this the correct status?
http
.
Redirect
(
w
,
r
,
"/
details?id="
+
strconv
.
Itoa
(
vino
.
ID
)
,
http
.
StatusSeeOther
)
// TODO: Is this the correct status?
}
This diff is collapsed.
Click to expand it.
vino.go
+
21
−
3
View file @
ad96e662
...
...
@@ -107,7 +107,12 @@ func (v Vino) String() string {
return
fmt
.
Sprintf
(
"{Name: %q, Rating: %d}"
,
v
.
Name
,
v
.
Rating
)
}
func
(
v
Vino
)
Store
(
ctx
context
.
Context
,
db
*
sqlx
.
DB
,
op
storeOperation
)
(
err
error
)
{
func
(
v
*
Vino
)
Store
(
ctx
context
.
Context
,
db
*
sqlx
.
DB
,
op
storeOperation
)
(
err
error
)
{
if
op
==
Add
&&
v
.
ID
!=
0
{
// If we already have an ID, the op needs to be an Update
return
errors
.
New
(
"add with already-set ID"
)
}
values
:=
map
[
string
]
interface
{}{
"name"
:
v
.
Name
,
"rating"
:
v
.
Rating
,
...
...
@@ -170,12 +175,25 @@ func (v Vino) Store(ctx context.Context, db *sqlx.DB, op storeOperation) (err er
return
err
}
_
,
err
=
squirrel
.
Insert
(
"wines"
)
.
res
,
err
:
=
squirrel
.
Insert
(
"wines"
)
.
SetMap
(
values
)
.
RunWith
(
tx
)
.
ExecContext
(
ctx
)
if
err
!=
nil
{
return
err
}
id
,
err
:=
res
.
LastInsertId
()
if
err
!=
nil
{
return
err
}
return
err
// If it's an add (i.e. initial creation of an entry) fill in the ID
log
.
Println
(
"insert result:"
,
res
,
"id:"
,
id
)
v
.
ID
=
int
(
id
)
return
nil
}
func
ListWines
(
ctx
context
.
Context
,
db
*
sqlx
.
DB
)
([]
Vino
,
error
)
{
...
...
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