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? {
val user = when (identifier) {
var user = when (identifier) {
is Long -> dslContext.selectFrom(USERS)
.where(USERS.USER_ID.eq(identifier))
.fetchOneInto(UsersRecord::class.java)
@ -53,6 +53,16 @@ class UserService(
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) {
val userDetails = UserDetails(
user.userId!!,
@ -75,7 +85,7 @@ class UserService(
// The database does NOT have the user; we will now use the osu!api
val apiUser = when (identifier) {
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
} ?: return null

View File

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

View File

@ -157,7 +157,7 @@
<ng-container *ngIf="column.type == 'string'">
<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-template #stringField>
{{ getValue(entry, column.name) }}

View File

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

View File

@ -62,11 +62,11 @@
<tr>
<td>Player</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>
</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>
</td>
</tr>

View File

@ -33,7 +33,7 @@
</div>
</div>
<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">
<br>
Submitted on <strong>{{ this.replayData.date }}</strong>
@ -196,7 +196,7 @@
<tbody>
<tr *ngFor="let score of this.replayData.similar_scores">
<td class="text-center">
<a [routerLink]="['/u/' + score.username]">{{ score.username }}</a>
<a [routerLink]="['/u/' + score.user_id]">{{ score.username }}</a>
</td>
<td class="text-center">
{{ score.pp | number: '1.2-2' }}

View File

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

View File

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