本文整理汇总了Golang中github.com/almighty/almighty-core/application.Transactional函数的典型用法代码示例。如果您正苦于以下问题:Golang Transactional函数的具体用法?Golang Transactional怎么用?Golang Transactional使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Transactional函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Update
// Update runs the update action.
func (c *TrackerqueryController) Update(ctx *app.UpdateTrackerqueryContext) error {
result := application.Transactional(c.db, func(appl application.Application) error {
toSave := app.TrackerQuery{
ID: ctx.ID,
Query: ctx.Payload.Query,
Schedule: ctx.Payload.Schedule,
TrackerID: ctx.Payload.TrackerID,
}
tq, err := appl.TrackerQueries().Save(ctx.Context, toSave)
if err != nil {
cause := errs.Cause(err)
switch cause.(type) {
case remoteworkitem.BadParameterError, remoteworkitem.ConversionError:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return ctx.BadRequest(jerrors)
default:
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal(err.Error()))
return ctx.InternalServerError(jerrors)
}
}
return ctx.OK(tq)
})
c.scheduler.ScheduleAllQueries()
return result
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:28,代码来源:trackerquery.go
示例2: Create
// Create runs the create action.
func (c *SpaceController) Create(ctx *app.CreateSpaceContext) error {
_, err := login.ContextIdentity(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
}
err = validateCreateSpace(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return application.Transactional(c.db, func(appl application.Application) error {
reqSpace := ctx.Payload.Data
newSpace := space.Space{
Name: *reqSpace.Attributes.Name,
}
if reqSpace.Attributes.Description != nil {
newSpace.Description = *reqSpace.Attributes.Description
}
space, err := appl.Spaces().Create(ctx, &newSpace)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
res := &app.SpaceSingle{
Data: ConvertSpace(ctx.RequestData, space),
}
ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.RequestData, app.SpaceHref(res.Data.ID)))
return ctx.Created(res)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:32,代码来源:space.go
示例3: createSpaceAndIteration
func createSpaceAndIteration(t *testing.T, db *gormapplication.GormDB) iteration.Iteration {
var itr iteration.Iteration
application.Transactional(db, func(app application.Application) error {
repo := app.Iterations()
newSpace := space.Space{
Name: "Test 1" + uuid.NewV4().String(),
}
p, err := app.Spaces().Create(context.Background(), &newSpace)
if err != nil {
t.Error(err)
}
start := time.Now()
end := start.Add(time.Hour * (24 * 8 * 3))
name := "Sprint #2"
i := iteration.Iteration{
Name: name,
SpaceID: p.ID,
StartAt: &start,
EndAt: &end,
}
repo.Create(context.Background(), &i)
itr = i
return nil
})
return itr
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:28,代码来源:iteration_test.go
示例4: List
// List runs the list action.
func (c *SpaceIterationsController) List(ctx *app.ListSpaceIterationsContext) error {
spaceID, err := uuid.FromString(ctx.ID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
}
return application.Transactional(c.db, func(appl application.Application) error {
_, err = appl.Spaces().Load(ctx, spaceID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
}
iterations, err := appl.Iterations().List(ctx, spaceID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
// fetch extra information(counts of WI in each iteration of the space) to be added in response
wiCounts, err := appl.WorkItems().GetCountsPerIteration(ctx, spaceID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
res := &app.IterationList{}
res.Data = ConvertIterations(ctx.RequestData, iterations, UpdateIterationsWithCounts(wiCounts))
return ctx.OK(res)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:30,代码来源:space-iterations.go
示例5: TestSuccessCreateIterationWithOptionalValues
func (rest *TestSpaceIterationREST) TestSuccessCreateIterationWithOptionalValues() {
t := rest.T()
resource.Require(t, resource.Database)
var p *space.Space
iterationName := "Sprint #22"
iterationDesc := "testing description"
ci := createSpaceIteration(iterationName, &iterationDesc)
application.Transactional(rest.db, func(app application.Application) error {
repo := app.Spaces()
testSpace := space.Space{
Name: "Test 1",
}
p, _ = repo.Create(context.Background(), &testSpace)
return nil
})
svc, ctrl := rest.SecuredController()
_, c := test.CreateSpaceIterationsCreated(t, svc.Context, svc, ctrl, p.ID.String(), ci)
assert.NotNil(t, c.Data.ID)
assert.NotNil(t, c.Data.Relationships.Space)
assert.Equal(t, p.ID.String(), *c.Data.Relationships.Space.Data.ID)
assert.Equal(t, *c.Data.Attributes.Name, iterationName)
assert.Equal(t, *c.Data.Attributes.Description, iterationDesc)
// create another Iteration with nil description
iterationName2 := "Sprint #23"
ci = createSpaceIteration(iterationName2, nil)
_, c = test.CreateSpaceIterationsCreated(t, svc.Context, svc, ctrl, p.ID.String(), ci)
assert.Equal(t, *c.Data.Attributes.Name, iterationName2)
assert.Nil(t, c.Data.Attributes.Description)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:32,代码来源:space-iterations_test.go
示例6: Show
// Show returns the authorized user based on the provided Token
func (c *UserController) Show(ctx *app.ShowUserContext) error {
id, err := c.tokenManager.Locate(ctx)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return ctx.BadRequest(jerrors)
}
return application.Transactional(c.db, func(appl application.Application) error {
identity, err := appl.Identities().Load(ctx, id)
if err != nil || identity == nil {
log.Error(ctx, map[string]interface{}{
"identityID": id,
}, "auth token containers id %s of unknown Identity", id)
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrUnauthorized(fmt.Sprintf("Auth token contains id %s of unknown Identity\n", id)))
return ctx.Unauthorized(jerrors)
}
var user *account.User
userID := identity.UserID
if userID.Valid {
user, err = appl.Users().Load(ctx.Context, userID.UUID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, errors.Wrap(err, fmt.Sprintf("Can't load user with id %s", userID.UUID)))
}
}
return ctx.OK(ConvertUser(ctx.RequestData, identity, user))
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:30,代码来源:user.go
示例7: Create
// Create runs the create action.
func (c *WorkItemRelationshipsLinksController) Create(ctx *app.CreateWorkItemRelationshipsLinksContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
// Check that current work item does indeed exist
if _, err := appl.WorkItems().Load(ctx.Context, ctx.ID); err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
// Check that the source ID of the link is the same as the current work
// item ID.
src, _ := getSrcTgt(ctx.Payload.Data)
if src != nil && *src != ctx.ID {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(fmt.Sprintf("data.relationships.source.data.id is \"%s\" but must be \"%s\"", ctx.Payload.Data.Relationships.Source.Data.ID, ctx.ID)))
return ctx.BadRequest(jerrors)
}
// If no source is specified we pre-fill the source field of the payload
// with the current work item ID from the URL. This is for convenience.
if src == nil {
if ctx.Payload.Data.Relationships == nil {
ctx.Payload.Data.Relationships = &app.WorkItemLinkRelationships{}
}
if ctx.Payload.Data.Relationships.Source == nil {
ctx.Payload.Data.Relationships.Source = &app.RelationWorkItem{}
}
if ctx.Payload.Data.Relationships.Source.Data == nil {
ctx.Payload.Data.Relationships.Source.Data = &app.RelationWorkItemData{}
}
ctx.Payload.Data.Relationships.Source.Data.ID = ctx.ID
ctx.Payload.Data.Relationships.Source.Data.Type = link.EndpointWorkItems
}
return createWorkItemLink(newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, app.WorkItemLinkHref), ctx, ctx.Payload)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:33,代码来源:work-item-relationships-links.go
示例8: createTestData
func (tester *TestSearchSpaces) createTestData() ([]space.Space, error) {
names := []string{"TEST_A", "TEST_AB", "TEST_B", "TEST_C"}
for i := 0; i < 20; i++ {
names = append(names, "TEST_"+strconv.Itoa(i))
}
spaces := []space.Space{}
err := application.Transactional(tester.db, func(app application.Application) error {
for _, name := range names {
space := space.Space{
Name: name,
Description: strings.ToTitle("description for " + name),
}
newSpace, err := app.Spaces().Create(context.Background(), &space)
if err != nil {
return err
}
spaces = append(spaces, *newSpace)
}
return nil
})
if err != nil {
return nil, fmt.Errorf("Failed to insert testdata", err)
}
return spaces, nil
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:27,代码来源:search_spaces_blackbox_test.go
示例9: TestListCommentsByParentWorkItem
func (rest *TestCommentREST) TestListCommentsByParentWorkItem() {
// given
wiid := rest.createDefaultWorkItem()
application.Transactional(rest.db, func(app application.Application) error {
repo := app.Comments()
repo.Create(context.Background(), &comment.Comment{ParentID: wiid, Body: "Test 1", CreatedBy: uuid.NewV4()})
repo.Create(context.Background(), &comment.Comment{ParentID: wiid, Body: "Test 2", CreatedBy: uuid.NewV4()})
repo.Create(context.Background(), &comment.Comment{ParentID: wiid, Body: "Test 3", CreatedBy: uuid.NewV4()})
repo.Create(context.Background(), &comment.Comment{ParentID: wiid + "_other", Body: "Test 1", CreatedBy: uuid.NewV4()})
return nil
})
// when
svc, ctrl := rest.UnSecuredController()
offset := "0"
limit := 3
_, cs := test.ListWorkItemCommentsOK(rest.T(), svc.Context, svc, ctrl, wiid, &limit, &offset)
// then
require.Equal(rest.T(), 3, len(cs.Data))
rest.assertComment(cs.Data[0], "Test 3", rendering.SystemMarkupDefault) // items are returned in reverse order or creation
// given
wiid2 := rest.createDefaultWorkItem()
// when
_, cs2 := test.ListWorkItemCommentsOK(rest.T(), svc.Context, svc, ctrl, wiid2, &limit, &offset)
// then
assert.Equal(rest.T(), 0, len(cs2.Data))
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:26,代码来源:work-item-comments_test.go
示例10: Create
// Create runs the create action.
func (c *WorkItemLinkTypeController) Create(ctx *app.CreateWorkItemLinkTypeContext) error {
// WorkItemLinkTypeController_Create: start_implement
// Convert payload from app to model representation
model := link.WorkItemLinkType{}
in := app.WorkItemLinkTypeSingle{
Data: ctx.Payload.Data,
}
err := link.ConvertLinkTypeToModel(in, &model)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
return ctx.BadRequest(jerrors)
}
return application.Transactional(c.db, func(appl application.Application) error {
linkType, err := appl.WorkItemLinkTypes().Create(ctx.Context, model.Name, model.Description, model.SourceTypeName, model.TargetTypeName, model.ForwardName, model.ReverseName, model.Topology, model.LinkCategoryID)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
// Enrich
linkCtx := newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, app.WorkItemLinkTypeHref)
err = enrichLinkTypeSingle(linkCtx, linkType)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal("Failed to enrich link type: %s", err.Error()))
return ctx.InternalServerError(jerrors)
}
ctx.ResponseData.Header().Set("Location", app.WorkItemLinkTypeHref(linkType.Data.ID))
return ctx.Created(linkType)
})
// WorkItemLinkTypeController_Create: end_implement
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:31,代码来源:work-item-link-type.go
示例11: Update
// Update does PATCH workitem
func (c *WorkitemController) Update(ctx *app.UpdateWorkitemContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
if ctx.Payload == nil || ctx.Payload.Data == nil || ctx.Payload.Data.ID == nil {
return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("missing data.ID element in request", nil))
}
wi, err := appl.WorkItems().Load(ctx, *ctx.Payload.Data.ID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, fmt.Sprintf("Failed to load work item with id %v", *ctx.Payload.Data.ID)))
}
// Type changes of WI are not allowed which is why we overwrite it the
// type with the old one after the WI has been converted.
oldType := wi.Type
err = ConvertJSONAPIToWorkItem(appl, *ctx.Payload.Data, wi)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
wi.Type = oldType
wi, err = appl.WorkItems().Save(ctx, *wi)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "Error updating work item"))
}
wi2 := ConvertWorkItem(ctx.RequestData, wi)
resp := &app.WorkItem2Single{
Data: wi2,
Links: &app.WorkItemLinks{
Self: buildAbsoluteURL(ctx.RequestData),
},
}
return ctx.OK(resp)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:32,代码来源:workitem.go
示例12: Update
// Update does PATCH comment
func (c *CommentsController) Update(ctx *app.UpdateCommentsContext) error {
identity, err := login.ContextIdentity(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
}
return application.Transactional(c.db, func(appl application.Application) error {
cm, err := appl.Comments().Load(ctx.Context, ctx.CommentID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
if identity != cm.CreatedBy.String() {
// need to use the goa.NewErrorClass() func as there is no native support for 403 in goa
// and it is not planned to be supported yet: https://github.com/goadesign/goa/pull/1030
return jsonapi.JSONErrorResponse(ctx, goa.NewErrorClass("forbidden", 403)("User is not the comment author"))
}
cm.Body = *ctx.Payload.Data.Attributes.Body
cm.Markup = rendering.NilSafeGetMarkup(ctx.Payload.Data.Attributes.Markup)
cm, err = appl.Comments().Save(ctx.Context, cm)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
res := &app.CommentSingle{
Data: ConvertComment(ctx.RequestData, cm, CommentIncludeParentWorkItem()),
}
return ctx.OK(res)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:32,代码来源:comments.go
示例13: Show
// Show runs the show action.
func (c *WorkitemtypeController) Show(ctx *app.ShowWorkitemtypeContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
res, err := appl.WorkItemTypes().Load(ctx.Context, ctx.Name)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return ctx.OK(res)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:10,代码来源:workitemtype.go
示例14: TestListAreas
func (rest *TestSpaceAreaREST) TestListAreas() {
t := rest.T()
resource.Require(t, resource.Database)
// Create a new space where we'll create 3 areas
var s *space.Space
// Create another space where we'll create 1 area.
var anotherSpace *space.Space
application.Transactional(rest.db, func(app application.Application) error {
var err error
repo := app.Spaces()
newSpace := &space.Space{
Name: "Test Space 1" + uuid.NewV4().String(),
}
s, err = repo.Create(context.Background(), newSpace)
require.Nil(t, err)
newSpace = &space.Space{
Name: "Another space" + uuid.NewV4().String(),
}
anotherSpace, err = repo.Create(context.Background(), newSpace)
require.Nil(t, err)
return nil
})
svc, ctrl := rest.SecuredController()
spaceId := s.ID
anotherSpaceId := anotherSpace.ID
var createdAreaUuids1 []uuid.UUID
for i := 0; i < 3; i++ {
name := "Test Area #20" + strconv.Itoa(i)
spaceAreaContext := createSpaceArea(name, &name)
_, c := test.CreateSpaceAreasCreated(t, svc.Context, svc, ctrl, spaceId.String(), spaceAreaContext)
require.NotNil(t, c.Data.ID)
require.NotNil(t, c.Data.Relationships.Space)
createdAreaUuids1 = append(createdAreaUuids1, *c.Data.ID)
}
name := "area in a different space"
anotherSpaceAreaContext := createSpaceArea(name, &name)
_, createdArea := test.CreateSpaceAreasCreated(t, svc.Context, svc, ctrl, anotherSpaceId.String(), anotherSpaceAreaContext)
require.NotNil(t, createdArea)
_, areaList := test.ListSpaceAreasOK(t, svc.Context, svc, ctrl, spaceId.String())
assert.Len(t, areaList.Data, 3)
for i := 0; i < len(createdAreaUuids1); i++ {
assert.NotNil(t, searchInAreaSlice(createdAreaUuids1[i], areaList))
}
_, anotherAreaList := test.ListSpaceAreasOK(t, svc.Context, svc, ctrl, anotherSpaceId.String())
assert.Len(t, anotherAreaList.Data, 1)
assert.Equal(t, anotherAreaList.Data[0].ID, createdArea.Data.ID)
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:57,代码来源:space-areas_test.go
示例15: List
// List runs the list action.
func (c *IdentityController) List(ctx *app.ListIdentityContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
result, err := appl.Identities().List(ctx.Context)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal(fmt.Sprintf("Error listing identities: %s", err.Error())))
return ctx.InternalServerError(jerrors)
}
return ctx.OK(result)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:11,代码来源:identity.go
示例16: Delete
// Delete runs the delete action.
func (c *WorkItemLinkCategoryController) Delete(ctx *app.DeleteWorkItemLinkCategoryContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
err := appl.WorkItemLinkCategories().Delete(ctx.Context, ctx.ID)
if err != nil {
jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
}
return ctx.OK([]byte{})
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:11,代码来源:work-item-link-category.go
示例17: Delete
// Delete does DELETE workitem
func (c *WorkitemController) Delete(ctx *app.DeleteWorkitemContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
err := appl.WorkItems().Delete(ctx, ctx.ID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, errs.Wrapf(err, "error deleting work item %s", ctx.ID))
}
if err := appl.WorkItemLinks().DeleteRelatedLinks(ctx, ctx.ID); err != nil {
return jsonapi.JSONErrorResponse(ctx, errs.Wrapf(err, "failed to delete work item links related to work item %s", ctx.ID))
}
return ctx.OK([]byte{})
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:13,代码来源:workitem.go
示例18: Show
// Show does GET workitem
func (c *WorkitemController) Show(ctx *app.ShowWorkitemContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
comments := WorkItemIncludeCommentsAndTotal(ctx, c.db, ctx.ID)
wi, err := appl.WorkItems().Load(ctx, ctx.ID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, fmt.Sprintf("Fail to load work item with id %v", ctx.ID)))
}
wi2 := ConvertWorkItem(ctx.RequestData, wi, comments)
resp := &app.WorkItem2Single{
Data: wi2,
}
return ctx.OK(resp)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:15,代码来源:workitem.go
示例19: List
// List runs the list action.
func (c *UsersController) List(ctx *app.ListUsersContext) error {
return application.Transactional(c.db, func(appl application.Application) error {
var err error
var users []*account.User
var result *app.UserArray
users, err = appl.Users().List(ctx.Context)
if err == nil {
result, err = LoadKeyCloakIdentities(appl, ctx.RequestData, users)
if err == nil {
return ctx.OK(result)
}
}
return jsonapi.JSONErrorResponse(ctx, errors.Wrap(err, "Error listing users"))
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:16,代码来源:users.go
示例20: List
// List runs the list action
func (c *WorkitemtypeController) List(ctx *app.ListWorkitemtypeContext) error {
start, limit, err := parseLimit(ctx.Page)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(fmt.Sprintf("could not parse paging: %s", err.Error())))
return ctx.BadRequest(jerrors)
}
return application.Transactional(c.db, func(appl application.Application) error {
result, err := appl.WorkItemTypes().List(ctx.Context, start, &limit)
if err != nil {
jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(fmt.Sprintf("Error listing work item types: %s", err.Error())))
return ctx.BadRequest(jerrors)
}
return ctx.OK(result)
})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:16,代码来源:workitemtype.go
注:本文中的github.com/almighty/almighty-core/application.Transactional函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论