Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature of DLC handling #51

Open
wants to merge 3 commits into
base: Boderator3.0
Choose a base branch
from
Open

Conversation

Smieszkokoleszko
Copy link
Contributor

Initial commit of new feature from issue #50.

Added basic class for single user and class with a list of users. Added API controller to check users and their DLCs.

Added basic class for single user and class with a list of users. Added
API controller to check users and their DLCs.
Copy link
Member

@3Mydlo3 3Mydlo3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look at my comments and take a quick look at Server API in Arma Server Manager.


namespace ArmaForces.Boderator.BotService.DataClasses
{
public class SingleUser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just User? This sounds awful.


namespace ArmaForces.Boderator.BotService.DataClasses
{
public class Users
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this class? It doesn't have an interface. If you want some class which will allow you to retrieve users data then create an interface for it, e.g IUsersRepository and create some useful methods there instead of just returning a list of users.

public class SingleUser
{
public ulong UserID;
public List<DLC> DLCList = new List<DLC>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a property too. Don't use fields for publicly available stuff. And make both the property and the list readonly, e.g. IReadOnlyList, IReadOnlyCollection or maybe even IReadOnlySet as it should not have duplicates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding new DLC when property is readonly?

Or you meant something like that?

private List<DLC> _dlcList;
public ReadOnlyCollection<DLC> DLCList {get { return _dlcList.AsReadOnly; }}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, almost, something like this:

private List<DLC> _dlcList;
public IReadOnlyCollection<DLC> DLCList => _dlcList.AsReadOnly();

We don't want to allow external modifications to any User or his data. This should be only done in IUserRepository or something like this, right where it's stored. So we need to always return immutable User object. Then to change anything, you must go through IUserRepository which will create new User instance with updated data.

@@ -0,0 +1,26 @@
using System.Collections.Generic;

namespace ArmaForces.Boderator.BotService.DataClasses
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DataClasses is awful and stinks with legacy ArmaforcesMissionBot, don't. You are creating a DLC feature so almost everything you do should be in Features/DLC folder/namespace. This one will probably go to Models subfolder.

Comment on lines 47 to 49
//List user with given ID. "0" lists all users
[HttpGet("{userID}")]
public void UserOnServer(ulong userID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. You should have separate method for no input instead of special handling for 0 value. And method should be named GetUser. Then method for all users would just be named GetUsers or GetAllUsers.

Comment on lines 12 to 15
[Route("users/")]
[ApiController]
[Produces("application/json")]
public class DLCController : ControllerBase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it DLCController with users path? You probably should have created 2 controllers. One for users, one for dlc.

{
[Route("users/")]
[ApiController]
[Produces("application/json")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant, you can remove this.

Suggested change
[Produces("application/json")]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant with what? Something in rest of program?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to specify what Content-Type you produce if you just use IActionResult and return the data object. It will be serialized to any Content-Type desired by caller.

Comment on lines 121 to 159
//Check if user has all DLCs
[HttpGet("DLC")]
public IActionResult UserhasDLC(ulong userID, String dlcs)
{
if (dlcs == null)
{
return (IActionResult)NotFound("No given DLC");
}

List<SingleUser.DLC> dlcList = new List<SingleUser.DLC>();

foreach (string singleDlc in dlcs.Split(','))
{

try
{
var dlcClass = (SingleUser.DLC)Enum.Parse(typeof(SingleUser.DLC), singleDlc);
dlcList.Add(dlcClass);
}
catch
{
return (IActionResult)BadRequest("Wrong DLC name");
}

}

var user = _users.UsersList.SingleOrDefault(x => x.UserID == userID);

if (user is null)
{
return (IActionResult)NotFound("User not found");
}

var dlcFound = !dlcList.Except(user.DLCList).Any();

return dlcFound
? Ok("User has all given DLCs")
: (IActionResult)NotFound("User doesn't have all given DLCs");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably useless in API. Instead just make sure API can return user and his DLCs.

ArmaForces.Boderator/.gitignore Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants