-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete_forum_topic_post.go
49 lines (41 loc) · 1.18 KB
/
delete_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
package forum
import (
"errors"
usecaseErrors "github.com/kaikourok/lunchtote-backend/usecase/errors"
"golang.org/x/crypto/bcrypt"
)
func (s *ForumUsecase) DeleteForumTopicPost(characterId *int, isAdministrator *bool, postId int, editPassword *string) error {
logger := s.registry.GetLogger()
repository := s.registry.GetRepository()
masterCharacter, savedPassword, postType, err := repository.RetrieveForumTopicEditCredentials(postId)
if err != nil {
logger.Error(err)
return err
}
switch postType {
case "ANONYMOUS":
if editPassword == nil {
return usecaseErrors.ErrValidate
}
err = bcrypt.CompareHashAndPassword([]byte(*savedPassword), []byte(*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.DeleteForumTopicPost(characterId, postId)
if err != nil {
logger.Error(err)
return err
}
return nil
}