-
Notifications
You must be signed in to change notification settings - Fork 0
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
PartTemplate work #293
PartTemplate work #293
Changes from 1 commit
4d2436d
106b9d8
1c2f3ad
6d3a43e
010d7e2
f9fb20d
d6438ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ public IQueryable<PartTemplate> FindAll() | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remember to take off AsNoTracking up above if we're amending these things now |
||
public void Add(PartTemplate entity) | ||
{ | ||
throw new NotImplementedException(); | ||
this.serviceDbContext.PartTemplates.Add(entity); | ||
} | ||
|
||
public void Remove(PartTemplate entity) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { UpdateApiActions } from '@linn-it/linn-form-components-library'; | ||
import { partTemplateActionTypes as actionTypes } from './index'; | ||
import * as itemTypes from '../itemTypes'; | ||
import config from '../config'; | ||
|
||
export default new UpdateApiActions( | ||
itemTypes.partTemplate.item, | ||
itemTypes.partTemplate.actionType, | ||
itemTypes.partTemplate.uri, | ||
actionTypes, | ||
config.appRoot | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,16 @@ import partsSelectors from '../../selectors/partsSelectors'; | |
import { getPrivileges } from '../../selectors/userSelectors'; | ||
import partTemplatesActions from '../../actions/partTemplatesActions'; | ||
import partTemplatesSelectors from '../../selectors/partTemplatesSelectors'; | ||
import partTemplateActions from '../../actions/partTemplatesActions'; | ||
import partTemplateSelectors from '../../selectors/partTemplatesSelectors'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need these extra action creators and selectors in the parts container? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also just realised I never got you set up witht the linter which would have complained about this most likely. Give me a shout today and I can try and remember what we need to do to get it working There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can talk about it after stand up if you're about |
||
const mapStateToProps = (state, { match }) => ({ | ||
linkToSources: match?.url?.endsWith('/sources'), | ||
items: partsSelectors.getSearchItems(state), | ||
loading: partsSelectors.getSearchLoading(state), | ||
privileges: getPrivileges(state), | ||
partTemplates: partTemplatesSelectors.getItems(state) | ||
partTemplates: partTemplatesSelectors.getItems(state), | ||
partTemplate: partTemplateSelectors.getItem(state) | ||
}); | ||
|
||
const initialise = () => dispatch => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { collectionStoreFactory } from '@linn-it/linn-form-components-library'; | ||
import { partTemplateActionTypes as actionTypes } from '../../actions'; | ||
import * as itemTypes from '../../itemTypes'; | ||
|
||
const defaultState = { | ||
loading: false, | ||
items: [] | ||
}; | ||
|
||
export default collectionStoreFactory( | ||
itemTypes.partTemplate.actionType, | ||
actionTypes, | ||
defaultState | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { ItemSelectors } from '@linn-it/linn-form-components-library'; | ||
import * as itemTypes from '../itemTypes'; | ||
|
||
export default new ItemSelectors(itemTypes.partTemplate.item); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,9 @@ public PartsModule( | |
|
||
this.partTemplateService = partTemplateService; | ||
this.Get("/inventory/part-templates", _ => this.GetPartTemplates()); | ||
this.Get("/inventory/part-templates/{id}", parameters => this.GetPartTemplate(parameters.id)); | ||
this.Put("/inventory/part-templates/{id}", parameters => this.UpdatePartTemplate(parameters.id)); | ||
this.Post("/inventory/part-templates", parameters => this.AddPartTemplate()); | ||
|
||
this.productAnalysisCodeService = productAnalysisCodeService; | ||
this.Get("inventory/product-analysis-codes", _ => this.GetProductAnalysisCodes()); | ||
|
@@ -230,6 +233,33 @@ private object GetPartCategories() | |
.WithMediaRangeModel("text/html", ApplicationSettings.Get); | ||
} | ||
|
||
private object AddPartTemplate() | ||
{ | ||
this.RequiresAuthentication(); | ||
var resource = this.Bind<PartTemplateResource>(); | ||
var result = this.partTemplateService.Add(resource); | ||
return this.Negotiate.WithStatusCode(HttpStatusCode.Created) | ||
.WithModel(result) | ||
.WithMediaRangeModel("text/html", ApplicationSettings.Get) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to handle html here because it will never be requested in a PUT or a POST |
||
.WithView("Index"); | ||
} | ||
|
||
private object GetPartTemplate(string id) | ||
{ | ||
var result = this.partTemplateService.GetById(id); | ||
return this.Negotiate.WithModel(result) | ||
.WithMediaRangeModel("text/html", ApplicationSettings.Get); | ||
} | ||
|
||
private object UpdatePartTemplate(string id) | ||
{ | ||
this.RequiresAuthentication(); | ||
var resource = this.Bind<PartTemplateResource>(); | ||
var result = this.partTemplateService.Update(id, resource); | ||
return this.Negotiate.WithModel(result) | ||
.WithMediaRangeModel("text/html", ApplicationSettings.Get); | ||
} | ||
|
||
private object GetPartTemplates() | ||
{ | ||
var result = this.partTemplateService.GetAll(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Linn.Stores.Service.ResponseProcessors | ||
{ | ||
using System.Collections.Generic; | ||
using Linn.Common.Facade; | ||
using Linn.Common.Nancy.Facade; | ||
using Linn.Stores.Domain.LinnApps.Parts; | ||
|
||
public class PartTemplateResponseProcessor : JsonResponseProcessor<PartTemplate> | ||
{ | ||
public PartTemplateResponseProcessor(IResourceBuilder<PartTemplate> resourceBuilder) | ||
: base(resourceBuilder, "linnapps-part-templates", 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be the singular. "linnapps-part-template" |
||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace Linn.Stores.Service.Tests.PartsModuleSpecs | ||
{ | ||
using System.Collections.Generic; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these usings needed for the get by id? |
||
using System.Linq; | ||
|
||
using FluentAssertions; | ||
|
||
using Linn.Common.Facade; | ||
using Linn.Stores.Domain.LinnApps.Parts; | ||
using Linn.Stores.Resources.Parts; | ||
|
||
using Nancy; | ||
using Nancy.Testing; | ||
|
||
using NSubstitute; | ||
|
||
using NUnit.Framework; | ||
|
||
public class WhenGettingPartTemplatesById : ContextBase | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
var a = new PartTemplate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd use a more descriptive variable name than a |
||
{ | ||
PartRoot = "PARTTEMP" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might be nice to declare "PARTTEMP" into a string field and then you can reference it against all the tests which avoids typos and also makes it clear what's being tested |
||
}; | ||
|
||
this.PartTemplateService.GetById(a.PartRoot) | ||
.Returns(new SuccessResult<PartTemplate>(a)); | ||
|
||
this.Response = this.Browser.Get( | ||
"/inventory/part-templates/PARTTEMP", | ||
with => | ||
{ | ||
with.Header("Accept", "application/json"); | ||
}).Result; | ||
} | ||
|
||
[Test] | ||
public void ShouldReturnOk() | ||
{ | ||
this.Response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
} | ||
|
||
[Test] | ||
public void ShouldCallService() | ||
{ | ||
this.PartTemplateService.Received().GetById("PARTTEMP"); | ||
} | ||
|
||
[Test] | ||
public void ShouldReturnResource() | ||
{ | ||
var resource = this.Response.Body.DeserializeJson<PartTemplateResource>(); | ||
resource.PartRoot.Should().Be("PARTTEMP"); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we tend to add a newline at the end of files to stop github complaining at us |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember you can set the "self" linkrel in GetLocation down below