A promise to customers
Wedding photos are the studio's best marketing, and they're also someone's private day. Posting a couple's photos on the studio's Instagram without asking is a quick way to lose their trust. Asking over WhatsApp works until it doesn't: "she said yes to the reel, I think?", or the version that went live isn't the one they saw.
So the rule is simple: nothing from a booking goes on the studio's Instagram until the customer has approved exactly that post. This post is about turning that sentence into code that can't be broken by accident. It's a good first example of a state machine: a thing that is always in exactly one state, with a fixed list of ways to move between states.
The states
A post has six states:
DRAFT -> PENDING_APPROVAL -> APPROVED -> POSTED
| |
+-> CHANGES_REQUESTED / DECLINED (studio reworks it and sends it again)- DRAFT: the studio is building it: caption, photos, videos, format (post, reel or story).
- PENDING_APPROVAL: sent to the customer, waiting for a decision.
- APPROVED: the customer said yes.
- CHANGES_REQUESTED: the customer wants something changed.
- DECLINED: the customer said no.
- POSTED: it's live, with its Instagram link recorded.
The rules live on the state enum itself, as three questions:
/** The studio can change the caption and media. */
public boolean studioEditable() {
return this == DRAFT || this == CHANGES_REQUESTED || this == DECLINED;
}
/** The customer can still approve, decline or ask for changes - including
* changing their mind about an approval, up until the post goes live. */
public boolean customerDecidable() {
return this == PENDING_APPROVAL || this == APPROVED;
}
/** The customer has seen it (it was sent at least once and not withdrawn). */
public boolean visibleToCustomer() {
return this != DRAFT;
}Every action in SocialPostService starts by asking one of these. That keeps the rules in one place: if we ever add a state, the compiler won't remind us, but these three methods are the only place to look.
The rule that makes approval mean something
Here's the subtle part. Suppose the customer approves a carousel of five photos. Then someone in the studio swaps photo three for a "better" one and posts it. The customer approved a post; they didn't approve this post.
So the studio cannot edit a post the customer is looking at or has approved. PENDING_APPROVAL and APPROVED are not in studioEditable():
private SocialPost requireStudioEditable(Long id) {
SocialPost p = require(id);
if (!p.getStatus().studioEditable()) {
throw new IllegalStateException(p.getStatus() == SocialPostStatus.POSTED
? "This post is already on Instagram"
: "Withdraw the post from the customer before changing it - their approval covers exactly what they saw");
}
return p;
}To change it, the studio must withdraw it, which sends it back to DRAFT and voids the approval. Then they edit and send it again, and the customer decides again. And only an APPROVED post can be marked POSTED:
if (p.getStatus() != SocialPostStatus.APPROVED) {
throw new IllegalStateException("Only a post the customer has approved can be posted");
}Put those two rules together and you get the guarantee: whatever is marked as posted is exactly what the customer approved. Not because everyone remembers to check, but because there's no path through the code where it isn't true.
Changing your mind
The customer can change their mind about an approval until the post goes live. APPROVED is in customerDecidable(), so an approved post can still be declined or sent back for changes. Once it's POSTED, the answer becomes "message the studio if you'd like it changed or taken down", because at that point it's a conversation with a person, not a button.
"Change this one": feedback per photo
"Please change some of the photos" isn't useful feedback on a carousel of twelve. So when the customer asks for changes, they can flag individual photos or videos, each with its own note:
p.getItems().forEach(it -> it.setChangeRequested(false));
for (ItemFeedback f : feedback) {
if (f.itemId() == null || !seen.add(f.itemId())) continue;
SocialPostItem it = item(p, f.itemId());
it.setChangeRequested(true);
addComment(p, it, false, name(me), c != null ? c : "Please change this one.");
}Three small details:
- Flags are cleared first, so a new round of feedback replaces the last one instead of piling up.
- Duplicates are skipped with a
Set, so a double-tap doesn't post the same comment twice. - A request with no flags and no note is refused ("Tell us what to change"), because "changes requested" with nothing to change leaves the studio guessing.
Each comment is anchored to the photo it's about, and also stores the photo's number ("photo 3"). If the studio later removes that photo, the database keeps the comment (the link to the photo becomes empty) and the number still makes sense in the conversation.
Who decides
A booking can have co-owners (Part 13): the couple, and maybe a parent. Any of them can approve. The post records who decided and when, so "approved by Divya on 24 October" is on the record, not just "approved". Every send, withdrawal, decision and posting is also written to the audit log.
Emails that can't break anything
Sending a post emails the customer, and every customer decision emails the studio member who made the post. Email is the least reliable part of this whole flow, so it's never allowed to undo the important part:
try {
email.sendSocialPostApprovalRequestEmail(b.getCustomer(), b, p.getItems().size());
} catch (Exception e) {
log.warn("Could not email approval request for social post {}: {}", p.getId(), e.getMessage());
}The state change is saved first. If the email fails, the post is still waiting for approval and the customer still sees it on their dashboard; we just log the failure.
Format rules, checked before sending
Instagram has its own rules, and it's kinder to check them before the customer sees anything:
- a reel is exactly one video,
- a story is one photo or video,
- a post is one item or a carousel of up to 20.
Takeaways
- Write the states down, and put the rules on the state. Three small methods answer every "can I do this now?" question.
- An approval must cover exactly what goes live. Lock the thing being approved, and make changing it void the approval.
- Only allow the final step from the approved state. Then the guarantee holds by construction, not by habit.
- Make feedback specific. Per-photo flags and notes turn "change some photos" into a to-do list.
- Record who decided, not just what was decided.
- Never let a notification failure roll back the real work.