Skip to content

Commit

Permalink
Page d'accueil producteur #35 - definition du service payments summar…
Browse files Browse the repository at this point in the history
…y dans openapi
  • Loading branch information
benjaminpochat committed Sep 3, 2024
1 parent fee3811 commit 79a648b
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import eu.viandeendirect.api.ProducersApiDelegate;
import eu.viandeendirect.domains.payment.StripeService;
import eu.viandeendirect.domains.sale.SaleRepository;
import eu.viandeendirect.model.Customer;
import eu.viandeendirect.model.Producer;
import eu.viandeendirect.model.Sale;
import eu.viandeendirect.model.StripeAccount;
import eu.viandeendirect.model.*;
import eu.viandeendirect.security.specs.AuthenticationServiceSpecs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -113,4 +110,19 @@ public ResponseEntity<StripeAccount> getStripeAccount(Integer producerId) {
throw new ResponseStatusException(INTERNAL_SERVER_ERROR, "Une erreur s'est produite à la création du lien vers le compte Stripe", e);
}
}

@Override
public ResponseEntity<PaymentsSummary> getProducerPaymentsSummary(Integer producerId) {
Producer producer = authenticationService.getAuthenticatedProducer();
if (!producer.getId().equals(producerId)) {
return new ResponseEntity<>(FORBIDDEN);
}
//TODO : calculer les montant à partir des API Stripe (https://docs.stripe.com/api/balance_transactions/object)
PaymentsSummary paymentsSummary = new PaymentsSummary();
paymentsSummary.setDaylyTotal(100f);
paymentsSummary.setWeeklyTotal(1000f);
paymentsSummary.setMonthlyTotal(4000f);
paymentsSummary.setYearlyTotal(12000f);
return new ResponseEntity<>(paymentsSummary, OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package eu.viandeendirect.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Generated;

import java.util.Objects;

/**
* the summary of payments made
*/

@Schema(name = "PaymentsSummary", description = "the summary of payments made")
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
public class PaymentsSummary {

@JsonProperty("daylyTotal")
private Float daylyTotal;

@JsonProperty("weeklyTotal")
private Float weeklyTotal;

@JsonProperty("monthlyTotal")
private Float monthlyTotal;

@JsonProperty("yearlyTotal")
private Float yearlyTotal;

public PaymentsSummary daylyTotal(Float daylyTotal) {
this.daylyTotal = daylyTotal;
return this;
}

/**
* the total amount paid for last day
* @return daylyTotal
*/

@Schema(name = "daylyTotal", description = "the total amount paid for last day", required = false)
public Float getDaylyTotal() {
return daylyTotal;
}

public void setDaylyTotal(Float daylyTotal) {
this.daylyTotal = daylyTotal;
}

public PaymentsSummary weeklyTotal(Float weeklyTotal) {
this.weeklyTotal = weeklyTotal;
return this;
}

/**
* the total amount paid for last week
* @return weeklyTotal
*/

@Schema(name = "weeklyTotal", description = "the total amount paid for last week", required = false)
public Float getWeeklyTotal() {
return weeklyTotal;
}

public void setWeeklyTotal(Float weeklyTotal) {
this.weeklyTotal = weeklyTotal;
}

public PaymentsSummary monthlyTotal(Float monthlyTotal) {
this.monthlyTotal = monthlyTotal;
return this;
}

/**
* the total amount paid for last month
* @return monthlyTotal
*/

@Schema(name = "monthlyTotal", description = "the total amount paid for last month", required = false)
public Float getMonthlyTotal() {
return monthlyTotal;
}

public void setMonthlyTotal(Float monthlyTotal) {
this.monthlyTotal = monthlyTotal;
}

public PaymentsSummary yearlyTotal(Float yearlyTotal) {
this.yearlyTotal = yearlyTotal;
return this;
}

/**
* the total amount paid for last year
* @return yearlyTotal
*/

@Schema(name = "yearlyTotal", description = "the total amount paid for last year", required = false)
public Float getYearlyTotal() {
return yearlyTotal;
}

public void setYearlyTotal(Float yearlyTotal) {
this.yearlyTotal = yearlyTotal;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PaymentsSummary paymentsSummary = (PaymentsSummary) o;
return Objects.equals(this.daylyTotal, paymentsSummary.daylyTotal) &&
Objects.equals(this.weeklyTotal, paymentsSummary.weeklyTotal) &&
Objects.equals(this.monthlyTotal, paymentsSummary.monthlyTotal) &&
Objects.equals(this.yearlyTotal, paymentsSummary.yearlyTotal);
}

@Override
public int hashCode() {
return Objects.hash(daylyTotal, weeklyTotal, monthlyTotal, yearlyTotal);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class PaymentsSummary {\n");
sb.append(" daylyTotal: ").append(toIndentedString(daylyTotal)).append("\n");
sb.append(" weeklyTotal: ").append(toIndentedString(weeklyTotal)).append("\n");
sb.append(" monthlyTotal: ").append(toIndentedString(monthlyTotal)).append("\n");
sb.append(" yearlyTotal: ").append(toIndentedString(yearlyTotal)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

41 changes: 41 additions & 0 deletions openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ paths:
$ref: '#/components/schemas/StripeAccount'
description: Successful response - returns a Stripe account
operationId: getStripeAccount
/producers/{producerId}/payments/summary:
parameters:
- name: producerId
description: the id of the producer related to the payments summary
schema:
type: integer
in: path
required: true
get:
security:
- oAuth2ForViandeEnDirect: [read]
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/PaymentsSummary'
description: Summary of payments made to the producer.
operationId: getProducerPaymentsSummary
summary: Get the payments summary for a producer

/sales:
summary: Path used to manage the list of all public sales.
Expand Down Expand Up @@ -490,6 +510,7 @@ paths:
$ref: '#/components/schemas/Order'
required: true


components:
securitySchemes:
oAuth2ForViandeEnDirect:
Expand Down Expand Up @@ -908,3 +929,23 @@ components:
OrderStatus:
type: string
enum: [BOOKED_WITHOUT_PAYMENT, PAYMENT_PENDING, PAYMENT_COMPLETED, PAYMENT_ABORTED, DELIVERED]
PaymentsSummary:
description: "the summary of payments made"
type: object
properties:
daylyTotal:
type: number
format: float
description: "the total amount paid for last day"
weeklyTotal:
type: number
format: float
description: "the total amount paid for last week"
monthlyTotal:
type: number
format: float
description: "the total amount paid for last month"
yearlyTotal:
type: number
format: float
description: "the total amount paid for last year"

0 comments on commit 79a648b

Please sign in to comment.