diff --git a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs index 276b1ae..32e99c5 100644 --- a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs +++ b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using MongoDB.Bson; using MongoDB.Driver; +using Retroactiune.DataTransferObjects; using Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures; using Retroactiune.Models; using Retroactiune.Settings; diff --git a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs index 94517c5..e751883 100644 --- a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs +++ b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs @@ -10,7 +10,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures { public class MongoDbFixture : IAsyncDisposable { - private IMongoDbSettings _settings; + private readonly IMongoDbSettings _settings; public IMongoDatabase Database { get; } public IMongoCollection FeedbackReceiverCollection => diff --git a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs index 6c61769..76a69cf 100644 --- a/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs +++ b/Retroactiune.UnitTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiverController.cs @@ -5,6 +5,7 @@ using AutoFixture.Xunit2; using Microsoft.AspNetCore.Mvc; using Moq; using Retroactiune.Controllers; +using Retroactiune.DataTransferObjects; using Retroactiune.Models; using Retroactiune.Services; using Xunit; diff --git a/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs b/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs index 1eedc94..9c8de7d 100644 --- a/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs +++ b/Retroactiune.WebAPI/Controllers/FeedbackReceiversController.cs @@ -7,6 +7,7 @@ using AutoMapper; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; +using Retroactiune.DataTransferObjects; using Retroactiune.Models; using Retroactiune.Services; @@ -34,10 +35,10 @@ namespace Retroactiune.Controllers /// /// The list of FeedbackReceivers /// A BasicResponse indicating success. - /// Returns the newly created item + /// Returns an ok message. /// If the items is invalid [HttpPost] - [ProducesResponseType(typeof(BasicResponse), StatusCodes.Status201Created)] + [ProducesResponseType(typeof(BasicResponse), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task Post([Required] IEnumerable items) { diff --git a/Retroactiune.WebAPI/Models/BasicResponse.cs b/Retroactiune.WebAPI/DataTransferObjects/BasicResponse.cs similarity index 79% rename from Retroactiune.WebAPI/Models/BasicResponse.cs rename to Retroactiune.WebAPI/DataTransferObjects/BasicResponse.cs index c8ee12c..3a9ec3f 100644 --- a/Retroactiune.WebAPI/Models/BasicResponse.cs +++ b/Retroactiune.WebAPI/DataTransferObjects/BasicResponse.cs @@ -1,4 +1,4 @@ -namespace Retroactiune.Models +namespace Retroactiune.DataTransferObjects { /// /// Simple response model that contains a message. diff --git a/Retroactiune.WebAPI/Models/FeedbackReceiverInDto.cs b/Retroactiune.WebAPI/DataTransferObjects/FeedbackReceiverInDto.cs similarity index 60% rename from Retroactiune.WebAPI/Models/FeedbackReceiverInDto.cs rename to Retroactiune.WebAPI/DataTransferObjects/FeedbackReceiverInDto.cs index dad631d..f2c005d 100644 --- a/Retroactiune.WebAPI/Models/FeedbackReceiverInDto.cs +++ b/Retroactiune.WebAPI/DataTransferObjects/FeedbackReceiverInDto.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; +using Retroactiune.Models; -namespace Retroactiune.Models +namespace Retroactiune.DataTransferObjects { /// /// FeedbackReceiverInDto is the DTO for , used in incoming requests. @@ -13,11 +14,4 @@ namespace Retroactiune.Models [Required] public string Description { get; set; } } - - /// - /// FeedbackReceiverDto is the DTO for , used in outgoing requests. - /// - public class FeedbackReceiverOutDto : FeedbackReceiver - { - } } \ No newline at end of file diff --git a/Retroactiune.WebAPI/DataTransferObjects/FeedbackReceiverOutDto.cs b/Retroactiune.WebAPI/DataTransferObjects/FeedbackReceiverOutDto.cs new file mode 100644 index 0000000..406ac63 --- /dev/null +++ b/Retroactiune.WebAPI/DataTransferObjects/FeedbackReceiverOutDto.cs @@ -0,0 +1,11 @@ +using Retroactiune.Models; + +namespace Retroactiune.DataTransferObjects +{ + /// + /// FeedbackReceiverDto is the DTO for , used in outgoing requests. + /// + public class FeedbackReceiverOutDto : FeedbackReceiver + { + } +} \ No newline at end of file diff --git a/Retroactiune.WebAPI/DataTransferObjects/GenerateTokensDto.cs b/Retroactiune.WebAPI/DataTransferObjects/GenerateTokensDto.cs new file mode 100644 index 0000000..ee85520 --- /dev/null +++ b/Retroactiune.WebAPI/DataTransferObjects/GenerateTokensDto.cs @@ -0,0 +1,21 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Retroactiune.DataAnnotations; + +namespace Retroactiune.DataTransferObjects +{ + /// + /// GenerateTokensDto is the payload that is sent by the user for generating tokens. + /// + public class GenerateTokensDto + { + [Range(1, 1000, ErrorMessage = "numberOfTokens is out of range, allowed ranges [1-1000]")] + public int NumberOfTokens { get; set; } = 1; + + [Required, StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)] + public string FeedbackReceiverId { get; set; } + + [DatetimeNotInThePast(ErrorMessage = "expiryTime cannot be in the past!")] + public DateTime? ExpiryTime { get; set; } = null; + } +} \ No newline at end of file diff --git a/Retroactiune.WebAPI/MappingProfile.cs b/Retroactiune.WebAPI/MappingProfile.cs index d90b68b..e3c0e58 100644 --- a/Retroactiune.WebAPI/MappingProfile.cs +++ b/Retroactiune.WebAPI/MappingProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using Retroactiune.DataTransferObjects; using Retroactiune.Models; namespace Retroactiune diff --git a/Retroactiune.WebAPI/Models/Feedback.cs b/Retroactiune.WebAPI/Models/Feedback.cs new file mode 100644 index 0000000..3132b92 --- /dev/null +++ b/Retroactiune.WebAPI/Models/Feedback.cs @@ -0,0 +1,7 @@ +namespace Retroactiune.Models +{ + public class Feedback + { + // TODO: Entity model for feedback. + } +} \ No newline at end of file diff --git a/Retroactiune.WebAPI/Models/FeedbackReceiver.cs b/Retroactiune.WebAPI/Models/FeedbackReceiver.cs index a7b3a73..80d9b82 100644 --- a/Retroactiune.WebAPI/Models/FeedbackReceiver.cs +++ b/Retroactiune.WebAPI/Models/FeedbackReceiver.cs @@ -6,7 +6,7 @@ using MongoDB.Bson.Serialization.Attributes; namespace Retroactiune.Models { /// - /// FeedbackReceiver is the thing that receives feedback. + /// FeedbackReceiver is the entity that receives feedback from the users. /// public class FeedbackReceiver { diff --git a/Retroactiune.WebAPI/Models/Token.cs b/Retroactiune.WebAPI/Models/Token.cs new file mode 100644 index 0000000..014d296 --- /dev/null +++ b/Retroactiune.WebAPI/Models/Token.cs @@ -0,0 +1,30 @@ +using System; +using System.Text.Json.Serialization; +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; + +namespace Retroactiune.Models +{ + /// + /// Token represents a token. + /// Token is used to authorize a for the . + /// + public class Token + { + [BsonId, JsonPropertyName("id")] + [BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } + + [BsonRepresentation(BsonType.ObjectId), JsonPropertyName("feedback_receiver_id")] + public string FeedbackReceiverId { get; set; } + + [JsonPropertyName("time_used")] + public DateTime? TimeUsed { get; set; } + + [JsonPropertyName("created_at")] + public DateTime CreatedAt { get; set; } + + [JsonPropertyName("expiry_time")] + public DateTime? ExpiryTime { get; set; } + } +} \ No newline at end of file diff --git a/Retroactiune.WebAPI/Services/ITokensService.cs b/Retroactiune.WebAPI/Services/ITokensService.cs new file mode 100644 index 0000000..2f1603c --- /dev/null +++ b/Retroactiune.WebAPI/Services/ITokensService.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Retroactiune.Models; + +namespace Retroactiune.Services +{ + public interface ITokensService + { + public Task CreateManyAsync(IEnumerable items); + } +} \ No newline at end of file diff --git a/Retroactiune.WebAPI/Services/TokensService.cs b/Retroactiune.WebAPI/Services/TokensService.cs new file mode 100644 index 0000000..bae3138 --- /dev/null +++ b/Retroactiune.WebAPI/Services/TokensService.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using MongoDB.Driver; +using Retroactiune.Models; +using Retroactiune.Settings; + +// TODO: Test +namespace Retroactiune.Services +{ + public class TokensService : ITokensService + { + private readonly IMongoCollection _collection; + + public TokensService(IMongoClient client, IMongoDbSettings settings) + { + var database = client.GetDatabase(settings.DatabaseName); + _collection = database.GetCollection(settings.TokensCollectionName); + } + + public async Task CreateManyAsync(IEnumerable items) + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Retroactiune.WebAPI/Startup.cs b/Retroactiune.WebAPI/Startup.cs index 9c53707..9a841f7 100644 --- a/Retroactiune.WebAPI/Startup.cs +++ b/Retroactiune.WebAPI/Startup.cs @@ -38,6 +38,7 @@ namespace Retroactiune // Services services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(i => { var settings = i.GetService>();