-
Notifications
You must be signed in to change notification settings - Fork 0
/
terms_of_service.go
67 lines (58 loc) · 2.3 KB
/
terms_of_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"errors"
"net/http"
"github.com/zgordan-vv/zacmm-server/model"
"github.com/zgordan-vv/zacmm-server/store"
)
func (a *App) CreateTermsOfService(text, userId string) (*model.TermsOfService, *model.AppError) {
termsOfService := &model.TermsOfService{
Text: text,
UserId: userId,
}
if _, appErr := a.GetUser(userId); appErr != nil {
return nil, appErr
}
var err error
if termsOfService, err = a.Srv().Store.TermsOfService().Save(termsOfService); err != nil {
var invErr *store.ErrInvalidInput
var appErr *model.AppError
switch {
case errors.As(err, &invErr):
return nil, model.NewAppError("CreateTermsOfService", "app.terms_of_service.create.existing.app_error", nil, "id="+termsOfService.Id, http.StatusBadRequest)
case errors.As(err, &appErr):
return nil, appErr
default:
return nil, model.NewAppError("CreateTermsOfService", "app.terms_of_service.create.app_error", nil, "terms_of_service_id="+termsOfService.Id+",err="+err.Error(), http.StatusInternalServerError)
}
}
return termsOfService, nil
}
func (a *App) GetLatestTermsOfService() (*model.TermsOfService, *model.AppError) {
termsOfService, err := a.Srv().Store.TermsOfService().GetLatest(true)
if err != nil {
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("GetLatestTermsOfService", "app.terms_of_service.get.no_rows.app_error", nil, "err="+err.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("GetLatestTermsOfService", "app.terms_of_service.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
}
}
return termsOfService, nil
}
func (a *App) GetTermsOfService(id string) (*model.TermsOfService, *model.AppError) {
termsOfService, err := a.Srv().Store.TermsOfService().Get(id, true)
if err != nil {
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("GetTermsOfService", "app.terms_of_service.get.no_rows.app_error", nil, "", http.StatusNotFound)
default:
return nil, model.NewAppError("GetTermsOfService", "app.terms_of_service.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
}
}
return termsOfService, nil
}