Skip to content

Commit

Permalink
불필요한 함수 제거함.
Browse files Browse the repository at this point in the history
  • Loading branch information
khw7096 committed Feb 25, 2024
1 parent d470ee5 commit b700d5d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 195 deletions.
61 changes: 0 additions & 61 deletions assets/js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -4353,9 +4353,6 @@ function addReviewStatusMode() {
});
}

function clickCommentButton() {
addReviewComment()
}

function clickReviewStatusModeCommentButton() {
addReviewStatusModeComment()
Expand Down Expand Up @@ -4680,64 +4677,6 @@ function setReviewName() {
}


function addReviewComment() {
$.ajax({
url: "/api/addreviewcomment",
type: "POST",
data: {
id: document.getElementById("current-review-id").value,
text: document.getElementById("review-comment").value,
media: document.getElementById("review-media").value,
frame: document.getElementById("currentframe").innerHTML,
framecomment: document.getElementById("review-framecomment").checked,
},
headers: {
"Authorization": "Basic "+ document.getElementById("token").value
},
dataType: "json",
success: function(data) {
// 데이터가 잘 들어가면 review-comments 에 들어간 데이터를 드로잉한다.
let body = data.text.replace(/(?:\r\n|\r|\n)/g, '<br>');
let newComment = `<div id="reviewcomment-${data.id}-${data.date}" class="p-1">
<span class="text-badge">${data.date} / <a href="/user?id=${data.author}" class="text-darkmode">${data.authorname}</a></span>
<span class="edit" data-toggle="modal" data-target="#modal-editreviewcomment" onclick="setEditReviewCommentModal('${data.id}', '${data.date}')">≡</span>
<span class="remove" data-toggle="modal" data-target="#modal-rmreviewcomment" onclick="setRmReviewCommentModal('${data.id}','${data.date}')">×</span>
<br>
`
if (data.framecomment) {
newComment += `<span class="badge badge-secondary m-1 finger" id="reviewcomment-${data.id}-${data.date}-frame" data-toggle="modal" data-target="#modal-gotoframe" onclick="setModalGotoFrame()">${data.frame}f / ${data.frame+data.productionstartframe-1}f</span>`
}
newComment += `<small class="text-white">${body}</small>`
if (data.media != "") {
if (data.media.includes("http")) {
newComment += `<div class="row pl-3 pt-3 pb-1">
<a href="${data.media}" onclick="copyClipboard('${data.media}')">
<img src="/assets/img/link.svg" class="finger">
</a>
<span class="text-white pl-2 small">${data.mediatitle}</span>
</div>`
} else {
newComment += `<div class="row pl-3 pt-3 pb-1">
<a href="${data.protocol}://${data.media}" onclick="copyClipboard('${data.media}')">
<img src="/assets/img/link.svg" class="finger">
</a>
<span class="text-white pl-2 small">${data.mediatitle}</span>
</div>`
}
}
newComment += `<hr class="my-1 p-0 m-0 divider"></hr></div>`
document.getElementById("review-comments").innerHTML = newComment + document.getElementById("review-comments").innerHTML;
// 입력한 값을 초기화 한다.
document.getElementById("review-comment").value = "";
document.getElementById("review-media").value = "";
document.getElementById("review-framecomment").checked = false;
},
error: function(request,status,error){
alert("code:"+request.status+"\n"+"status:"+status+"\n"+"msg:"+request.responseText+"\n"+"error:"+error);
}
});
}




Expand Down
43 changes: 43 additions & 0 deletions db_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,46 @@ func addReviewCommentV2(client *mongo.Client, id string, cmt Comment) error {
}
return nil
}

func EditReviewCommentV2(client *mongo.Client, id, date, text, media string, frame int) error {

reviewItem, err := getReviewV2(client, id)
if err != nil {
return err
}
var newComments []Comment
for _, comment := range reviewItem.Comments {
if comment.Date == date {
comment.Text = text
comment.Media = media
comment.Frame = frame
}
newComments = append(newComments, comment)
}
reviewItem.Comments = newComments
err = setReviewItemV2(client, reviewItem)
if err != nil {
return err
}
return nil
}

func RmReviewCommentV2(client *mongo.Client, id, date string) error {
reviewItem, err := getReviewV2(client, id)
if err != nil {
return err
}
var newComments []Comment
for _, comment := range reviewItem.Comments {
if comment.Date == date {
continue
}
newComments = append(newComments, comment)
}
reviewItem.Comments = newComments
err = setReviewItemV2(client, reviewItem)
if err != nil {
return err
}
return nil
}
5 changes: 2 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,9 @@ func webserver(port string) {
r.HandleFunc("/api/review", handleAPIReview).Methods("POST")
r.HandleFunc("/api/searchreview", handleAPISearchReview)
r.HandleFunc("/api/setreviewitemstatus", handleAPISetReviewItemStatus).Methods("POST")
r.HandleFunc("/api/addreviewcomment", handleAPIAddReviewComment)
r.HandleFunc("/api/addreviewstatusmodecomment", handleAPIAddReviewStatusModeComment).Methods("POST")
r.HandleFunc("/api/editreviewcomment", handleAPIEditReviewComment)
r.HandleFunc("/api/rmreviewcomment", handleAPIRmReviewComment)
r.HandleFunc("/api/editreviewcomment", handleAPIEditReviewComment).Methods("POST")
r.HandleFunc("/api/rmreviewcomment", handleAPIRmReviewComment).Methods("POST")
r.HandleFunc("/api/rmreview", handleAPIRmReview)
r.HandleFunc("/api/setreviewproject", handleAPISetReviewProject)
r.HandleFunc("/api/setreviewtask", handleAPISetReviewTask)
Expand Down
140 changes: 9 additions & 131 deletions restapiReview.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,113 +312,6 @@ func handleAPISetReviewItemStatus(w http.ResponseWriter, r *http.Request) {
w.Write(data)
}

// handleAPIAddReviewComment 함수는 review에 comment를 설정하는 RestAPI 이다.
func handleAPIAddReviewComment(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Post Only", http.StatusMethodNotAllowed)
return
}
type Recipe struct {
UserID string `json:"userid"`
ID string `json:"id"`
Text string `json:"text"`
Media string `json:"media"`
MediaTitle string `json:"mediatitle"`
Author string `json:"author"`
AuthorName string `json:"authorname"`
Date string `json:"date"`
Frame int `json:"frame"`
FrameComment bool `json:"framecomment"`
ProductionStartFrame int `json:"productionstartframe"` // UX 를 그릴 때 필요하다.
Protocol string `json:"protocol"`
}
rcp := Recipe{}
rcp.Protocol = CachedAdminSetting.Protocol
rcp.ProductionStartFrame = CachedAdminSetting.ProductionStartFrame
session, err := mgo.Dial(*flagDBIP)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer session.Close()
rcp.UserID, _, err = TokenHandler(r, session)
if err != nil {
http.Error(w, err.Error(), http.StatusUnauthorized)
return
}
_, _, err = net.SplitHostPort(r.RemoteAddr)
if err != nil {
http.Error(w, err.Error(), http.StatusUnauthorized)
return
}
// 사용자의 이름을 구한다.
u, err := getUser(session, rcp.UserID)
if err != nil {
http.Error(w, err.Error(), http.StatusUnauthorized) // 사용자가 존재하지 않으면 당연히 Comment를 작성하면 안된다.
return
}
rcp.AuthorName = u.LastNameKor + u.FirstNameKor
r.ParseForm()
id := r.FormValue("id")
if id == "" {
http.Error(w, "need id", http.StatusBadRequest)
return
}
rcp.ID = id
rcp.Text = r.FormValue("text")
rcp.Media = r.FormValue("media")
if rcp.Text == "" && rcp.Media == "" {
http.Error(w, "comment(text) 또는 첨부파일(media) 값 둘중 하나는 반드시 입력되어야 합니다", http.StatusBadRequest)
return
}
rcp.MediaTitle = r.FormValue("mediatitle")

review, err := getReview(session, rcp.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
rcp.FrameComment = str2bool(r.FormValue("framecomment"))
frame, err := strconv.Atoi(r.FormValue("frame"))
if err != nil {
frame = 0
}
if rcp.FrameComment {
rcp.Frame = frame
}
cmt := Comment{}
cmt.Date = time.Now().Format(time.RFC3339)
rcp.Date = cmt.Date
cmt.Author = rcp.UserID
rcp.Author = rcp.UserID
cmt.AuthorName = rcp.AuthorName
cmt.Text = rcp.Text
cmt.Media = rcp.Media
cmt.MediaTitle = rcp.MediaTitle
cmt.Frame = rcp.Frame

err = addReviewComment(session, rcp.ID, cmt)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// slack log
err = slacklog(session, review.Project, fmt.Sprintf("Add Review Comment: %s, \nProject: %s, Name: %s, Author: %s", rcp.Text, review.Project, review.Name, rcp.UserID))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

data, err := json.Marshal(rcp)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write(data)
}

// handleAPIAddReviewStatusModeComment 함수는 review status mode에서 comment를 설정하는 RestAPI 이다.
func handleAPIAddReviewStatusModeComment(w http.ResponseWriter, r *http.Request) {
type Recipe struct {
Expand Down Expand Up @@ -530,10 +423,6 @@ func handleAPIAddReviewStatusModeComment(w http.ResponseWriter, r *http.Request)

// handleAPIEditReviewComment 함수는 리뷰에서 코멘트를 수정합니다.
func handleAPIEditReviewComment(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Post Only", http.StatusMethodNotAllowed)
return
}
type Recipe struct {
ID string `json:"id"`
Time string `json:"time"`
Expand All @@ -547,13 +436,13 @@ func handleAPIEditReviewComment(w http.ResponseWriter, r *http.Request) {
rcp := Recipe{}
rcp.Protocol = CachedAdminSetting.Protocol
rcp.ProductionStartFrame = CachedAdminSetting.ProductionStartFrame
session, err := mgo.Dial(*flagDBIP)
client, err := initMongoClient()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer session.Close()
rcp.UserID, _, err = TokenHandler(r, session)
defer client.Disconnect(context.Background())
rcp.UserID, _, err = TokenHandlerV2(r, client)
if err != nil {
http.Error(w, err.Error(), http.StatusUnauthorized)
return
Expand Down Expand Up @@ -585,7 +474,7 @@ func handleAPIEditReviewComment(w http.ResponseWriter, r *http.Request) {
return
}
rcp.Frame = frame
err = EditReviewComment(session, rcp.ID, rcp.Time, rcp.Text, rcp.Media, rcp.Frame)
err = EditReviewCommentV2(client, rcp.ID, rcp.Time, rcp.Text, rcp.Media, rcp.Frame)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -603,10 +492,6 @@ func handleAPIEditReviewComment(w http.ResponseWriter, r *http.Request) {

// handleAPIRmReviewComment 함수는 리뷰에서 수정사항을 삭제합니다.
func handleAPIRmReviewComment(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Post Only", http.StatusMethodNotAllowed)
return
}
type Recipe struct {
ID string `json:"id"`
Time string `json:"time"`
Expand All @@ -616,13 +501,13 @@ func handleAPIRmReviewComment(w http.ResponseWriter, r *http.Request) {
UserID string `json:"userid"`
}
rcp := Recipe{}
session, err := mgo.Dial(*flagDBIP)
client, err := initMongoClient()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer session.Close()
rcp.UserID, _, err = TokenHandler(r, session)
defer client.Disconnect(context.Background())
rcp.UserID, _, err = TokenHandlerV2(r, client)
if err != nil {
http.Error(w, err.Error(), http.StatusUnauthorized)
return
Expand All @@ -647,7 +532,7 @@ func handleAPIRmReviewComment(w http.ResponseWriter, r *http.Request) {
rcp.Time = reviewTime

// ID를 이용해서 삭제할 리뷰아이템을 가져와 Project, Name, Text를 반환될 json에 설정합니다.
review, err := getReview(session, rcp.ID)
review, err := getReviewV2(client, rcp.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -662,14 +547,7 @@ func handleAPIRmReviewComment(w http.ResponseWriter, r *http.Request) {
}

// 리뷰데이터를 삭제합니다.
err = RmReviewComment(session, rcp.ID, rcp.Time)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// slack log
err = slacklog(session, rcp.Project, fmt.Sprintf("Rm Review Comment: %s\nProject: %s, Name: %s, Author: %s", rcp.Text, rcp.Project, rcp.Name, rcp.UserID))
err = RmReviewCommentV2(client, rcp.ID, rcp.Time)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit b700d5d

Please sign in to comment.