✨ Get myself current status API
This commit is contained in:
		
							
								
								
									
										10
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@@ -4,7 +4,11 @@
 | 
				
			|||||||
    <option name="autoReloadType" value="ALL" />
 | 
					    <option name="autoReloadType" value="ALL" />
 | 
				
			||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
  <component name="ChangeListManager">
 | 
					  <component name="ChangeListManager">
 | 
				
			||||||
    <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Edit, delete current status" />
 | 
					    <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix clear status affected the statutes cleared before">
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/index.go" afterDir="false" />
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/statuses_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/statuses_api.go" afterDir="false" />
 | 
				
			||||||
 | 
					    </list>
 | 
				
			||||||
    <option name="SHOW_DIALOG" value="false" />
 | 
					    <option name="SHOW_DIALOG" value="false" />
 | 
				
			||||||
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
					    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
				
			||||||
    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
 | 
					    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
 | 
				
			||||||
@@ -149,7 +153,6 @@
 | 
				
			|||||||
    </option>
 | 
					    </option>
 | 
				
			||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
  <component name="VcsManagerConfiguration">
 | 
					  <component name="VcsManagerConfiguration">
 | 
				
			||||||
    <MESSAGE value=":recycle: Improve code structure and much easier to read
:bug: Fix auth middleware" />
 | 
					 | 
				
			||||||
    <MESSAGE value=":bug: FIx cannot resolve service" />
 | 
					    <MESSAGE value=":bug: FIx cannot resolve service" />
 | 
				
			||||||
    <MESSAGE value=":sparkles: Accepts token in querystring" />
 | 
					    <MESSAGE value=":sparkles: Accepts token in querystring" />
 | 
				
			||||||
    <MESSAGE value=":bug: Fix registration service issue" />
 | 
					    <MESSAGE value=":bug: Fix registration service issue" />
 | 
				
			||||||
@@ -174,7 +177,8 @@
 | 
				
			|||||||
    <MESSAGE value=":bug: Fix online condition" />
 | 
					    <MESSAGE value=":bug: Fix online condition" />
 | 
				
			||||||
    <MESSAGE value=":sparkles: Last seen at" />
 | 
					    <MESSAGE value=":sparkles: Last seen at" />
 | 
				
			||||||
    <MESSAGE value=":sparkles: Edit, delete current status" />
 | 
					    <MESSAGE value=":sparkles: Edit, delete current status" />
 | 
				
			||||||
    <option name="LAST_COMMIT_MESSAGE" value=":sparkles: Edit, delete current status" />
 | 
					    <MESSAGE value=":bug: Fix clear status affected the statutes cleared before" />
 | 
				
			||||||
 | 
					    <option name="LAST_COMMIT_MESSAGE" value=":bug: Fix clear status affected the statutes cleared before" />
 | 
				
			||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
  <component name="VgoProject">
 | 
					  <component name="VgoProject">
 | 
				
			||||||
    <settings-migrated>true</settings-migrated>
 | 
					    <settings-migrated>true</settings-migrated>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,7 @@ func MapAPIs(app *fiber.App) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			me.Post("/confirm", doRegisterConfirm)
 | 
								me.Post("/confirm", doRegisterConfirm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								me.Get("/status", getStatus)
 | 
				
			||||||
			me.Post("/status", setStatus)
 | 
								me.Post("/status", setStatus)
 | 
				
			||||||
			me.Put("/status", editStatus)
 | 
								me.Put("/status", editStatus)
 | 
				
			||||||
			me.Delete("/status", clearStatus)
 | 
								me.Delete("/status", clearStatus)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,6 +33,24 @@ func getStatus(c *fiber.Ctx) error {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getMyselfStatus(c *fiber.Ctx) error {
 | 
				
			||||||
 | 
						user := c.Locals("user").(models.Account)
 | 
				
			||||||
 | 
						if err := exts.EnsureAuthenticated(c); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						status, err := services.GetStatus(user.ID)
 | 
				
			||||||
 | 
						disturbable := services.GetStatusDisturbable(user.ID) == nil
 | 
				
			||||||
 | 
						online := services.GetStatusOnline(user.ID) == nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return c.JSON(fiber.Map{
 | 
				
			||||||
 | 
							"status":         lo.Ternary(err == nil, &status, nil),
 | 
				
			||||||
 | 
							"last_seen_at":   user.Profile.LastSeenAt,
 | 
				
			||||||
 | 
							"is_disturbable": disturbable,
 | 
				
			||||||
 | 
							"is_online":      online,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func setStatus(c *fiber.Ctx) error {
 | 
					func setStatus(c *fiber.Ctx) error {
 | 
				
			||||||
	user := c.Locals("user").(models.Account)
 | 
						user := c.Locals("user").(models.Account)
 | 
				
			||||||
	if err := exts.EnsureAuthenticated(c); err != nil {
 | 
						if err := exts.EnsureAuthenticated(c); err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user