ruanwenjun commented on issue #15183:
URL: 
https://github.com/apache/dolphinscheduler/issues/15183#issuecomment-1833398941

   > I encountered a new problem. If I want to divide Status, how should the 
**Status value()** at this annotation be handled?
   > 
   > ```java
   > @Retention(RUNTIME)
   > @Target(METHOD)
   > public @interface ApiException {
   >    Status value();
   > }
   > ```
   > 
   >  ```java
   > @Parameter(hidden = true)
   > @PostMapping(value = "/generate")
   > @ResponseStatus(HttpStatus.CREATED)
   > @ApiException(GENERATE_TOKEN_ERROR)
   > public Result<String> generateToken(@RequestAttribute(value = 
Constants.SESSION_USER) User loginUser,
   >                                                                    
@RequestParam(value = "userId") int userId,
   >                                                                    
@RequestParam(value = "expireTime") String expireTime) {
   >    String token = accessTokenService.generateToken(loginUser, userId, 
expireTime);
   >    return Result.success(token);
   > }
   > ```
   > 
   > It is easy to think of defining a new enumeration class in the interface
   > 
   > ```java
   > @Retention(RUNTIME)
   > @Target(METHOD)
   > public @interface ApiException {
   >    Status.ApiStatus value();
   > }
   > ```
   > 
   > But doing so will result in a lot of duplicate code
   
   ```
   public interface Status {
       String getCode();
       String getMsg();
   }
   
   public enum UserStatus implements Status {
        xx("USER-001", ""),
        ...
   }
   
   public enum ProjectStatus implements Status {
        xx("PROJECT-001", ""),
        ...
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to