PublicUserProfileDto.java
package com.wavii.dto.user;
import com.wavii.model.User;
import java.time.format.DateTimeFormatter;
import java.util.UUID;
/**
* DTO que representa el perfil publico de un usuario.
* No expone datos sensibles como el email o el telefono de contacto.
*/
public record PublicUserProfileDto(
UUID id,
String name,
String level,
String role,
int xp,
int streak,
int bestStreak,
int tabsPublished,
boolean acceptsMessages,
boolean blockedByMe,
boolean teacherProfileAvailable,
String memberSince
) {
public static PublicUserProfileDto from(
User user,
int tabsPublished,
boolean blockedByMe,
boolean teacherProfileAvailable
) {
return new PublicUserProfileDto(
user.getId(),
user.getName(),
user.getLevel() != null ? user.getLevel().name() : null,
user.getRole() != null ? user.getRole().name() : null,
user.getXp(),
user.getStreak(),
user.getBestStreak(),
tabsPublished,
user.isAcceptsMessages(),
blockedByMe,
teacherProfileAvailable,
user.getCreatedAt() != null
? user.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM"))
: null
);
}
}