Also supports Get request for /api/users and /api/users?userId=x and /api/timelogs?userId=x and /api/stats stats needs fleshing out. also logic behind when someone is checking in/out..
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Devkoes.Restup.WebServer.Attributes;
|
|
using Devkoes.Restup.WebServer.Models.Schemas;
|
|
|
|
namespace WebSocketService
|
|
{
|
|
internal partial class RestService
|
|
{
|
|
[UriFormat("/users")]
|
|
public GetResponse GetAllUsers()
|
|
{
|
|
var query = _conn.Table<UserIdentity>();
|
|
if (query.Any())
|
|
{
|
|
return new GetResponse(GetResponse.ResponseStatus.OK, query.ToArray());
|
|
}
|
|
return new GetResponse(GetResponse.ResponseStatus.NotFound);
|
|
}
|
|
|
|
[UriFormat("/users?userid={id}")]
|
|
public GetResponse GetUserById(int id)
|
|
{
|
|
var userQuery = _conn.Query<UserIdentity>(
|
|
"select * from UserIdentity where Id = ?",
|
|
id);
|
|
if (userQuery.Any())
|
|
{
|
|
return new GetResponse(GetResponse.ResponseStatus.OK, userQuery.First());
|
|
}
|
|
return new GetResponse(GetResponse.ResponseStatus.NotFound);
|
|
}
|
|
|
|
[UriFormat("/timelogs?userid={id}")]
|
|
public GetResponse GetTimeLogsByUserId(int id)
|
|
{
|
|
var timeLogQuery = _conn.Query<TimeLog>(
|
|
"select * from TimeLog where UserId_FK = ?",
|
|
id);
|
|
if (timeLogQuery.Any())
|
|
{
|
|
return new GetResponse(GetResponse.ResponseStatus.OK, timeLogQuery.ToArray());
|
|
}
|
|
return new GetResponse(GetResponse.ResponseStatus.NotFound);
|
|
}
|
|
|
|
[UriFormat("/stats")]
|
|
public GetResponse GetTimeLogStatistics()
|
|
{
|
|
return new GetResponse(GetResponse.ResponseStatus.NotFound);
|
|
}
|
|
}
|
|
}
|