mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-13 03:13:41 +08:00
fix(goal): pin JSON wire form for GoalStatus to lowercase
This commit is contained in:
parent
746ade0410
commit
efce3bc209
@ -1,6 +1,8 @@
|
||||
package vip.mate.goal.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* Persistent goal lifecycle states.
|
||||
@ -35,10 +37,34 @@ public enum GoalStatus {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link JsonValue} pins the JSON-wire form to the same lowercase string
|
||||
* the DB stores via {@link EnumValue}. Without this, Jackson defaults to
|
||||
* {@link #name()} (uppercase) and the frontend's
|
||||
* {@code status: 'active' | 'paused' | ...} TS literal types reject
|
||||
* every payload — UI bug observed during PR4 manual QA.
|
||||
*/
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept both lowercase wire strings ("active") and uppercase Java
|
||||
* names ("ACTIVE") on the inbound path so client code that constructs
|
||||
* payloads either way doesn't 400.
|
||||
*/
|
||||
@JsonCreator
|
||||
public static GoalStatus fromJson(String raw) {
|
||||
if (raw == null) return null;
|
||||
for (GoalStatus s : values()) {
|
||||
if (s.value.equalsIgnoreCase(raw) || s.name().equalsIgnoreCase(raw)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown GoalStatus: " + raw);
|
||||
}
|
||||
|
||||
/** Terminal states do not transition; they free the conversation
|
||||
* uniqueness slot for a fresh active goal. */
|
||||
public boolean isTerminal() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user