diff --git a/.github/config/pr-labeler-config.yml b/.github/config/pr-labeler-config.yml new file mode 100644 index 0000000..f096fb6 --- /dev/null +++ b/.github/config/pr-labeler-config.yml @@ -0,0 +1,3 @@ +feature: feature/* +fix: fix/* +chore: chore/* \ No newline at end of file diff --git a/.github/config/release-drafter-config.yml b/.github/config/release-drafter-config.yml new file mode 100644 index 0000000..fca3ad1 --- /dev/null +++ b/.github/config/release-drafter-config.yml @@ -0,0 +1,26 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +categories: + - title: 'Features' + labels: + - 'feature' + - title: 'Bug Fixes' + labels: + - 'fix' + - title: 'Maintenance' + label: 'chore' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: patch +template: | + $CHANGES \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a0ed230 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: .NET build and test + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + env: + SOLUTION: ./Kwtc.Tjek.Client.sln + + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + - name: Restore dependencies + run: dotnet restore $SOLUTION + + - name: Build + run: dotnet build $SOLUTION -c Release --no-restore + + - name: Test + run: dotnet test $SOLUTION -c Release --no-build --verbosity normal \ No newline at end of file diff --git a/.github/workflows/pr-labeler.yml b/.github/workflows/pr-labeler.yml new file mode 100644 index 0000000..1a2aa5b --- /dev/null +++ b/.github/workflows/pr-labeler.yml @@ -0,0 +1,21 @@ +name: PR labeler + +on: + pull_request: + types: [opened] + +permissions: + contents: read + +jobs: + pr-labeler: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: TimonVS/pr-labeler-action@v4 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + configuration-path: .github/config/pr-labeler-config.yml + \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..bebc5fd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,46 @@ +name: Publish + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 15 + + permissions: + packages: write + + env: + SOLUTION: ./Kwtc.Tjek.Client.sln + + steps: + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Verify commit exists in origin/main + run: git branch --remote --contains | grep origin/main + + - name: Extract release notes + run: | + git log --pretty=format:'%d %s' ${GITHUB_REF} | perl -pe 's| \(.*tag: v(\d+.\d+.\d+(-preview\d{3})?)(, .*?)*\)|\n## \1\n|g' > RELEASE-NOTES + + - name: Set VERSION variable from tag + run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + + - name: Build + run: dotnet build $SOLUTION -c Release /p:Version=${VERSION} + + - name: Test + run: dotnet test $SOLUTION -c Release /p:Version=${VERSION} --no-build + + - name: Pack + run: dotnet pack $SOLUTION -c Release /p:Version=${VERSION} --no-build --output . + + - name: Push package to Github + run: dotnet nuget push **\*.nupkg --api-key ${{secrets.GITHUB_TOKEN}} --source https://nuget.pkg.github.com/kwtc/index.json \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..11a35c3 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,21 @@ +name: Release drafter + +on: + push: + branches: ["main"] + +permissions: + contents: read + +jobs: + release-drafter: + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + with: + config-name: config/release-drafter-config.yml + disable-autolabeler: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/require-pr-label.yml b/.github/workflows/require-pr-label.yml new file mode 100644 index 0000000..95ba410 --- /dev/null +++ b/.github/workflows/require-pr-label.yml @@ -0,0 +1,17 @@ +name: Require PR version label +on: + pull_request_target: + types: [opened, labeled, unlabeled, synchronize] + +jobs: + require-pr-label: + name: check + runs-on: ubuntu-latest + + steps: + - uses: jesusvasquez333/verify-pr-label-action@v1.4.0 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + valid-labels: "major, minor, patch" + pull-request-number: "${{ github.event.pull_request.number }}" + disable-reviews: true \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2fe94db --- /dev/null +++ b/.gitignore @@ -0,0 +1,403 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +.idea/ + +data/ +appsettings.Development.json \ No newline at end of file diff --git a/Kwtc.Tjek.Client.sln b/Kwtc.Tjek.Client.sln new file mode 100644 index 0000000..03f2ec9 --- /dev/null +++ b/Kwtc.Tjek.Client.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9C75E12E-C71F-4ABF-9295-452FC0DB7B9A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D89F0A53-BC97-47A6-A334-0D2DD992A0EE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kwtc.Tjek.Client.Abstractions", "src\Kwtc.Tjek.Client.Abstractions\Kwtc.Tjek.Client.Abstractions.csproj", "{27A8AE87-BCE9-4AE5-AB07-1FBDAD3B8398}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kwtc.Tjek.Client", "src\Kwtc.Tjek.Client\Kwtc.Tjek.Client.csproj", "{891F57D1-6CE1-4825-A1B6-F3844E86396A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kwtc.Tjek.Client.Tests", "test\Kwtc.Tjek.Client.Tests\Kwtc.Tjek.Client.Tests.csproj", "{46E2396E-00E5-41D8-9A8B-730ADAC6113C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {27A8AE87-BCE9-4AE5-AB07-1FBDAD3B8398} = {9C75E12E-C71F-4ABF-9295-452FC0DB7B9A} + {891F57D1-6CE1-4825-A1B6-F3844E86396A} = {9C75E12E-C71F-4ABF-9295-452FC0DB7B9A} + {46E2396E-00E5-41D8-9A8B-730ADAC6113C} = {D89F0A53-BC97-47A6-A334-0D2DD992A0EE} + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {27A8AE87-BCE9-4AE5-AB07-1FBDAD3B8398}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {27A8AE87-BCE9-4AE5-AB07-1FBDAD3B8398}.Debug|Any CPU.Build.0 = Debug|Any CPU + {27A8AE87-BCE9-4AE5-AB07-1FBDAD3B8398}.Release|Any CPU.ActiveCfg = Release|Any CPU + {27A8AE87-BCE9-4AE5-AB07-1FBDAD3B8398}.Release|Any CPU.Build.0 = Release|Any CPU + {891F57D1-6CE1-4825-A1B6-F3844E86396A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {891F57D1-6CE1-4825-A1B6-F3844E86396A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {891F57D1-6CE1-4825-A1B6-F3844E86396A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {891F57D1-6CE1-4825-A1B6-F3844E86396A}.Release|Any CPU.Build.0 = Release|Any CPU + {46E2396E-00E5-41D8-9A8B-730ADAC6113C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46E2396E-00E5-41D8-9A8B-730ADAC6113C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46E2396E-00E5-41D8-9A8B-730ADAC6113C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46E2396E-00E5-41D8-9A8B-730ADAC6113C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/Kwtc.Tjek.Client.Abstractions/IClient.cs b/src/Kwtc.Tjek.Client.Abstractions/IClient.cs new file mode 100644 index 0000000..bbc2ff8 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/IClient.cs @@ -0,0 +1,8 @@ +using Kwtc.Tjek.Client.Abstractions.Models; + +namespace Kwtc.Tjek.Client.Abstractions; + +public interface IClient +{ + Task> Search(string query, CancellationToken cancellationToken = default); +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Kwtc.Tjek.Client.Abstractions.csproj b/src/Kwtc.Tjek.Client.Abstractions/Kwtc.Tjek.Client.Abstractions.csproj new file mode 100644 index 0000000..d6d762d --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Kwtc.Tjek.Client.Abstractions.csproj @@ -0,0 +1,11 @@ + + + + net8.0 + enable + enable + Kwtc.Tjek.Client.Abstractions + true + + + diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Branding.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Branding.cs new file mode 100644 index 0000000..45fb099 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Branding.cs @@ -0,0 +1,21 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Branding +{ + [JsonPropertyName("name")] + public string Name { get; set; } = default!; + + [JsonPropertyName("website")] + public string? Website { get; set; } + + [JsonPropertyName("description")] + public string? Description { get; set; } + + [JsonPropertyName("color")] + public string Color { get; set; } = default!; + + [JsonPropertyName("logo")] + public string Logo { get; set; } = default!; +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Country.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Country.cs new file mode 100644 index 0000000..c722a25 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Country.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Country +{ + [JsonPropertyName("id")] + public string Code { get; set; } = default!; +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Dealer.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Dealer.cs new file mode 100644 index 0000000..c84cb63 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Dealer.cs @@ -0,0 +1,54 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Dealer +{ + [JsonPropertyName("id")] + public string Id { get; set; } = default!; + + [JsonPropertyName("ern")] + public string Ern { get; set; } = default!; + + [JsonPropertyName("markets")] + public IEnumerable Markets { get; set; } = default!; + + [JsonPropertyName("name")] + public string Name { get; set; } = default!; + + [JsonPropertyName("website")] + public string Website { get; set; } = default!; + + [JsonPropertyName("description")] + public string Description { get; set; } = default!; + + [JsonPropertyName("logo")] + public string Logo { get; set; } = default!; + + [JsonPropertyName("color")] + public string Color { get; set; } = default!; + + [JsonPropertyName("pageflip")] + public Pageflip Pageflip { get; set; } = default!; + + [JsonPropertyName("country")] + public Country Country { get; set; } = default!; + + [JsonPropertyName("description_markdown")] + public string DescriptionMarkdown { get; set; } = default!; + + [JsonPropertyName("favorite_count")] + public long FavoriteCount { get; set; } + + [JsonPropertyName("is_incito_supported")] + public bool IsIncitoSupported { get; set; } + + [JsonPropertyName("locale")] + public string Locale { get; set; } = default!; + + [JsonPropertyName("category_ids")] + public IEnumerable CategoryIds { get; set; } = default!; + + [JsonPropertyName("is_content_public")] + public bool IsContentPublic { get; set; } +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Images.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Images.cs new file mode 100644 index 0000000..8cf9295 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Images.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Images +{ + [JsonPropertyName("thumb")] + public string Thumb { get; set; } = default!; + + [JsonPropertyName("view")] + public string View { get; set; } = default!; + + [JsonPropertyName("zoom")] + public string Zoom { get; set; } = default!; +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Links.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Links.cs new file mode 100644 index 0000000..16bae6a --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Links.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Links +{ + [JsonPropertyName("webshop")] + public string? Webshop { get; set; } +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Market.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Market.cs new file mode 100644 index 0000000..3505a93 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Market.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Market +{ + [JsonPropertyName("slug")] + public string Slug { get; set; } = default!; + + [JsonPropertyName("country_code")] + public string CountryCode { get; set; } = default!; +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Offer.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Offer.cs new file mode 100644 index 0000000..cbd7f54 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Offer.cs @@ -0,0 +1,51 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Offer +{ + [JsonPropertyName("id")] + public string Id { get; set; } = default!; + + [JsonPropertyName("branding")] + public Branding Branding { get; set; } = default!; + + [JsonPropertyName("heading")] + public string Heading { get; set; } = default!; + + [JsonPropertyName("description")] + public string Description { get; set; } = default!; + + [JsonPropertyName("catalog_page")] + public int? CatalogPage { get; set; } + + [JsonPropertyName("catalog_id")] + public string? CatalogId { get; set; } + + [JsonPropertyName("dealer_id")] + public string DealerId { get; set; } = default!; + + [JsonPropertyName("dealer")] + public Dealer Dealer { get; set; } = default!; + + [JsonPropertyName("images")] + public Images Images { get; set; } = default!; + + [JsonPropertyName("links")] + public Links Links { get; set; } = default!; + + [JsonPropertyName("pricing")] + public Pricing Pricing { get; set; } = default!; + + [JsonPropertyName("publish")] + public string Publish { get; set; } = default!; + + [JsonPropertyName("run_from")] + public string FromDate { get; set; } = default!; + + [JsonPropertyName("run_till")] + public string ToDate { get; set; } = default!; + + [JsonPropertyName("quantity")] + public Quantity Quantity { get; set; } = default!; +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Pageflip.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Pageflip.cs new file mode 100644 index 0000000..045eee9 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Pageflip.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Pageflip +{ + [JsonPropertyName("logo")] + public string Logo { get; set; } = default!; + + [JsonPropertyName("color")] + public string Color { get; set; } = default!; +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Pieces.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Pieces.cs new file mode 100644 index 0000000..ff9b7b7 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Pieces.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Pieces +{ + [JsonPropertyName("from")] + public long From { get; set; } + + [JsonPropertyName("to")] + public long To { get; set; } +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Pricing.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Pricing.cs new file mode 100644 index 0000000..c615afc --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Pricing.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Pricing +{ + [JsonPropertyName("pre_price")] + public decimal? PrePrice { get; set; } + + [JsonPropertyName("price")] + public decimal Price { get; set; } + + [JsonPropertyName("currency")] + public string Currency { get; set; } = default!; +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Quantity.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Quantity.cs new file mode 100644 index 0000000..1437770 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Quantity.cs @@ -0,0 +1,10 @@ +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Quantity +{ + public Pieces Pieces { get; set; } = default!; + + public Size Size { get; set; } = default!; + + public Unit? Unit { get; set; } +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Si.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Si.cs new file mode 100644 index 0000000..c3c3d5f --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Si.cs @@ -0,0 +1,8 @@ +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Si +{ + public long Factor { get; set; } + + public long To { get; set; } +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Size.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Size.cs new file mode 100644 index 0000000..a1f2e3b --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Size.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Size +{ + [JsonPropertyName("from")] + public long From { get; set; } + + [JsonPropertyName("to")] + public long To { get; set; } +} diff --git a/src/Kwtc.Tjek.Client.Abstractions/Models/Unit.cs b/src/Kwtc.Tjek.Client.Abstractions/Models/Unit.cs new file mode 100644 index 0000000..a1acff4 --- /dev/null +++ b/src/Kwtc.Tjek.Client.Abstractions/Models/Unit.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace Kwtc.Tjek.Client.Abstractions.Models; + +public class Unit +{ + [JsonPropertyName("si")] + public Si Si { get; set; } = default!; + + [JsonPropertyName("symbol")] + public string Symbol { get; set; } = default!; +} diff --git a/src/Kwtc.Tjek.Client/Client.cs b/src/Kwtc.Tjek.Client/Client.cs new file mode 100644 index 0000000..ef711c9 --- /dev/null +++ b/src/Kwtc.Tjek.Client/Client.cs @@ -0,0 +1,31 @@ +using System.Text.Json; +using Kwtc.Tjek.Client.Abstractions; +using Kwtc.Tjek.Client.Abstractions.Models; + +namespace Kwtc.Tjek.Client; + +public class Client : IClient +{ + private readonly IHttpClientFactory httpClientFactory; + + public Client(IHttpClientFactory httpClientFactory) + { + this.httpClientFactory = httpClientFactory; + } + + public async Task> Search(string query, CancellationToken cancellationToken = default) + { + //https://squid-api.tjek.com/v2/offers/search?query= + + // TODO: Ensure we can handle queries with whitespaces + + var client = this.httpClientFactory.CreateClient(Constants.HttpClientName); + var response = await client.GetAsync($"v2/offers/search?query={query}", cancellationToken); + response.EnsureSuccessStatusCode(); + + var contentStream = await response.Content.ReadAsStreamAsync(cancellationToken); + var result = await JsonSerializer.DeserializeAsync>(contentStream, cancellationToken: cancellationToken); + + return result ?? []; + } +} diff --git a/src/Kwtc.Tjek.Client/ClientConfig.cs b/src/Kwtc.Tjek.Client/ClientConfig.cs new file mode 100644 index 0000000..a88407f --- /dev/null +++ b/src/Kwtc.Tjek.Client/ClientConfig.cs @@ -0,0 +1,8 @@ +namespace Kwtc.Tjek.Client; + +public class ClientConfig +{ + public static string SectionName => "TjekClientConfig"; + + public string ApiKey { get; set; } = string.Empty; +} diff --git a/src/Kwtc.Tjek.Client/Constants.cs b/src/Kwtc.Tjek.Client/Constants.cs new file mode 100644 index 0000000..f917c96 --- /dev/null +++ b/src/Kwtc.Tjek.Client/Constants.cs @@ -0,0 +1,8 @@ +namespace Kwtc.Tjek.Client; + +public static class Constants +{ + public static string HttpClientName => "Kwtc.Tjek.Client"; + + public static string BaseUrl => "https://squid-api.tjek.com/v2"; +} diff --git a/src/Kwtc.Tjek.Client/Kwtc.Tjek.Client.csproj b/src/Kwtc.Tjek.Client/Kwtc.Tjek.Client.csproj new file mode 100644 index 0000000..6eab854 --- /dev/null +++ b/src/Kwtc.Tjek.Client/Kwtc.Tjek.Client.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + Kwtc.Tjek.Client + enable + enable + true + + + + + + + + + + + diff --git a/src/Kwtc.Tjek.Client/ServiceCollectionExtensions.cs b/src/Kwtc.Tjek.Client/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..83b8c69 --- /dev/null +++ b/src/Kwtc.Tjek.Client/ServiceCollectionExtensions.cs @@ -0,0 +1,30 @@ +using Kwtc.Tjek.Client.Abstractions; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Kwtc.Tjek.Client; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddTjekClientServices(this IServiceCollection services, ConfigurationManager configuration) + { + var clientConfig = configuration.GetSection(ClientConfig.SectionName).Get(); + if (clientConfig is null) + { + throw new InvalidOperationException("Client configuration is missing"); + } + + services.Configure(configuration.GetSection(ClientConfig.SectionName)); + + services.AddHttpClient(Constants.HttpClientName, client => + { + client.BaseAddress = new Uri(Constants.BaseUrl); + client.DefaultRequestHeaders.Add("Accept", "application/json"); + client.DefaultRequestHeaders.Add("X-Api-Key", clientConfig.ApiKey); + }); + + services.AddTransient(); + + return services; + } +} diff --git a/test/Kwtc.Tjek.Client.Tests/Kwtc.Tjek.Client.Tests.csproj b/test/Kwtc.Tjek.Client.Tests/Kwtc.Tjek.Client.Tests.csproj new file mode 100644 index 0000000..30393e3 --- /dev/null +++ b/test/Kwtc.Tjek.Client.Tests/Kwtc.Tjek.Client.Tests.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + false + true + + + + + + + + + + + + + + + + + + diff --git a/test/Kwtc.Tjek.Client.Tests/UnitTest1.cs b/test/Kwtc.Tjek.Client.Tests/UnitTest1.cs new file mode 100644 index 0000000..b221d2a --- /dev/null +++ b/test/Kwtc.Tjek.Client.Tests/UnitTest1.cs @@ -0,0 +1,10 @@ +namespace Kwtc.Tjek.Client.Tests; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + + } +} \ No newline at end of file