Skip to content

Commit

Permalink
feat: Get tagdata in a container (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
taustad authored Nov 9, 2023
1 parent 8a724f7 commit 2f21d8e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
18 changes: 17 additions & 1 deletion datasheetapi/Controllers/ContainersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ public class ContainersController : ControllerBase
private readonly IConversationService _conversationService;
private readonly ILogger<ContractsController> _logger;
private readonly IUserService _userService;
private readonly ITagDataService _tagDataService;

public ContainersController(
ILoggerFactory loggerFactory,
IContainerService containerService,
IConversationService conversationService,
IUserService userService
IUserService userService,
ITagDataService tagDataService
)
{
_logger = loggerFactory.CreateLogger<ContractsController>();
_containerService = containerService;
_conversationService = conversationService;
_userService = userService;
_tagDataService = tagDataService;
}

[HttpGet("{containerId}")]
Expand Down Expand Up @@ -67,4 +70,17 @@ public async Task<ActionResult<List<GetConversationDto>>> GetConversations([NotE

return conversations.Select(conversation => conversation.ToDto(userIdNameMap)).ToList();
}

[HttpGet("{containerId}/tags")]
public async Task<ActionResult<List<TagDataDto>>> GetTags([NotEmptyGuid] Guid containerId)
{
var container = await _containerService.GetContainer(containerId) ??
throw new NotFoundException($"Container with id {containerId} not found");

var tagNos = container.Tags.Select(t => t.TagNo).ToList();

var tags = await _tagDataService.GetTagDataByTagNos(tagNos);

return Ok(tags.ToDto());
}
}
5 changes: 5 additions & 0 deletions datasheetapi/Services/DummyServices/DummyFAMService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public DummyFAMService(ILoggerFactory loggerFactory)
return await Task.Run(() => _tagData.Find(d => d.TagNo == tagNo));
}

public async Task<List<ITagData>> GetTagDataForTagNos(List<string> tagNos)
{
return await Task.Run(() => _tagData.Where(d => d.TagNo != null && tagNos.Contains(d.TagNo)).ToList());
}

public async Task<List<ITagData>> GetTagData()
{
return await Task.Run(() => _tagData);
Expand Down
1 change: 1 addition & 0 deletions datasheetapi/Services/DummyServices/IFAMService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace datasheetapi.Services;
public interface IFAMService
{
Task<ITagData?> GetTagData(string tagNo);
Task<List<ITagData>> GetTagDataForTagNos(List<string> tagNos);
Task<List<ITagData>> GetTagData();
}
1 change: 1 addition & 0 deletions datasheetapi/Services/ITagDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace datasheetapi.Services;
public interface ITagDataService
{
Task<ITagData> GetTagDataByTagNo(string tagNo);
Task<List<ITagData>> GetTagDataByTagNos(List<string> tagNos);
Task<List<ITagData>> GetAllTagData();
}
7 changes: 7 additions & 0 deletions datasheetapi/Services/TagDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public async Task<ITagData> GetTagDataByTagNo(string tagNo)
return tagData ?? throw new NotFoundException($"Unable to find Tag Data for Tag No - {tagNo}.");
}

public async Task<List<ITagData>> GetTagDataByTagNos(List<string> tagNos)
{
var tagData = await _FAMService.GetTagDataForTagNos(tagNos);

return tagData;
}

public async Task<List<ITagData>> GetAllTagData()
{
var allTagData = await _FAMService.GetTagData();
Expand Down

0 comments on commit 2f21d8e

Please sign in to comment.