🚚 Rename daily-sign to check-in
This commit is contained in:
		
							
								
								
									
										11
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										11
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@@ -4,8 +4,13 @@
 | 
			
		||||
    <option name="autoReloadType" value="ALL" />
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="ChangeListManager">
 | 
			
		||||
    <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix group permission didn't extend properly">
 | 
			
		||||
    <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":mute: Remove authenticate result logging">
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/pkg/authkit/models/sign_record.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/authkit/models/check_in.go" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/pkg/internal/database/migrator.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/migrator.go" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/pkg/internal/http/api/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/index.go" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/pkg/internal/http/api/sign_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/check_in_api.go" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/pkg/internal/services/sign.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/check_in.go" afterDir="false" />
 | 
			
		||||
    </list>
 | 
			
		||||
    <option name="SHOW_DIALOG" value="false" />
 | 
			
		||||
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
			
		||||
@@ -158,7 +163,6 @@
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="VcsManagerConfiguration">
 | 
			
		||||
    <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
 | 
			
		||||
    <MESSAGE value="Revert ":recycle: Move models.Account to sec.UserInfo"

This reverts commit 8fbb7960" />
 | 
			
		||||
    <MESSAGE value=":rewind: Revert ":recycle: Move models.Account to sec.UserInfo" for a better solution

This reverts commit 8fbb7960" />
 | 
			
		||||
    <MESSAGE value=":truck: Update package name from Hypdrogen to Hypernet" />
 | 
			
		||||
    <MESSAGE value=":sparkles: Support users related rpc calls" />
 | 
			
		||||
@@ -183,7 +187,8 @@
 | 
			
		||||
    <MESSAGE value=":bug: Fix unable get user full perm node" />
 | 
			
		||||
    <MESSAGE value=":loud_sound: Add verbose permission logging" />
 | 
			
		||||
    <MESSAGE value=":bug: Fix group permission didn't extend properly" />
 | 
			
		||||
    <option name="LAST_COMMIT_MESSAGE" value=":bug: Fix group permission didn't extend properly" />
 | 
			
		||||
    <MESSAGE value=":mute: Remove authenticate result logging" />
 | 
			
		||||
    <option name="LAST_COMMIT_MESSAGE" value=":mute: Remove authenticate result logging" />
 | 
			
		||||
    <option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="VgoProject">
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
type SignRecord struct {
 | 
			
		||||
type CheckInRecord struct {
 | 
			
		||||
	BaseModel
 | 
			
		||||
 | 
			
		||||
	ResultTier       int     `json:"result_tier"`
 | 
			
		||||
@@ -25,7 +25,7 @@ var AutoMaintainRange = []any{
 | 
			
		||||
	&models.NotificationSubscriber{},
 | 
			
		||||
	&models.AuditRecord{},
 | 
			
		||||
	&models.ApiKey{},
 | 
			
		||||
	&models.SignRecord{},
 | 
			
		||||
	&models.CheckInRecord{},
 | 
			
		||||
	&models.PreferenceNotification{},
 | 
			
		||||
	&models.PreferenceAuth{},
 | 
			
		||||
	&models.AbuseReport{},
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func listDailySignRecord(c *fiber.Ctx) error {
 | 
			
		||||
func listCheckInRecord(c *fiber.Ctx) error {
 | 
			
		||||
	take := c.QueryInt("take", 0)
 | 
			
		||||
	offset := c.QueryInt("offset", 0)
 | 
			
		||||
 | 
			
		||||
@@ -20,13 +20,13 @@ func listDailySignRecord(c *fiber.Ctx) error {
 | 
			
		||||
 | 
			
		||||
	var count int64
 | 
			
		||||
	if err := database.C.
 | 
			
		||||
		Model(&models.SignRecord{}).
 | 
			
		||||
		Model(&models.CheckInRecord{}).
 | 
			
		||||
		Where("account_id = ?", user.ID).
 | 
			
		||||
		Count(&count).Error; err != nil {
 | 
			
		||||
		return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var records []models.SignRecord
 | 
			
		||||
	var records []models.CheckInRecord
 | 
			
		||||
	if err := database.C.
 | 
			
		||||
		Where("account_id = ?", user.ID).
 | 
			
		||||
		Limit(take).Offset(offset).
 | 
			
		||||
@@ -41,7 +41,7 @@ func listDailySignRecord(c *fiber.Ctx) error {
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func listOtherUserDailySignRecord(c *fiber.Ctx) error {
 | 
			
		||||
func listOtherUserCheckInRecord(c *fiber.Ctx) error {
 | 
			
		||||
	take := c.QueryInt("take", 0)
 | 
			
		||||
	offset := c.QueryInt("offset", 0)
 | 
			
		||||
 | 
			
		||||
@@ -56,13 +56,13 @@ func listOtherUserDailySignRecord(c *fiber.Ctx) error {
 | 
			
		||||
 | 
			
		||||
	var count int64
 | 
			
		||||
	if err := database.C.
 | 
			
		||||
		Model(&models.SignRecord{}).
 | 
			
		||||
		Model(&models.CheckInRecord{}).
 | 
			
		||||
		Where("account_id = ?", account.ID).
 | 
			
		||||
		Count(&count).Error; err != nil {
 | 
			
		||||
		return fiber.NewError(fiber.StatusInternalServerError, err.Error())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var records []models.SignRecord
 | 
			
		||||
	var records []models.CheckInRecord
 | 
			
		||||
	if err := database.C.
 | 
			
		||||
		Where("account_id = ?", account.ID).
 | 
			
		||||
		Limit(take).Offset(offset).
 | 
			
		||||
@@ -77,26 +77,26 @@ func listOtherUserDailySignRecord(c *fiber.Ctx) error {
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getTodayDailySign(c *fiber.Ctx) error {
 | 
			
		||||
func getTodayCheckIn(c *fiber.Ctx) error {
 | 
			
		||||
	if err := exts.EnsureAuthenticated(c); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	user := c.Locals("user").(models.Account)
 | 
			
		||||
 | 
			
		||||
	if record, err := services.GetTodayDailySign(user); err != nil {
 | 
			
		||||
	if record, err := services.GetTodayCheckIn(user); err != nil {
 | 
			
		||||
		return fiber.NewError(fiber.StatusNotFound, err.Error())
 | 
			
		||||
	} else {
 | 
			
		||||
		return c.JSON(record)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func doDailySign(c *fiber.Ctx) error {
 | 
			
		||||
func doCheckIn(c *fiber.Ctx) error {
 | 
			
		||||
	if err := exts.EnsureAuthenticated(c); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	user := c.Locals("user").(models.Account)
 | 
			
		||||
 | 
			
		||||
	if record, err := services.DailySign(user); err != nil {
 | 
			
		||||
	if record, err := services.CheckIn(user); err != nil {
 | 
			
		||||
		return fiber.NewError(fiber.StatusBadRequest, err.Error())
 | 
			
		||||
	} else {
 | 
			
		||||
		services.AddEvent(user.ID, "dailySign", strconv.Itoa(int(record.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
 | 
			
		||||
@@ -10,11 +10,11 @@ func MapAPIs(app *fiber.App, baseURL string) {
 | 
			
		||||
 | 
			
		||||
	api := app.Group(baseURL).Name("API")
 | 
			
		||||
	{
 | 
			
		||||
		daily := api.Group("/daily").Name("Daily Sign API")
 | 
			
		||||
		checkIn := api.Group("/check-in").Name("Daily Check In API")
 | 
			
		||||
		{
 | 
			
		||||
			daily.Get("/", listDailySignRecord)
 | 
			
		||||
			daily.Get("/today", getTodayDailySign)
 | 
			
		||||
			daily.Post("/", doDailySign)
 | 
			
		||||
			checkIn.Get("/", listCheckInRecord)
 | 
			
		||||
			checkIn.Get("/today", getTodayCheckIn)
 | 
			
		||||
			checkIn.Post("/", doCheckIn)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		notify := api.Group("/notifications").Name("Notifications API")
 | 
			
		||||
@@ -97,7 +97,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
 | 
			
		||||
			directory.Get("/", getOtherUserinfo)
 | 
			
		||||
			directory.Get("/status", getStatus)
 | 
			
		||||
 | 
			
		||||
			directory.Get("/daily", listOtherUserDailySignRecord)
 | 
			
		||||
			directory.Get("/check-in", listOtherUserCheckInRecord)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		api.Get("/users", getOtherUserinfoBatch)
 | 
			
		||||
 
 | 
			
		||||
@@ -11,10 +11,10 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func CheckDailyCanSign(user models.Account) error {
 | 
			
		||||
func CheckCanCheckIn(user models.Account) error {
 | 
			
		||||
	probe := time.Now().Format("2006-01-02")
 | 
			
		||||
 | 
			
		||||
	var record models.SignRecord
 | 
			
		||||
	var record models.CheckInRecord
 | 
			
		||||
	if err := database.C.Where("account_id = ? AND created_at::date = ?", user.ID, probe).First(&record).Error; err != nil {
 | 
			
		||||
		if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
			
		||||
			return nil
 | 
			
		||||
@@ -24,25 +24,25 @@ func CheckDailyCanSign(user models.Account) error {
 | 
			
		||||
	return fmt.Errorf("daliy sign record exists")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTodayDailySign(user models.Account) (models.SignRecord, error) {
 | 
			
		||||
func GetTodayCheckIn(user models.Account) (models.CheckInRecord, error) {
 | 
			
		||||
	probe := time.Now().Format("2006-01-02")
 | 
			
		||||
 | 
			
		||||
	var record models.SignRecord
 | 
			
		||||
	var record models.CheckInRecord
 | 
			
		||||
	if err := database.C.Where("account_id = ? AND created_at::date = ?", user.ID, probe).First(&record).Error; err != nil {
 | 
			
		||||
		return record, fmt.Errorf("unable get daliy sign record: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
	return record, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func DailySign(user models.Account) (models.SignRecord, error) {
 | 
			
		||||
func CheckIn(user models.Account) (models.CheckInRecord, error) {
 | 
			
		||||
	tier := rand.Intn(5)
 | 
			
		||||
	record := models.SignRecord{
 | 
			
		||||
	record := models.CheckInRecord{
 | 
			
		||||
		ResultTier:       tier,
 | 
			
		||||
		ResultExperience: rand.Intn(int(math.Max(float64(tier), 1)*100)+1-100) + 100,
 | 
			
		||||
		AccountID:        user.ID,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := CheckDailyCanSign(user); err != nil {
 | 
			
		||||
	if err := CheckCanCheckIn(user); err != nil {
 | 
			
		||||
		return record, fmt.Errorf("today already signed")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user