Skip to content

2023 10 07 ESPN Fantasy Football SpringBoot

I've written a lot of the SpringBoot project so far, but I wanted to start taking a few notes as a go.

Roster IDs

Many of the entities that I have created by nature have composite IDs. The composite primary key design of RosterEntry could be a little tricky because you need to decide which field provides uniquenes to the instance, i.e. is it lineupSlotId (and Team) or is it playerId (and Team). If it's the former, than really your primary key could be the playerPoolEntry field, as this is already unique to the Team and league. To determine this, we need to determine if the RosterEntry is predicated on the slot itself, or the players within the Roster. If I move some players out of their starting positions, this will create additional slots. However, the roster entry array size does not change when queried from

https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2023/segments/0/leagues/695660?rosterForTeamId=1&view=mRoster

It should also be noted that all bench spots have a lineupSlotId of 20. There we have our answer - playerPoolEntry is our primary key.

Now, after actually writing the code and testing it, playerPoolEntry shouldn't be the primary key, because playerPoolEntry, and this RosterEntry is a direct @OneToMany value within the Team (I don't think I need a Roster object within the team). The primary keys should be the playerId and the Team. The player pool entry will join on a mix of these columns and therefore should not be updatable/insertable.

Some fields within RosterEntry
@Id
@Column(name = "player_id")
private Long playerId;

@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns(value = {
        @JoinColumn(name = "league_id", referencedColumnName = "league_id"),
        @JoinColumn(name = "season_id", referencedColumnName = "season_id"),
        @JoinColumn(name = "team_id", referencedColumnName = "id")
}, foreignKey = @ForeignKey(name = "FK_RosterEntry_Team"))
private Team team;

@ManyToOne
@JoinColumns(value = {
        @JoinColumn(name = "league_id", referencedColumnName = "league_id", updatable = false, insertable = false),
        @JoinColumn(name = "season_id", referencedColumnName = "season_id", updatable = false, insertable = false),
        @JoinColumn(name = "player_id", referencedColumnName = "id", updatable = false, insertable = false),
}, foreignKey = @ForeignKey(name = "FK_RosterEntry_PlayerPoolEntry"))
private PlayerPoolEntry playerPoolEntry;

Will need to update the TeamMapper

Had to ignore the roster field in TeamMapper

@Mapping(target = "roster", ignore = true)

Comments