This file contains hidden or 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
| import uvicorn | |
| from fastapi import FastAPI | |
| app = FastAPI() | |
| @app.get('/hello') | |
| def hello(): | |
| return 'Hello World' | |
| if __name__ == '__main__': |
This file contains hidden or 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
| type tweetHandlerSuite struct { | |
| // we need this to use the suite functionalities from testify | |
| suite.Suite | |
| // the mocked version of the usecase | |
| usecase *mocks.TweetUsecase | |
| // the functionalities we need to test | |
| handler TweetHandler | |
| // testing server to be used the handler | |
| testingServer *httptest.Server | |
| } |
This file contains hidden or 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
| type tweetHandler struct { | |
| tweetUsecase usecases.TweetUsecase | |
| } | |
| type TweetHandler interface { | |
| CreateTweet(ctx *gin.Context) *entities.AppResult | |
| // ... another methods | |
| } | |
| func InitializeTweetHandler(usecase usecases.TweetUsecase) TweetHandler { |
This file contains hidden or 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
| type tweetUsecase struct { | |
| tweetRepository repositories.TweetRepository | |
| } | |
| type TweetUsecase interface { | |
| CreateTweet(tweet *entities.Tweet) error | |
| // ... other methods | |
| } | |
| func InitializeTweetUsecase(repository repositories.TweetRepository) TweetUsecase { |
This file contains hidden or 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
| type tweetUsecaseSuite struct { | |
| // we need this to use the suite functionalities from testify | |
| suite.Suite | |
| // the generated mocked version of our repository | |
| repository *mocks.TweetRepository | |
| // the functionalities we want to test | |
| usecase TweetUsecase | |
| } | |
| func (suite *tweetUsecaseSuite) SetupTest() { |
This file contains hidden or 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
| // TweetRepository is an autogenerated mock type for the TweetRepository type | |
| type TweetRepository struct { | |
| mock.Mock | |
| } | |
| // CreateTweet provides a mock function with given fields: tweet | |
| func (_m *TweetRepository) CreateTweet(tweet *entities.Tweet) error { | |
| ret := _m.Called(tweet) | |
| var r0 error |
This file contains hidden or 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
| type tweetRepository struct { | |
| db *sqlx.DB | |
| } | |
| type TweetRepository interface { | |
| CreateTweet(tweet *entities.Tweet) error | |
| // ... another methods for tweet repository | |
| } | |
| func InitializeTweetRepository(db *sqlx.DB) TweetRepository { |
This file contains hidden or 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
| type tweetRepositorySuite struct { | |
| // we need this to use the suite functionalities from testify | |
| suite.Suite | |
| // the funcionalities we need to test | |
| repository TweetRepository | |
| // some helper function to clean-up any used tables | |
| cleanupExecutor utils.TruncateTableExecutor | |
| } | |
| func (suite *tweetRepositorySuite) SetupSuite() { |
This file contains hidden or 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
| <html> | |
| <body style="margin: 0; padding: 0; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif;"> | |
| <div style="width: 100%; background: #efefef; border-radius: 10px; padding: 10px;"> | |
| <div style="margin: 0 auto; width: 90%; text-align: center;"> | |
| <h1 style="background-color: rgba(0, 53, 102, 1); padding: 5px 10px; border-radius: 5px; color: white;">{{ body.title }}</h1> | |
| <div style="margin: 30px auto; background: white; width: 40%; border-radius: 10px; padding: 50px; text-align: center;"> | |
| <h3 style="margin-bottom: 100px; font-size: 24px;">{{ body.name }}!</h3> | |
| <p style="margin-bottom: 30px;">Lorem ipsum dolor sit amet consectetur adipisicing elit. Eligendi, doloremque.</p> | |
| <a style="display: block; margin: 0 auto; border: none; background-color: rgba(255, 214, 10, 1); color: white; width: 200px; line-height: 24px; padding: 10px; font-size: 24px; border-radius: 10px; cursor: pointer; text-decoration: none;" | |
| href="https://fastapi.tiangolo.com/" |
This file contains hidden or 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
| @todo_blueprint.route('/update/<int:todo_id>', methods=['POST']) | |
| @token_required | |
| def update_todo(todo_id): | |
| try: | |
| user_data = session['user_data'] | |
| client = TodoClient() | |
| result_update = client.update_todo(todo_id, request.form['title'], request.form['description']) | |
| result_get = client.get_todo(todo_id, user_data.get('ID')) | |
| data = json.loads(result_get.data) | |
| return render_template('todo/item.html', todo=data) |