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

Simplify enum classes #305

Closed
andregasser opened this issue Oct 23, 2023 · 3 comments · Fixed by #310
Closed

Simplify enum classes #305

andregasser opened this issue Oct 23, 2023 · 3 comments · Fixed by #310
Assignees
Labels
code quality Everything related to code quality good first issue Good for newcomers, low-hanging fruit hacktoberfest

Comments

@andregasser
Copy link
Owner

andregasser commented Oct 23, 2023

As outlined here, enum classes can be simplified. Instead of writing code like this:

enum class SourceSuggestion(val value: String) {
    STAFF("staff"),
    PAST_INTERACTIONS("past_interactions"),
    GLOBAL("global")
}

we can write code like so:

@Serializable
enum class SourceSuggestion {
    @SerialName("staff")
    STAFF,

    @SerialName("past_interactions")
    PAST_INTERACTIONS,

    @SerialName("global")
    GLOBAL
}

Doing so we let the serializer do the translation work for us and we can simplify the constructor.

All the enum classes in the project should be reviewed and simplified if it makes sense.

@andregasser andregasser added good first issue Good for newcomers, low-hanging fruit code quality Everything related to code quality hacktoberfest labels Oct 23, 2023
@G10xy
Copy link
Contributor

G10xy commented Oct 23, 2023

Assign me this, so that I will try to refactor any enum used within any dto model

@G10xy
Copy link
Contributor

G10xy commented Oct 25, 2023

Let's take in consideration the Enum CardType, for example. This enum was made to restrict the possible values for the attribute "type" of the PreviewCard dto model.
Should I update the "type" attribute as Type
@SerialName("type") val type: CardType = CardType.Link,

or remain it as String?
@SerialName("type") val type: String = CardType.Link.name.lowercase(),

@andregasser
Copy link
Owner Author

Hello @G10xy I'd switch this to type CardType.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Everything related to code quality good first issue Good for newcomers, low-hanging fruit hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants