Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorPolyakov committed Jul 12, 2024
1 parent fc00c8d commit ea68b7c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CONCEPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

Отдельной таблицей по отношению к пользователям (многие ко многим? - да владеть двумя командами это возможно):
- команда uuid - *уникальный идентификатор*
- Роль в [команде](https://github.com/sea-kg/ctf01d-training-platform/issues/44) - (четыре роли: owner, captain, vice-captain, player)
- Роль в [команде](https://github.com/sea-kg/ctf01d-training-platform/issues/44) - (owner, captain, vice-captain, player, guest)
- Название роли в команде - *роли придуманные капитанами и замами команд*
- публичный комментарий - *виден всем*
- приватный комментарий - *виден только владельцу капитану и зам капитана*
Expand Down
6 changes: 6 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,11 @@ components:
ProfileResponse:
type: object
description: The response schema for a user's profile, including id, timestamps, team name, and team history.
required:
- id
- created_at
- team_name
- team_role
properties:
id:
type: string
Expand All @@ -916,6 +921,7 @@ components:
- captain
- vice-captain
- player
- guest
team_history:
type: array
description: The list of teams the user has been part of, including the periods of membership.
Expand Down
4 changes: 2 additions & 2 deletions html/assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,13 +716,13 @@ function showMyTeams(userId) {
for (var i in data.team_history) {
var team = data.team_history[i];
teamHistoryHtml += '<div class="team">';
teamHistoryHtml += '<div class="team-name">' + team.name + '</div>';
teamHistoryHtml += '<div class="team-name">[' + team.name + '] ' + team.role + '</div>';
teamHistoryHtml += '<div class="team-dates">Joined at: ' + new Date(team.join).toLocaleString() +
(team.left ? ', Left at: ' + new Date(team.left).toLocaleString() : ', ... ') + '</div>';
teamHistoryHtml += '</div>';
}
teamHistoryHtml += '</div>';
var currentTeamHtml = '<div class="current-team"><strong>Current Team: </strong>' + data.team_name + '</div>';
var currentTeamHtml = '<div class="current-team"><strong>Current Team: </strong>[' + data.team_name + '] ' + data.team_role + '</div>';
$('#my_teams_content').html(currentTeamHtml + teamHistoryHtml);
$('#modal_my_teams').modal('show');
});
Expand Down
11 changes: 7 additions & 4 deletions internal/app/db/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package db

import (
"time"

openapi_types "github.com/oapi-codegen/runtime/types"
)

type Profile struct {
CurrentTeam string `db:"name"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"created_at"`
Role string `db:"role"`
Id openapi_types.UUID `db:"id"`
CurrentTeam string `db:"name"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"created_at"`
Role string `db:"role"`
}

type ProfileTeams struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/app/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func (r *userRepo) AddUserToTeams(ctx context.Context, userId openapi_types.UUID

func (r *userRepo) GetProfileWithHistory(ctx context.Context, id openapi_types.UUID) (*models.ProfileWithHistory, error) {
query := `
SELECT teams.name, role, created_at, updated_at
SELECT profiles.id, teams.name, role, created_at, updated_at
FROM profiles JOIN teams on profiles.current_team_id=teams.id
WHERE profiles.user_id = $1
`
profile := models.Profile{}
err := r.db.QueryRowContext(ctx, query, id).Scan(&profile.CurrentTeam, &profile.Role, &profile.CreatedAt, &profile.UpdatedAt)
err := r.db.QueryRowContext(ctx, query, id).Scan(&profile.Id, &profile.CurrentTeam, &profile.Role, &profile.CreatedAt, &profile.UpdatedAt)
if err != nil {
return nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions internal/app/server/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions internal/app/view/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (

func NewProfileFromModel(p *db.ProfileWithHistory) *server.ProfileResponse {
return &server.ProfileResponse{
CreatedAt: &p.Profile.CreatedAt,
UpdatedAt: &p.Profile.UpdatedAt,
TeamName: &p.Profile.CurrentTeam,
// TeamRole: &(*server.ProfileResponseTeamRole)(p.Profile.Role),
Id: p.Profile.Id,
CreatedAt: p.Profile.CreatedAt,
UpdatedAt: &p.Profile.UpdatedAt,
TeamName: p.Profile.CurrentTeam,
TeamRole: server.ProfileResponseTeamRolePlayer,
TeamHistory: makeTeamHistory(p.History),
}
}
Expand All @@ -23,6 +24,7 @@ func makeTeamHistory(tms []db.ProfileTeams) *[]server.TeamHistory {
Join: tm.JoinedAt,
Left: tm.LeftAt,
Name: tm.Name,
Role: server.TeamHistoryRolePlayer,
})
}
return &out
Expand Down

0 comments on commit ea68b7c

Please sign in to comment.