-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add webvisor * remove ya metrica in dev env * disable calc button if there is only one person * remove unused code * add tests * #6 fix backend error * fix #6
- Loading branch information
1 parent
5efdfbc
commit c1c5efe
Showing
10 changed files
with
106 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import axios from 'axios'; | ||
import { calculateUrl } from "./urls"; | ||
import { calculateUrl } from './urls'; | ||
import { Person } from './../model/Person'; | ||
|
||
export const incrementCountType = 'INCREMENT_PERSON_COUNT'; | ||
export const decrementCountType = 'DECREMENT_PERSON_COUNT'; | ||
export const calculateType = 'CALCULATE'; | ||
|
||
async function transfersFromBack(people: Person[]) { | ||
try { | ||
return await axios.post(calculateUrl, people); | ||
} | ||
catch { | ||
return { data: [] }; | ||
} | ||
} | ||
|
||
export const actionCreators = { | ||
increment: () => ({ type: incrementCountType }), | ||
decrement: () => ({ type: decrementCountType }), | ||
calculate: (people: any) => async (dispatch: any) => { | ||
const response = await axios.post(calculateUrl, people); | ||
dispatch({ | ||
type: calculateType, | ||
payload: response | ||
}) | ||
} | ||
increment: () => ({ type: incrementCountType }), | ||
decrement: () => ({ type: decrementCountType }), | ||
calculate: (people: Person[]) => async (dispatch: any) => { | ||
const response = await transfersFromBack(people); | ||
dispatch({ | ||
type: calculateType, | ||
payload: response | ||
}) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Izzy.Web.Model; | ||
|
||
namespace Izzy.Web.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class CalculatorController : Controller | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public CalculatorController(ILogger<CalculatorController> logger) | ||
{ | ||
this._logger = logger; | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult Calculate([FromBody] IEnumerable<Person> persons) | ||
{ | ||
return new OkObjectResult( | ||
new Receipt(persons) | ||
.Transfers() | ||
); | ||
if (ModelState.IsValid) { | ||
return new OkObjectResult( | ||
new Receipt(persons) | ||
.Transfers() | ||
); | ||
} else { | ||
return new BadRequestObjectResult( | ||
"Name should have string type, Roubles should have number type" | ||
); | ||
} | ||
|
||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.