Property Group Label Translation und erste TreeView fertig
This commit is contained in:
@@ -31,7 +31,7 @@ func (lc PropertygroupsController) CreatePropertygroup(ctx *gin.Context) {
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
parent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId)
|
||||
parent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
@@ -90,7 +90,7 @@ func (lc PropertygroupsController) ChangePropertygroupParent(ctx *gin.Context) {
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
oldparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId)
|
||||
oldparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
@@ -102,7 +102,7 @@ func (lc PropertygroupsController) ChangePropertygroupParent(ctx *gin.Context) {
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
newparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId)
|
||||
newparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
@@ -148,13 +148,21 @@ func (lc PropertygroupsController) DeletePropertygroup(ctx *gin.Context) {
|
||||
|
||||
func (lc PropertygroupsController) GetPropertygroup(ctx *gin.Context) {
|
||||
PropertygroupId := ctx.Param("id")
|
||||
LangId := ctx.Param("langid")
|
||||
lId, err := strconv.Atoi(PropertygroupId)
|
||||
if err != nil {
|
||||
log.Println("Error PropertygroupId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
response, responseErr := lc.PropertygroupsService.GetPropertygroup(lId)
|
||||
languageId, err := strconv.Atoi(LangId)
|
||||
if err != nil {
|
||||
log.Println("Error LangId not int", err)
|
||||
ctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
response, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, languageId)
|
||||
if responseErr != nil {
|
||||
ctx.JSON(responseErr.Status, responseErr)
|
||||
return
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package models
|
||||
|
||||
type Propertygroup struct {
|
||||
ID int `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
SubPropertygroups []*Propertygroup `json:"subPropertygroups"`
|
||||
ID int `json:"id"`
|
||||
Label string `json:"label"`
|
||||
LabelTranslation string `json:"labelTranslation"`
|
||||
Description string `json:"description"`
|
||||
DescriptionTranslation string `json:"descriptionTranslationKey"`
|
||||
SubPropertygroups []*Propertygroup `json:"subPropertygroups"`
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ func (rr PropertygroupsRepository) DeletePropertygroup(PropertygroupId int) *mod
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int) (*models.Propertygroup, *models.ResponseError) {
|
||||
func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int, langId int) (*models.Propertygroup, *models.ResponseError) {
|
||||
|
||||
if pg, exists := rr.m[PropertygroupId]; exists {
|
||||
return pg, nil
|
||||
@@ -209,13 +209,45 @@ func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int) (*model
|
||||
}
|
||||
}
|
||||
|
||||
pg := &models.Propertygroup{
|
||||
ID: id,
|
||||
Label: label,
|
||||
Description: description,
|
||||
// translate label and description based on langId
|
||||
translation_query := `SELECT translation FROM property_group_translations WHERE property_group_id=$1 AND language_id=$2`
|
||||
translation_rows, err := rr.dbHandler.Query(translation_query, id, langId)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
err2 := rr.GetSubPropertygroups(pg)
|
||||
defer translation_rows.Close()
|
||||
var translation string
|
||||
for translation_rows.Next() {
|
||||
err := translation_rows.Scan(&translation)
|
||||
if err != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
}
|
||||
if translation_rows.Err() != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
if translation == "" {
|
||||
translation = label
|
||||
}
|
||||
pg := &models.Propertygroup{
|
||||
ID: id,
|
||||
Label: label,
|
||||
LabelTranslation: translation,
|
||||
Description: description,
|
||||
}
|
||||
|
||||
err2 := rr.GetSubPropertygroups(pg, langId)
|
||||
if err2 != nil {
|
||||
return nil, &models.ResponseError{
|
||||
Message: "Error reading sub propertygroups for propertygroup with id " + strconv.Itoa(pg.ID) + " : " + err2.Message,
|
||||
@@ -227,7 +259,7 @@ func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int) (*model
|
||||
return pg, nil
|
||||
}
|
||||
|
||||
func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Propertygroup) *models.ResponseError {
|
||||
func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Propertygroup, langId int) *models.ResponseError {
|
||||
query := `SELECT id FROM property_groups WHERE parent_property_group_id=$1`
|
||||
rows, err := rr.dbHandler.Query(query, Propertygroup.ID)
|
||||
if err != nil {
|
||||
@@ -255,7 +287,7 @@ func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Pr
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
pg, err2 := rr.GetPropertygroup(id)
|
||||
pg, err2 := rr.GetPropertygroup(id, langId)
|
||||
if err2 != nil {
|
||||
return &models.ResponseError{
|
||||
Message: "SubPropertygroup not found with the given id " + idstr,
|
||||
@@ -270,7 +302,7 @@ func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Pr
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return &models.ResponseError{
|
||||
Message: err.Error(),
|
||||
Message: rows.Err().Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
router.PUT("/propertygroup", propertygroupsController.UpdatePropertygroup)
|
||||
router.PUT("/propertygroup/:id/change-parent/:newparentid", propertygroupsController.ChangePropertygroupParent)
|
||||
router.DELETE("/propertygroup/:id", propertygroupsController.DeletePropertygroup)
|
||||
router.GET("/propertygroup/:id", propertygroupsController.GetPropertygroup)
|
||||
router.GET("/propertygroup/:id/lang/:langid", propertygroupsController.GetPropertygroup)
|
||||
|
||||
// server
|
||||
return HttpServer{
|
||||
|
||||
@@ -44,8 +44,8 @@ func (ls PropertygroupsService) DeletePropertygroup(PropertygroupId int) *models
|
||||
return ls.PropertygroupsRepository.DeletePropertygroup(PropertygroupId)
|
||||
}
|
||||
|
||||
func (ls PropertygroupsService) GetPropertygroup(PropertygroupId int) (*models.Propertygroup, *models.ResponseError) {
|
||||
return ls.PropertygroupsRepository.GetPropertygroup(PropertygroupId)
|
||||
func (ls PropertygroupsService) GetPropertygroup(PropertygroupId int, langId int) (*models.Propertygroup, *models.ResponseError) {
|
||||
return ls.PropertygroupsRepository.GetPropertygroup(PropertygroupId, langId)
|
||||
}
|
||||
|
||||
func validatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {
|
||||
|
||||
Reference in New Issue
Block a user