-
Notifications
You must be signed in to change notification settings - Fork 2
/
revise_forum_topic_post.go
54 lines (45 loc) · 1.37 KB
/
revise_forum_topic_post.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
package forum
import (
"errors"
"github.com/kaikourok/lunchtote-backend/entity/model"
usecaseErrors "github.com/kaikourok/lunchtote-backend/usecase/errors"
"golang.org/x/crypto/bcrypt"
)
func (s *ForumUsecase) ReviseForumTopicPost(characterId *int, isAdministrator *bool, postId int, post *model.ForumTopicPostReviseData) error {
logger := s.registry.GetLogger()
repository := s.registry.GetRepository()
masterCharacter, editPassword, postType, err := repository.RetrieveForumTopicEditCredentials(postId)
if err != nil {
logger.Error(err)
return err
}
if postType != post.PostType {
return errors.New("投稿タイプが一致していません")
}
switch post.PostType {
case "ANONYMOUS":
if post.EditPassword == nil {
return usecaseErrors.ErrValidate
}
err = bcrypt.CompareHashAndPassword([]byte(*editPassword), []byte(*post.EditPassword))
if err != nil {
return usecaseErrors.ErrPermission
}
case "SIGNED_IN":
if characterId == nil || *characterId != *masterCharacter {
return usecaseErrors.ErrPermission
}
case "ADMINISTRATOR":
if isAdministrator == nil || !*isAdministrator {
return usecaseErrors.ErrPermission
}
default:
return errors.New("保存されているデータが正しくありません")
}
err = repository.ReviseForumTopicPost(characterId, postId, post)
if err != nil {
logger.Error(err)
return err
}
return nil
}