Skip to content

Commit

Permalink
Merge pull request #240 from systemli/Move-API-Responses-to-CamelCase
Browse files Browse the repository at this point in the history
💥 Move API Responses to CamelCase
  • Loading branch information
0x46616c6b authored Oct 18, 2023
2 parents fd143df + 47b2766 commit 601dab6
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 80 deletions.
2 changes: 1 addition & 1 deletion internal/api/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type FeaturesResponse map[string]bool

func NewFeaturesResponse(config config.Config) FeaturesResponse {
return FeaturesResponse{
"telegram_enabled": config.TelegramEnabled(),
"telegramEnabled": config.TelegramEnabled(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/api/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestGetFeatures(t *testing.T) {

h.GetFeatures(c)

expected := `{"data":{"features":{"telegram_enabled":false}},"status":"success","error":{}}`
expected := `{"data":{"features":{"telegramEnabled":false}},"status":"success","error":{}}`
assert.Equal(t, expected, w.Body.String())
assert.Equal(t, http.StatusOK, w.Code)
}
2 changes: 1 addition & 1 deletion internal/api/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (h *handler) PostMessage(c *gin.Context) {

var body struct {
Text string `json:"text" binding:"required"`
GeoInformation geojson.FeatureCollection `json:"geo_information"`
GeoInformation geojson.FeatureCollection `json:"geoInformation"`
Attachments []int `json:"attachments"`
}
err = c.Bind(&body)
Expand Down
10 changes: 5 additions & 5 deletions internal/api/response/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (

type Message struct {
ID int `json:"id"`
CreationDate time.Time `json:"creation_date"`
CreatedAt time.Time `json:"createdAt"`
Text string `json:"text"`
Ticker int `json:"ticker"`
TelegramURL string `json:"telegram_url,omitempty"`
MastodonURL string `json:"mastodon_url,omitempty"`
GeoInformation string `json:"geo_information"`
TelegramURL string `json:"telegramUrl,omitempty"`
MastodonURL string `json:"mastodonUrl,omitempty"`
GeoInformation string `json:"geoInformation"`
Attachments []MessageAttachment `json:"attachments"`
}

Expand All @@ -35,7 +35,7 @@ func MessageResponse(message storage.Message, config config.Config) Message {

return Message{
ID: message.ID,
CreationDate: message.CreatedAt,
CreatedAt: message.CreatedAt,
Text: message.Text,
Ticker: message.TickerID,
TelegramURL: message.TelegramURL(),
Expand Down
4 changes: 2 additions & 2 deletions internal/api/response/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package response
import "github.com/systemli/ticker/internal/storage"

type Settings struct {
RefreshInterval int `json:"refresh_interval,omitempty"`
InactiveSettings interface{} `json:"inactive_settings,omitempty"`
RefreshInterval int `json:"refreshInterval,omitempty"`
InactiveSettings interface{} `json:"inactiveSettings,omitempty"`
}

type Setting struct {
Expand Down
40 changes: 20 additions & 20 deletions internal/api/response/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
)

type Ticker struct {
ID int `json:"id"`
CreationDate time.Time `json:"creation_date"`
Domain string `json:"domain"`
Title string `json:"title"`
Description string `json:"description"`
Active bool `json:"active"`
Information Information `json:"information"`
Telegram Telegram `json:"telegram"`
Mastodon Mastodon `json:"mastodon"`
Location Location `json:"location"`
ID int `json:"id"`
CreatedAt time.Time `json:"createdAt"`
Domain string `json:"domain"`
Title string `json:"title"`
Description string `json:"description"`
Active bool `json:"active"`
Information Information `json:"information"`
Telegram Telegram `json:"telegram"`
Mastodon Mastodon `json:"mastodon"`
Location Location `json:"location"`
}

type Information struct {
Expand All @@ -32,18 +32,18 @@ type Information struct {
type Telegram struct {
Active bool `json:"active"`
Connected bool `json:"connected"`
BotUsername string `json:"bot_username"`
ChannelName string `json:"channel_name"`
BotUsername string `json:"botUsername"`
ChannelName string `json:"channelName"`
}

type Mastodon struct {
Active bool `json:"active"`
Connected bool `json:"connected"`
Name string `json:"name"`
Server string `json:"server"`
ScreenName string `json:"screen_name"`
ScreenName string `json:"screenName"`
Description string `json:"description"`
ImageURL string `json:"image_url"`
ImageURL string `json:"imageUrl"`
}

type Location struct {
Expand All @@ -53,12 +53,12 @@ type Location struct {

func TickerResponse(t storage.Ticker, config config.Config) Ticker {
return Ticker{
ID: t.ID,
CreationDate: t.CreatedAt,
Domain: t.Domain,
Title: t.Title,
Description: t.Description,
Active: t.Active,
ID: t.ID,
CreatedAt: t.CreatedAt,
Domain: t.Domain,
Title: t.Title,
Description: t.Description,
Active: t.Active,
Information: Information{
Author: t.Information.Author,
URL: t.Information.URL,
Expand Down
2 changes: 1 addition & 1 deletion internal/api/response/ticker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestTickersResponse(t *testing.T) {

assert.Equal(t, 1, len(tickerResponse))
assert.Equal(t, ticker.ID, tickerResponse[0].ID)
assert.Equal(t, ticker.CreatedAt, tickerResponse[0].CreationDate)
assert.Equal(t, ticker.CreatedAt, tickerResponse[0].CreatedAt)
assert.Equal(t, ticker.Domain, tickerResponse[0].Domain)
assert.Equal(t, ticker.Title, tickerResponse[0].Title)
assert.Equal(t, ticker.Description, tickerResponse[0].Description)
Expand Down
6 changes: 3 additions & 3 deletions internal/api/response/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type Timeline []TimelineEntry

type TimelineEntry struct {
ID int `json:"id"`
CreationDate time.Time `json:"creation_date"`
CreatedAt time.Time `json:"createdAt"`
Text string `json:"text"`
GeoInformation string `json:"geo_information"`
GeoInformation string `json:"geoInformation"`
Attachments []MessageAttachment `json:"attachments"`
}

Expand All @@ -36,7 +36,7 @@ func TimelineResponse(messages []storage.Message, config config.Config) []Timeli

timeline = append(timeline, TimelineEntry{
ID: message.ID,
CreationDate: message.CreatedAt,
CreatedAt: message.CreatedAt,
Text: message.Text,
GeoInformation: string(m),
Attachments: attachments,
Expand Down
20 changes: 10 additions & 10 deletions internal/api/response/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (
)

type Upload struct {
ID int `json:"id"`
UUID string `json:"uuid"`
CreationDate time.Time `json:"creation_date"`
URL string `json:"url"`
ContentType string `json:"content_type"`
ID int `json:"id"`
UUID string `json:"uuid"`
CreatedAt time.Time `json:"createdAt"`
URL string `json:"url"`
ContentType string `json:"contentType"`
}

func UploadResponse(upload storage.Upload, config config.Config) Upload {
return Upload{
ID: upload.ID,
UUID: upload.UUID,
CreationDate: upload.CreatedAt,
URL: upload.URL(config.UploadURL),
ContentType: upload.ContentType,
ID: upload.ID,
UUID: upload.UUID,
CreatedAt: upload.CreatedAt,
URL: upload.URL(config.UploadURL),
ContentType: upload.ContentType,
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/api/response/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (

type User struct {
ID int `json:"id"`
CreationDate time.Time `json:"creation_date"`
CreatedAt time.Time `json:"createdAt"`
Email string `json:"email"`
Role string `json:"role"`
IsSuperAdmin bool `json:"is_super_admin"`
IsSuperAdmin bool `json:"isSuperAdmin"`
}

func UserResponse(user storage.User) User {
return User{
ID: user.ID,
CreationDate: user.CreatedAt,
CreatedAt: user.CreatedAt,
Email: user.Email,
IsSuperAdmin: user.IsSuperAdmin,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/api/response/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestUsersResponse(t *testing.T) {
usersResponse := UsersResponse(users)
assert.Equal(t, 1, len(usersResponse))
assert.Equal(t, users[0].ID, usersResponse[0].ID)
assert.Equal(t, users[0].CreatedAt, usersResponse[0].CreationDate)
assert.Equal(t, users[0].CreatedAt, usersResponse[0].CreatedAt)
assert.Equal(t, users[0].Email, usersResponse[0].Email)
assert.Equal(t, users[0].IsSuperAdmin, usersResponse[0].IsSuperAdmin)
}
4 changes: 2 additions & 2 deletions internal/api/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestPutRefreshIntervalSettingsStorageError(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, IsSuperAdmin: true})
body := `{"refresh_interval": 10000}`
body := `{"refreshInterval": 10000}`
c.Request = httptest.NewRequest(http.MethodPost, "/v1/admin/settings", strings.NewReader(body))
c.Request.Header.Add("Content-Type", "application/json")

Expand All @@ -173,7 +173,7 @@ func TestPutRefreshIntervalSettings(t *testing.T) {
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, IsSuperAdmin: true})
setting := storage.DefaultRefreshIntervalSettings()
body := `{"refresh_interval": 10000}`
body := `{"refreshInterval": 10000}`
c.Request = httptest.NewRequest(http.MethodPost, "/v1/admin/settings", strings.NewReader(body))
c.Request.Header.Add("Content-Type", "application/json")

Expand Down
10 changes: 5 additions & 5 deletions internal/api/tickers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func TestPutTickerTelegramStorageError(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("ticker", storage.Ticker{})
body := `{"active":true,"channel_name":"@channel_name"}`
body := `{"active":true,"channelName":"@channel_name"}`
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/tickers/1/telegram", strings.NewReader(body))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -395,7 +395,7 @@ func TestPutTickerTelegram(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("ticker", storage.Ticker{})
body := `{"active":true,"channel_name":"@channel_name"}`
body := `{"active":true,"channelName":"@channel_name"}`
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/tickers/1/telegram", strings.NewReader(body))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand Down Expand Up @@ -491,7 +491,7 @@ func TestPutTickerMastodonConnectError(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("ticker", storage.Ticker{})
body := `{"active":true,"server":"http://localhost","secret":"secret","token":"token","access_token":"access_token"}`
body := `{"active":true,"server":"http://localhost","secret":"secret","token":"token","accessToken":"access_token"}`
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/tickers/1/mastodon", strings.NewReader(body))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -516,7 +516,7 @@ func TestPutTickerMastodonStorageError(t *testing.T) {
defer server.Close()
c, _ := gin.CreateTestContext(w)
c.Set("ticker", storage.Ticker{})
body := fmt.Sprintf(`{"server":"%s","token":"token","secret":"secret","access_token":"access_toklen"}`, server.URL)
body := fmt.Sprintf(`{"server":"%s","token":"token","secret":"secret","accessToken":"access_toklen"}`, server.URL)
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/tickers/1/mastodon", strings.NewReader(body))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -541,7 +541,7 @@ func TestPutTickerMastodon(t *testing.T) {
defer server.Close()
c, _ := gin.CreateTestContext(w)
c.Set("ticker", storage.Ticker{})
body := fmt.Sprintf(`{"server":"%s","token":"token","secret":"secret","access_token":"access_toklen"}`, server.URL)
body := fmt.Sprintf(`{"server":"%s","token":"token","secret":"secret","accessToken":"access_toklen"}`, server.URL)
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/tickers/1/mastodon", strings.NewReader(body))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand Down
6 changes: 3 additions & 3 deletions internal/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (h *handler) PostUser(c *gin.Context) {
var body struct {
Email string `json:"email,omitempty" binding:"required" validate:"email"`
Password string `json:"password,omitempty" binding:"required" validate:"min=10"`
IsSuperAdmin bool `json:"is_super_admin,omitempty"`
IsSuperAdmin bool `json:"isSuperAdmin,omitempty"`
Tickers []int `json:"tickers,omitempty"`
}

Expand Down Expand Up @@ -88,7 +88,7 @@ func (h *handler) PutUser(c *gin.Context) {
var body struct {
Email string `json:"email,omitempty" validate:"email"`
Password string `json:"password,omitempty" validate:"min=10"`
IsSuperAdmin bool `json:"is_super_admin,omitempty"`
IsSuperAdmin bool `json:"isSuperAdmin,omitempty"`
Tickers []int `json:"tickers,omitempty"`
}

Expand Down Expand Up @@ -161,7 +161,7 @@ func (h *handler) PutMe(c *gin.Context) {

var body struct {
Password string `json:"password" binding:"required"`
NewPassword string `json:"new_password" binding:"required" validate:"min=10"`
NewPassword string `json:"newPassword" binding:"required" validate:"min=10"`
}

err = c.Bind(&body)
Expand Down
16 changes: 8 additions & 8 deletions internal/api/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestPutUserStorageError(t *testing.T) {
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, IsSuperAdmin: true})
c.Set("user", storage.User{})
json := `{"email":"[email protected]","password":"password1234","is_super_admin":true,"tickers":[1]}`
json := `{"email":"[email protected]","password":"password1234","isSuperAdmin":true,"tickers":[1]}`
c.Request = httptest.NewRequest(http.MethodPost, "/v1/admin/users", strings.NewReader(json))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -288,7 +288,7 @@ func TestPutUserStorageError2(t *testing.T) {
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, IsSuperAdmin: true})
c.Set("user", storage.User{})
json := `{"email":"[email protected]","password":"password1234","is_super_admin":true,"tickers":[1]}`
json := `{"email":"[email protected]","password":"password1234","isSuperAdmin":true,"tickers":[1]}`
c.Request = httptest.NewRequest(http.MethodPost, "/v1/admin/users", strings.NewReader(json))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -309,7 +309,7 @@ func TestPutUser(t *testing.T) {
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, IsSuperAdmin: true})
c.Set("user", storage.User{})
json := `{"email":"[email protected]","password":"password1234","is_super_admin":true,"tickers":[1]}`
json := `{"email":"[email protected]","password":"password1234","isSuperAdmin":true,"tickers":[1]}`
c.Request = httptest.NewRequest(http.MethodPost, "/v1/admin/users", strings.NewReader(json))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestDeleteUser(t *testing.T) {
func TestPutMeUnauthenticated(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
json := `{"password":"password1234","new_password":"password5678"}`
json := `{"password":"password1234","newPassword":"password5678"}`
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/users/me", strings.NewReader(json))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -410,7 +410,7 @@ func TestPutMeFormError(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, EncryptedPassword: "$2a$10$3rj/kzMI7gKPoBtJFG55tuzA.RQGYqbYQdM69LPyU.2YkGbkRu.T2"})
json := `{"wrongparameter":"password1234","new_password":"password5678"}`
json := `{"wrongparameter":"password1234","newPassword":"password5678"}`
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/users/me", strings.NewReader(json))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -427,7 +427,7 @@ func TestPutMeWrongPassword(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, EncryptedPassword: "$2a$10$3rj/kzMI7gKPoBtJFG55tuzA.RQGYqbYQdM69LPyU.2YkGbkRu.T2"})
json := `{"password":"wrongpassword","new_password":"password5678"}`
json := `{"password":"wrongpassword","newPassword":"password5678"}`
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/users/me", strings.NewReader(json))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -444,7 +444,7 @@ func TestPutMeStorageError(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, EncryptedPassword: "$2a$10$3rj/kzMI7gKPoBtJFG55tuzA.RQGYqbYQdM69LPyU.2YkGbkRu.T2"})
json := `{"password":"password1234","new_password":"password5678"}`
json := `{"password":"password1234","newPassword":"password5678"}`
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/users/me", strings.NewReader(json))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand All @@ -461,7 +461,7 @@ func TestPutMeOk(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Set("me", storage.User{ID: 1, EncryptedPassword: "$2a$10$3rj/kzMI7gKPoBtJFG55tuzA.RQGYqbYQdM69LPyU.2YkGbkRu.T2"})
json := `{"password":"password1234","new_password":"password5678"}`
json := `{"password":"password1234","newPassword":"password5678"}`
c.Request = httptest.NewRequest(http.MethodPut, "/v1/admin/users/me", strings.NewReader(json))
c.Request.Header.Add("Content-Type", "application/json")
s := &storage.MockStorage{}
Expand Down
6 changes: 3 additions & 3 deletions internal/storage/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type TelegramMeta struct {
}

type MastodonMeta struct {
ID string `json:"id"`
URI string `json:"uri"`
URL string `json:"url"`
ID string
URI string
URL string
}

type Attachment struct {
Expand Down
Loading

0 comments on commit 601dab6

Please sign in to comment.