Skip to content

Commit

Permalink
players have fargo observable ids
Browse files Browse the repository at this point in the history
  • Loading branch information
codephobia committed Jul 12, 2023
1 parent 22f593f commit a5f01c3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ <h1 class="text-gray-50 uppercase text-4xl">{{ isCreating ? 'Create' : 'Update'
/>
</div>
</div>
<div class="flex flex-wrap -mx-3 mb-6">
<div class="w-full px-3 mb-6 md:mb-0">
<label class="block uppercase tracking-wide text-gray-100 text-xs font-bold mb-2" for="fargo_id">Fargo Observable ID</label>
<input
class="appearance-none block w-full bg-gray-200 text-gray-700 border rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white"
id="fargo_observable_id"
type="number"
min="0"
placeholder="Fargo Observable ID"
formControlName="fargo_observable_id"
/>
</div>
</div>
<div class="flex flex-wrap -mx-3 mb-6">
<div class="w-full px-3 mb-6 md:mb-0">
<label class="block uppercase tracking-wide text-gray-100 text-xs font-bold mb-2" for="fargo_id">Fargo ID</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class PlayerFormComponent {
this.form.addControl('id', this._fb.control(this._player.id, Validators.required));
this.form.controls.name.patchValue(this._player.name);
this.form.controls.flag_id.patchValue(this._player.flag_id);
this.form.controls.fargo_observable_id.patchValue(this._player.fargo_observable_id);
this.form.controls.fargo_id.patchValue(this._player.fargo_id);
this.form.controls.fargo_rating.patchValue(this._player.fargo_rating);
}
Expand All @@ -42,6 +43,7 @@ export class PlayerFormComponent {
this.form = this._fb.group({
name: ['', Validators.required],
flag_id: [1, Validators.required],
fargo_observable_id: [0, Validators.required],
fargo_id: [0, Validators.required],
fargo_rating: [0, Validators.required],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
<div class="w-1/12 flex flex-col justify-center items-start px-10">
<p class="text-white uppercase text-xs">Flag</p>
</div>
<div class="w-5/12 flex flex-col justify-center items-start px-10">
<div class="w-3/12 flex flex-col justify-center items-start px-10">
<p class="text-white uppercase text-xs">Name</p>
</div>
<div class="w-2/12 flex flex-col justify-center items-start px-10">
<p class="text-white uppercase text-xs whitespace-nowrap">Fargo Observable ID</p>
</div>
<div class="w-2/12 flex flex-col justify-center items-start px-10">
<p class="text-white uppercase text-xs whitespace-nowrap">Fargo ID</p>
</div>
Expand All @@ -19,9 +22,12 @@
<div class="w-1/12 flex flex-col justify-center items-start px-10">
<img *ngIf="player?.flag" class="w-5 h-auto" src="./assets/flags/{{ player?.flag?.image_path }}" [alt]="player?.flag?.country" />
</div>
<div class="w-5/12 flex flex-col justify-center px-10">
<div class="w-3/12 flex flex-col justify-center px-10">
<p class="text-white uppercase text-xs whitespace-nowrap">{{ player?.name }}</p>
</div>
<div class="w-2/12 flex flex-col justify-center px-10">
<p class="text-white uppercase text-xs">{{ player?.fargo_observable_id }}</p>
</div>
<div class="w-2/12 flex flex-col justify-center px-10">
<p class="text-white uppercase text-xs">{{ player?.fargo_id }}</p>
</div>
Expand Down
30 changes: 17 additions & 13 deletions libs/go/api/players.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ const (

// PlayersPostBody is an incoming body on a POST request for creating a player.
type PlayersPostBody struct {
Name string `json:"name"`
FlagID uint `json:"flag_id"`
FargoID uint `json:"fargo_id"`
FargoRating uint `json:"fargo_rating"`
Name string `json:"name"`
FlagID uint `json:"flag_id"`
FargoObservableID uint `json:"fargo_observable_id"`
FargoID uint `json:"fargo_id"`
FargoRating uint `json:"fargo_rating"`
}

// PlayersPatchBody is an incoming body on a PATCH request for updating a
// player.
type PlayersPatchBody struct {
Name string `json:"name"`
FlagID uint `json:"flag_id"`
FargoID uint `json:"fargo_id"`
FargoRating uint `json:"fargo_rating"`
Name string `json:"name"`
FlagID uint `json:"flag_id"`
FargoObservableID uint `json:"fargo_observable_id"`
FargoID uint `json:"fargo_id"`
FargoRating uint `json:"fargo_rating"`
}

// Handler for /players.
Expand Down Expand Up @@ -88,7 +90,7 @@ func (server *Server) handlePlayersGet(w http.ResponseWriter, r *http.Request) {

offset := pageNum*playersPerPage - playersPerPage
playersResult := server.db.
Select("id", "name", "flag_id", "fargo_id", "fargo_rating").
Select("id", "name", "flag_id", "fargo_observable_id", "fargo_id", "fargo_rating").
Order("name").
Limit(playersPerPage).
Offset(offset).
Expand Down Expand Up @@ -117,10 +119,11 @@ func (server *Server) handlePlayersPost(w http.ResponseWriter, r *http.Request)

// create a new player from the body
player := &models.Player{
Name: body.Name,
FlagID: body.FlagID,
FargoID: body.FargoID,
FargoRating: body.FargoRating,
Name: body.Name,
FlagID: body.FlagID,
FargoObservableID: body.FargoObservableID,
FargoID: body.FargoID,
FargoRating: body.FargoRating,
}

// add new player to the database
Expand Down Expand Up @@ -256,6 +259,7 @@ func (server *Server) handlePlayerByIDPatch(w http.ResponseWriter, r *http.Reque
// update player details from the body
player.Name = body.Name
player.FlagID = body.FlagID
player.FargoObservableID = body.FargoObservableID
player.FargoID = body.FargoID
player.FargoRating = body.FargoRating

Expand Down
9 changes: 5 additions & 4 deletions libs/go/models/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ func (p *Player) Update(database *gorm.DB) error {
}

return database.Model(p).Updates(map[string]interface{}{
"name": p.Name,
"flag_id": p.FlagID,
"fargo_id": p.FargoID,
"fargo_rating": p.FargoRating,
"name": p.Name,
"flag_id": p.FlagID,
"fargo_observable_id": p.FargoObservableID,
"fargo_id": p.FargoID,
"fargo_rating": p.FargoRating,
}).Error
}

Expand Down
1 change: 1 addition & 0 deletions libs/models/src/lib/player.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface IPlayer {
name: string;
flag_id: number;
flag?: IFlag;
fargo_observable_id: number;
fargo_id: number;
fargo_rating: number;
}

0 comments on commit a5f01c3

Please sign in to comment.