Skip to content

Commit

Permalink
photos d'accueil #26 - finalization features 'visit farm'
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Sep 12, 2024
1 parent 07b4e18 commit 1f60630
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.viandeendirect.domains.production;

import eu.viandeendirect.api.BeefProductionsApiDelegate;
import eu.viandeendirect.domains.user.ProducerRepository;
import eu.viandeendirect.model.BeefProduction;
import eu.viandeendirect.model.PackageLot;
import eu.viandeendirect.model.Production;
Expand Down Expand Up @@ -29,6 +30,8 @@ public class BeefProductionService implements BeefProductionsApiDelegate {
AuthenticationServiceSpecs producerService;
@Autowired
private SaleRepository saleRepository;
@Autowired
private ProducerRepository producerRepository;

@Override
public ResponseEntity<BeefProduction> getBeefProduction(Integer beefProductionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ public ResponseEntity<Integer> getProductionPercentageSold(Integer productionId)
return new ResponseEntity<>(roundedPercentageSold, OK);
}

@Override
public ResponseEntity<Producer> getProductionProducerPublicData(Integer productionId) {
Production production = productionRepository.findById(productionId).get();
Producer producer = production.getProducer();
var producerWithPublicData = new Producer();
producerWithPublicData.setFarmName(producer.getFarmName());
producerWithPublicData.setSlideShowUrl(producer.getSlideShowUrl());
producerWithPublicData.setWebsiteUrl(producer.getWebsiteUrl());
return new ResponseEntity<>(producerWithPublicData, OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ databaseChangeLog:
author: benjamin
changes:
- addColumn:
tableName: producers
columns:
- column:
name: slideShowUrl
type: VARCHAR(255)
- column:
name: websiteUrl
type: VARCHAR(255)
- column:
name: farmName
type: VARCHAR(255)
tableName: producers
columns:
- column:
name: slide_show_url
type: VARCHAR(255)
- column:
name: website_url
type: VARCHAR(255)
- column:
name: farm_name
type: VARCHAR(255)
- dropColumn:
tableName: producers
columnName: saleCredits
tableName: producers
columnName: sales_credits
6 changes: 6 additions & 0 deletions frontend/app/src/api/mock/MockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MockApiCustomers } from "./MockApiCustomers.ts"
import { MockApiProductions } from "./MockApiProductions.ts"
import { MockApiSales } from "./MockApiSales.ts"
import { MockApiProducers } from "./MockApiProducers.ts"
import { getPopoverUtilityClass } from "@mui/material"

export class MockApi {

Expand Down Expand Up @@ -30,6 +31,11 @@ export class MockApi {
return this.mockApiProductions.getProductionPercentageSold()
}

getProductionProducerPublicData(args) {
this.log('getProducerPublicData', args)
return this.mockApiProductions.getProductionProducerPublicData()
}

getBeefProduction(args) {
this.log('getBeefProduction', args)
return this.mockApiProductions.getBeefProduction()
Expand Down
10 changes: 10 additions & 0 deletions frontend/app/src/api/mock/MockApiProductions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,14 @@ export class MockApiProductions {
}
return [template1, template2, template3]
}


getProductionProducerPublicData() {
return {
id: 1,
slideShowUrl: 'https://docs.google.com/presentation/d/1sqDR1v9AZLQYVJo2iT1gAVZ4UX25RamEBXeTmiUWRa4/edit?usp=sharing',
websiteUrl: 'https://www.lemonde.fr',
farmName: 'La ferme des Marronniers'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default function EditableTextField({
defaultValue={value}
variant="standard"
InputProps={{ readOnly: !writable }}
disabled={!writable && !(value?.length > 0)}
onChange={(event) => setValue(event.target.value)}

fullWidth
/>
{getActions()}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function VisitFarmButton({producer}) {
<Button variant='contained' onClick={() => setSlideShowDisplayed(false)}>Fermer</Button>
</DialogActions>
</Dialog>
<Button size='small' onClick={() => setSlideShowDisplayed(true)}>Je visite la ferme</Button>
<Button variant='outlined' size='small' onClick={() => setSlideShowDisplayed(true)}>Je visite la ferme</Button>
</>
}
return <></>
Expand Down
53 changes: 44 additions & 9 deletions frontend/app/src/domains/producer/views/ProducerAccountView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function ProducerAccountView() {

const WEB_SITE_URL_FIELD = 'websiteUrl';
const SLIDE_SHOW_URL_FIELD = 'slideShowUrl';
const FARM_NAME_FIELD = 'farmeName';

const {keycloak} = useKeycloak()
const apiBuilder = new ApiBuilder()
Expand All @@ -26,17 +27,39 @@ export default function ProducerAccountView() {

return <>
<Typography variant="h6">Gestion du compte</Typography>
<br/>
<Typography variant='subtitle1'>Configuration des paiements</Typography>
{displayStripeAccount()}

<Typography variant='subtitle1'>Présentation de la ferme</Typography>

<EditableTextField
label="nom de l'exploitation agricole"
initialValue={producer.farmName}
validateCallback={async (updatedFarmName) => {
const updatedProducer = { ...producer, farmName: updatedFarmName };
await updateProducer(updatedProducer)
setProducer(updatedProducer)
}}
editable={currentlyEditedField === undefined || currentlyEditedField === FARM_NAME_FIELD}
toggleCallback={() => {
if(currentlyEditedField) {
setCurrentlyEditedField(undefined)
} else {
setCurrentlyEditedField(FARM_NAME_FIELD)
}
}}
/>

<br/>

<EditableTextField
label='adresse du site web'
initialValue={producer.websiteUrl}
validateCallback={(updatedWebSiteUrl) => {
setProducer({...producer, websiteUrl: updatedWebSiteUrl})
updateProducer()
validateCallback={async (updatedWebSiteUrl) => {
const updatedProducer = { ...producer, websiteUrl: updatedWebSiteUrl };
await updateProducer(updatedProducer)
setProducer(updatedProducer)
}}
editable={currentlyEditedField === undefined || currentlyEditedField === WEB_SITE_URL_FIELD}
toggleCallback={() => {
Expand All @@ -48,10 +71,16 @@ export default function ProducerAccountView() {
}}
/>

<br/>

<EditableTextField
label='adresse du diaporama'
initialValue={producer.slideShowUrl}
validateCallback={() => console.log('test')}
validateCallback={async (updatedSlideShowUrl) => {
const updatedProducer = { ...producer, slideShowUrl: updatedSlideShowUrl };
await updateProducer(updatedProducer)
setProducer(updatedProducer)
}}
editable={currentlyEditedField === undefined || currentlyEditedField === SLIDE_SHOW_URL_FIELD}
toggleCallback={() => {
if(currentlyEditedField) {
Expand All @@ -70,7 +99,7 @@ export default function ProducerAccountView() {
{displayStripeAccountLink()}
</>
} else {
return <Button disabled={stripeAccountCreationPending} onClick={createStripeAccount}>
return <Button variant='outlined' size='small' disabled={stripeAccountCreationPending} onClick={createStripeAccount}>
Créer un compte de paiement Stripe
{displayStripeAccountCreationProgress()}
</Button>
Expand All @@ -83,8 +112,14 @@ export default function ProducerAccountView() {
return <Button onClick={() => window.location.href = producer.stripeAccount.accountLink}>Saisissez votre RIB et vos informations réglementaires sur Stripe</Button>
} else {
return <>
<Button onClick={() => window.open('https://dashboard.stripe.com/', '_blank')}>Consultez vos encaissements sur Stripe</Button>
<Button onClick={() => window.open(producer.stripeAccount.accountLink, '_self')}>Modifier votre RIB et vos informations réglementaires sur Stripe</Button>
<div>
<Button size='small' variant='outlined' onClick={() => window.open('https://dashboard.stripe.com/', '_blank')}>Consultez vos encaissements sur Stripe</Button>
</div>
<br/>
<div>
<Button size='small' variant='outlined' onClick={() => window.open(producer.stripeAccount.accountLink, '_self')}>Modifiez votre RIB et vos informations réglementaires sur Stripe</Button>
</div>
<br/>
</>
}
}
Expand All @@ -96,9 +131,9 @@ export default function ProducerAccountView() {
}
}

async function updateProducer() {
async function updateProducer(updatedProducer: Producer) {
const api = await apiBuilder.getAuthenticatedApi(keycloak)
await api.updateProducer({producerId: producer.id, producer: producer})
await api.updateProducer({producerId: producer.id, producer: updatedProducer})
}

async function createStripeAccount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default function BeefProductionCustomerCard({production: production}) {
const loadData = async () => {
const api = await apiBuilder.getAnonymousApi()
const loadedBeefProduction = await api.getBeefProduction({beefProductionId: production.id})
const producer = await api.getProductionProducerPublicData({productionId: production.id})
loadedBeefProduction.producer = producer
setBeefProduction(loadedBeefProduction)
const loadedPercentageSold = await api.getProductionPercentageSold({productionId: production.id})
setPercentageSold(+loadedPercentageSold)
Expand All @@ -33,7 +35,7 @@ export default function BeefProductionCustomerCard({production: production}) {
<div className="sale-customer-card__product-information">
<Typography variant="h5">Viande de boeuf</Typography>
<PieChart percentage={percentageSold} description={<><div>{percentageSold}%</div><div>déjà vendu</div></>}></PieChart>
</div>
</div>
<div className="sale-customer-card__general-information">
<div className="sale-customer-card__animal-information">
<div className="sale-customer-card__animal">
Expand Down
36 changes: 30 additions & 6 deletions openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,29 @@ paths:
in: path
required: true

/productions/{productionId}/producer/publicData:
summary: Path used to access producers public data for a given production
get:
parameters:
- in: path
name: productionId
schema:
type: integer
description: "the id of the Production"
required: true
security:
- oAuth2ForViandeEnDirect: [read]
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/Producer'
description: Successful response - returns a `Producer` entities, with only public data.
operationId: getProductionProducerPublicData
summary: Get a producer's public data for a production identified by its id.
description: Gets a `Producer` entities, with only public data for a production identified by its id.

/beefProductions:
post:
requestBody:
Expand Down Expand Up @@ -447,12 +470,13 @@ paths:
schema:
type: integer
required: true
- in: query
name: producer
description: The updated producer details.
schema:
$ref: '#/components/schemas/Producer'
required: true
requestBody:
description: A new `customer` to be created.
content:
application/json:
schema:
$ref: '#/components/schemas/Producer'
required: true
security:
- oAuth2ForViandeEnDirect: [read]
responses:
Expand Down

0 comments on commit 1f60630

Please sign in to comment.