Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: chat update the interface params (#98)
Browse files Browse the repository at this point in the history
* fix:transform type of action_type to int64

* feat:add the coverage test file

* fix: golangci-lint problem

* fix:update the interface params
  • Loading branch information
XZ0730 authored Aug 28, 2023
1 parent 1d321c1 commit ecb8ada
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 320 deletions.
2 changes: 1 addition & 1 deletion cmd/chat/dal/mq/chat_mq.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func convertForMysql(message *cache.Message, tempMessage *MiddleMessage) (err er
message.ToUserId = tempMessage.ToUserId
message.FromUserId = tempMessage.FromUserId
message.Content = tempMessage.Content
message.CreatedAt, err = time.Parse(time.DateTime, tempMessage.CreatedAt)
message.CreatedAt, err = time.Parse(time.RFC3339, tempMessage.CreatedAt)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/chat/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"time"

pack "github.com/ozline/tiktok/cmd/chat/pack"
service "github.com/ozline/tiktok/cmd/chat/service"
Expand All @@ -16,13 +17,13 @@ type MessageServiceImpl struct{}
// MessagePost implements the MessageServiceImpl interface.
func (s *MessageServiceImpl) MessagePost(ctx context.Context, req *chat.MessagePostRequest) (resp *chat.MessagePostReponse, err error) {
resp = new(chat.MessagePostReponse)
_, err = utils.CheckToken(req.Token)
claim, err := utils.CheckToken(req.Token)
if err != nil {
resp.Base = pack.BuildBaseResp(errno.AuthorizationFailedError)
return resp, nil
}

err = service.NewChatService(ctx).SendMessage(req)
err = service.NewChatService(ctx).SendMessage(req, claim.UserId, time.Now().Format(time.RFC3339))
if err != nil {
resp.Base = pack.BuildBaseResp(err)
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/chat/service/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package service
import (
"context"
"testing"
"time"

"github.com/ozline/tiktok/cmd/chat/dal"
"github.com/ozline/tiktok/config"
)

var chatservice *ChatService
var (
chatservice *ChatService
create_at string = time.Now().Format(time.RFC3339)
ac_type int64 = 1
)

const (
content string = "cover test"
Expand Down
9 changes: 3 additions & 6 deletions cmd/chat/service/post_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ func testPostMessage(t *testing.T) {
if err != nil {
klog.Info(err)
}
now := time.Now().Format(time.DateTime)
req := &chat.MessagePostRequest{
Token: token,
FromUserId: from_user_id,
ToUserId: to_user_id,
Content: content,
CreateTime: &now,
ActionType: &ac_type,
}
err = chatservice.SendMessage(req)
err = chatservice.SendMessage(req, from_user_id, create_at)
if err != nil {
t.Error(err)
t.Fail()
}
req.FromUserId = to_user_id
req.ToUserId = from_user_id
err = chatservice.SendMessage(req)
err = chatservice.SendMessage(req, to_user_id, create_at)
if err != nil {
t.Error(err)
t.Fail()
Expand Down
6 changes: 3 additions & 3 deletions cmd/chat/service/send_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"github.com/ozline/tiktok/kitex_gen/chat"
)

func (c *ChatService) SendMessage(req *chat.MessagePostRequest) error {
func (c *ChatService) SendMessage(req *chat.MessagePostRequest, user_id int64, create_at string) error {
if len(req.Content) == 0 || len(req.Content) > 1000 {
return errors.New("character limit error")
}
message := &mq.MiddleMessage{
Id: db.SF.NextVal(),
ToUserId: req.ToUserId,
FromUserId: req.FromUserId,
FromUserId: user_id,
Content: req.Content,
CreatedAt: *req.CreateTime,
CreatedAt: create_at,
}
trans_message, err := sonic.Marshal(message)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions idl/chat.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ struct Message {
struct MessagePostRequest {
1: required string token
2: required i64 to_user_id
3: required i64 from_user_id,
4: required string content,
5: optional string create_time,
6: optional i64 action_type,
3: required string content,
4:optional i64 action_type,
}

struct MessagePostReponse {
Expand Down
Loading

0 comments on commit ecb8ada

Please sign in to comment.