Merge branch 'user-id-lookup'

This commit is contained in:
Stedoss 2024-07-05 18:59:21 +01:00
commit 7b59badf26
8 changed files with 24 additions and 11 deletions

View File

@ -43,7 +43,7 @@ class UserService(
} }
fun getUserDetails(identifier: Any): UserDetailsExtended? { fun getUserDetails(identifier: Any): UserDetailsExtended? {
val user = when (identifier) { var user = when (identifier) {
is Long -> dslContext.selectFrom(USERS) is Long -> dslContext.selectFrom(USERS)
.where(USERS.USER_ID.eq(identifier)) .where(USERS.USER_ID.eq(identifier))
.fetchOneInto(UsersRecord::class.java) .fetchOneInto(UsersRecord::class.java)
@ -53,6 +53,16 @@ class UserService(
else -> null else -> null
} }
// Lookup user by ID if we have not found a user via a username lookup and the identifier is a valid number
if (user == null && identifier is String) {
val longIdentifier = identifier.toLongOrNull()
if (longIdentifier != null) {
user = dslContext.selectFrom(USERS)
.where(USERS.USER_ID.eq(longIdentifier))
.fetchOneInto(UsersRecord::class.java)
}
}
if (user != null) { if (user != null) {
val userDetails = UserDetails( val userDetails = UserDetails(
user.userId!!, user.userId!!,
@ -75,7 +85,7 @@ class UserService(
// The database does NOT have the user; we will now use the osu!api // The database does NOT have the user; we will now use the osu!api
val apiUser = when (identifier) { val apiUser = when (identifier) {
is Long -> this.osuApi.getUserProfile(userId = identifier.toString(), mode = "osu", key = "id") is Long -> this.osuApi.getUserProfile(userId = identifier.toString(), mode = "osu", key = "id")
is String -> this.osuApi.getUserProfile(userId = identifier, mode = "osu", key = "username") is String -> this.osuApi.getUserProfile(userId = identifier, mode = "osu")
else -> null else -> null
} ?: return null } ?: return null

View File

@ -68,7 +68,7 @@ export function getMockReplayData(): ReplayData {
export interface ReplayData { export interface ReplayData {
replay_id: number | null; replay_id: number | null;
user_id: number; user_id: number | null;
username: string; username: string;
date: string; date: string;
beatmap_id: number; beatmap_id: number;

View File

@ -157,7 +157,7 @@
<ng-container *ngIf="column.type == 'string'"> <ng-container *ngIf="column.type == 'string'">
<ng-container *ngIf="column.name == 'user_username'; else stringField"> <ng-container *ngIf="column.name == 'user_username'; else stringField">
<a [href]="'/u/' + getValue(entry, column.name)" target="_blank">{{ getValue(entry, column.name) }}</a> <a [href]="'/u/' + getValue(entry, 'user_id')" target="_blank">{{ getValue(entry, column.name) }}</a>
</ng-container> </ng-container>
<ng-template #stringField> <ng-template #stringField>
{{ getValue(entry, column.name) }} {{ getValue(entry, column.name) }}

View File

@ -346,7 +346,7 @@ export class SearchComponent implements OnInit {
getLink(entry: any): any { getLink(entry: any): any {
if(this.searchType === 'user') { if(this.searchType === 'user') {
return "/u/" + this.getValue(entry, 'username'); return "/u/" + this.getValue(entry, 'user_id');
} else { } else {
return "/s/" + this.getValue(entry, 'replay_id'); return "/s/" + this.getValue(entry, 'replay_id');
} }

View File

@ -62,11 +62,11 @@
<tr> <tr>
<td>Player</td> <td>Player</td>
<td> <td>
<a [routerLink]="['/u/' + this.pair.replays[0].username]">{{ this.pair.replays[0].username }}</a> <a [routerLink]="['/u/' + this.pair.replays[0].user_id]">{{ this.pair.replays[0].username }}</a>
<a class="btn" style="margin-left: 5px" href="https://osu.ppy.sh/users/{{ this.pair.replays[0].user_id }}" target="_blank">osu!web</a> <a class="btn" style="margin-left: 5px" href="https://osu.ppy.sh/users/{{ this.pair.replays[0].user_id }}" target="_blank">osu!web</a>
</td> </td>
<td> <td>
<a [routerLink]="['/u/' + this.pair.replays[1].username]">{{ this.pair.replays[1].username }}</a> <a [routerLink]="['/u/' + this.pair.replays[1].user_id]">{{ this.pair.replays[1].username }}</a>
<a class="btn" style="margin-left: 5px" href="https://osu.ppy.sh/users/{{ this.pair.replays[1].user_id }}" target="_blank">osu!web</a> <a class="btn" style="margin-left: 5px" href="https://osu.ppy.sh/users/{{ this.pair.replays[1].user_id }}" target="_blank">osu!web</a>
</td> </td>
</tr> </tr>

View File

@ -33,7 +33,7 @@
</div> </div>
</div> </div>
<div class="score-player__row score-player__row--player mt-2"> <div class="score-player__row score-player__row--player mt-2">
Played by <a [routerLink]="['/u/' + this.replayData.username]">{{ this.replayData.username }}</a> <a *ngIf="this.replayData.user_id" class="btn" style="margin-left: 5px" href="https://osu.ppy.sh/users/{{ this.replayData.user_id }}" target="_blank">osu!web</a> Played by <a [routerLink]="['/u/' + (this.replayData.user_id ?? this.replayData.username)]">{{ this.replayData.username }}</a> <a *ngIf="this.replayData.user_id" class="btn" style="margin-left: 5px" href="https://osu.ppy.sh/users/{{ this.replayData.user_id }}" target="_blank">osu!web</a>
<ng-container *ngIf="!this.isUserScore"> <ng-container *ngIf="!this.isUserScore">
<br> <br>
Submitted on <strong>{{ this.replayData.date }}</strong> Submitted on <strong>{{ this.replayData.date }}</strong>
@ -196,7 +196,7 @@
<tbody> <tbody>
<tr *ngFor="let score of this.replayData.similar_scores"> <tr *ngFor="let score of this.replayData.similar_scores">
<td class="text-center"> <td class="text-center">
<a [routerLink]="['/u/' + score.username]">{{ score.username }}</a> <a [routerLink]="['/u/' + score.user_id]">{{ score.username }}</a>
</td> </td>
<td class="text-center"> <td class="text-center">
{{ score.pp | number: '1.2-2' }} {{ score.pp | number: '1.2-2' }}

View File

@ -98,7 +98,7 @@
<tbody style="font-size: 14px;"> <tbody style="font-size: 14px;">
<tr *ngFor="let score of this.getCurrentPage()"> <tr *ngFor="let score of this.getCurrentPage()">
<td> <td>
<a [routerLink]="['/u/' + score.username]"> <a [routerLink]="['/u/' + score.user_id]">
{{ score.username }} {{ score.username }}
</a> </a>
</td> </td>

View File

@ -3,7 +3,7 @@ import {SimilarReplay, SuspiciousScore} from "../replays";
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import {catchError, EMPTY, finalize, Observable, Subscription} from "rxjs"; import {catchError, EMPTY, finalize, Observable, Subscription} from "rxjs";
import {environment} from "../../environments/environment"; import {environment} from "../../environments/environment";
import {DatePipe, DecimalPipe, JsonPipe, NgForOf, NgIf, NgOptimizedImage} from "@angular/common"; import {DatePipe, DecimalPipe, JsonPipe, Location, NgForOf, NgIf, NgOptimizedImage} from "@angular/common";
import {ActivatedRoute, RouterLink} from "@angular/router"; import {ActivatedRoute, RouterLink} from "@angular/router";
import {UserDetails, UserQueueDetails} from "../userDetails"; import {UserDetails, UserQueueDetails} from "../userDetails";
import {calculateTimeAgo, countryCodeToFlag, formatDuration} from "../format"; import {calculateTimeAgo, countryCodeToFlag, formatDuration} from "../format";
@ -68,6 +68,7 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy {
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private title: Title, private title: Title,
private rxStompService: RxStompService, private rxStompService: RxStompService,
private location: Location,
public userService: UserService, public userService: UserService,
public followService: FollowService public followService: FollowService
) { } ) { }
@ -135,6 +136,8 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy {
this.subscribeToUser(); this.subscribeToUser();
} }
this.checkIfUserIsFollowed(); this.checkIfUserIsFollowed();
this.location.replaceState(`u/${this.userInfo.user_details.user_id}`);
} }
); );
} }