Skip to content

Commit

Permalink
chore: run v fmt -w .
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Apr 5, 2024
1 parent 4fd9e9b commit 1bb4ee7
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 62 deletions.
22 changes: 11 additions & 11 deletions src/app.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import time

struct App {
vweb.Context
config config.Config [vweb_global]
config config.Config @[vweb_global]
pub mut:
db pg.DB [vweb_global]
title string [vweb_global]
cur_user User [vweb_global]
storage storage.Provider [vweb_global]
db pg.DB @[vweb_global]
title string @[vweb_global]
cur_user User @[vweb_global]
storage storage.Provider @[vweb_global]

nr_packages &string [vweb_global] = unsafe { nil }
categories []Category [vweb_global]
new_packages []Package [vweb_global]
recently_updated_packages []Package [vweb_global]
most_downloaded_packages []Package [vweb_global]
last_update &time.Time [vweb_global] = unsafe { nil }
nr_packages &string = unsafe { nil } @[vweb_global]
categories []Category @[vweb_global]
new_packages []Package @[vweb_global]
recently_updated_packages []Package @[vweb_global]
most_downloaded_packages []Package @[vweb_global]
last_update &time.Time = unsafe { nil } @[vweb_global]
}

// Whole app middleware
Expand Down
4 changes: 1 addition & 3 deletions src/auth.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ struct GitHubUser {
login string
}

const (
random = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890'
)
const random = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890'

fn random_string(len int) string {
mut buf := [`0`].repeat(len)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/migrate/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import entity { Package, User }

// Old definition
struct Mod {
id int [primary; sql: serial]
id int @[primary; sql: serial]
name string
description string
url string
Expand Down
16 changes: 8 additions & 8 deletions src/entity/category.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ module entity

import time

[json: 'category']
@[json: 'category']
pub struct Category {
pub mut:
id int [primary; sql: serial]
id int @[primary; sql: serial]
// For paths `/search?category=slug`
slug string [unique]
slug string @[unique]
// Packages count
packages int

name string [unique]
name string @[unique]
description string

created_at time.Time = time.now()
updated_at time.Time = time.now()
}

[json: 'category_to_package']
@[json: 'category_to_package']
pub struct CategoryPackage {
pub mut:
id int [primary; sql: serial]
category_id int [fkey: 'Category']
package_id int [fkey: 'Package']
id int @[primary; sql: serial]
category_id int @[fkey: 'Category']
package_id int @[fkey: 'Package']
}
8 changes: 4 additions & 4 deletions src/entity/package.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ module entity

import time

[json: 'package']
@[json: 'package']
pub struct Package {
pub mut:
id int [primary; sql: serial]
name string [unique]
id int @[primary; sql: serial]
name string @[unique]
description string
documentation string
url string
nr_downloads int
vcs string = 'git'
user_id int
author User [fkey: 'id']
author User @[fkey: 'id']
stars int
is_flatten bool // No need to mention author of package, example `ui`
updated_at time.Time = time.now()
Expand Down
6 changes: 3 additions & 3 deletions src/entity/user.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module entity

import time

[json: 'user']
@[json: 'user']
pub struct User {
pub mut:
id int [primary; sql: serial]
id int @[primary; sql: serial]
github_id int
username string [unique]
username string @[unique]
avatar_url string

is_blocked bool
Expand Down
2 changes: 1 addition & 1 deletion src/lib/log/logger.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import x.json2 as j2

pub const logging_level = level_from_str(os.getenv('VPM_LOG'))

[noinit]
@[noinit]
pub struct Logger {
level Level
fields []Field
Expand Down
4 changes: 1 addition & 3 deletions src/lib/storage/errors.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module storage

pub const (
err_not_found = error('file not found')
)
pub const err_not_found = error('file not found')
2 changes: 1 addition & 1 deletion src/lib/storage/local/local.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module local
import os
import lib.storage

[noinit]
@[noinit]
pub struct Provider {
pub:
dir_path string
Expand Down
18 changes: 9 additions & 9 deletions src/package.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import lib.html
import markdown
import entity { Package }

['/new']
@['/new']
fn (mut app App) new() vweb.Result {
app.title = 'Creating package | vpm'
return $vweb.html()
}

['/create_package'; post]
@['/create_package'; post]
pub fn (mut app App) create_package(name string, url string, description string) vweb.Result {
app.packages().create(name, url, description, app.cur_user) or {
log.error()
Expand All @@ -31,7 +31,7 @@ pub fn (mut app App) create_package(name string, url string, description string)
return app.redirect('/')
}

['/users/:name']
@['/users/:name']
pub fn (mut app App) user(name string) vweb.Result {
user := app.users().get_by_name(name) or {
error_msg := 'Not found such user'
Expand All @@ -45,12 +45,12 @@ pub fn (mut app App) user(name string) vweb.Result {
return $vweb.html()
}

['/packages']
@['/packages']
pub fn (mut app App) packages_redir() vweb.Result {
return app.redirect('/search')
}

['/packages/:name']
@['/packages/:name']
pub fn (mut app App) package(name string) vweb.Result {
pkg := app.packages().get(name) or {
println(err)
Expand Down Expand Up @@ -97,7 +97,7 @@ fn (mut app App) get_readme(name string, readme_path string) !string {
return data.bytestr()
}

['/packages/:name/edit']
@['/packages/:name/edit']
pub fn (mut app App) edit(name string) vweb.Result {
pkg := app.packages().get(name) or {
app.error(err.msg())
Expand All @@ -114,7 +114,7 @@ pub fn (mut app App) edit(name string) vweb.Result {
return $vweb.html()
}

['/packages/:name/edit'; POST]
@['/packages/:name/edit'; POST]
pub fn (mut app App) perform_edit(name string) vweb.Result {
pkg := app.packages().get(name) or {
app.error(err.msg())
Expand All @@ -140,7 +140,7 @@ pub fn (mut app App) perform_edit(name string) vweb.Result {
return app.redirect('/')
}

['/packages/:name/delete']
@['/packages/:name/delete']
pub fn (mut app App) delete(name string) vweb.Result {
pkg := app.packages().get(name) or {
app.error(err.msg())
Expand All @@ -156,7 +156,7 @@ pub fn (mut app App) delete(name string) vweb.Result {
return $vweb.html()
}

['/packages/:name/delete'; POST]
@['/packages/:name/delete'; POST]
pub fn (mut app App) perform_delete(name string) vweb.Result {
pkg := app.packages().get(name) or {
app.error(err.msg())
Expand Down
12 changes: 6 additions & 6 deletions src/package_api.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module main
import vweb
import lib.log

['/api/packages'; post]
@['/api/packages'; post]
pub fn (mut app App) api_create_package(name string, vcsUrl string, description string) vweb.Result {
app.packages().create(name, vcsUrl, description, app.cur_user) or { return app.json(err.msg()) }

return app.ok('ok')
}

['/api/packages/id/:package_id'; delete]
@['/api/packages/id/:package_id'; delete]
pub fn (mut app App) delete_package(package_id int) vweb.Result {
if !app.is_logged_in() {
app.set_status(401, 'Unauthorized')
Expand All @@ -24,14 +24,14 @@ pub fn (mut app App) delete_package(package_id int) vweb.Result {
return app.ok('ok')
}

['/api/packages/:name']
@['/api/packages/:name']
pub fn (mut app App) get_package_by_name(name string) vweb.Result {
package := app.packages().get(name) or { return app.json('404') }

return app.json(package)
}

['/api/packages/:name/incr_downloads'; post]
@['/api/packages/:name/incr_downloads'; post]
pub fn (mut app App) incr_downloads(name string) vweb.Result {
app.packages().incr_downloads(name) or { return app.json('404') }

Expand All @@ -40,7 +40,7 @@ pub fn (mut app App) incr_downloads(name string) vweb.Result {

// TODO: Delete jsmod and delete_package_deprecated some time after V is updated to use the new API endpoints

['/jsmod/:name']
@['/jsmod/:name']
pub fn (mut app App) jsmod_deprecated(name string) vweb.Result {
log.info()
.add('name', name)
Expand All @@ -50,7 +50,7 @@ pub fn (mut app App) jsmod_deprecated(name string) vweb.Result {
return app.json(package)
}

['/delete_package/:package_id'; post]
@['/delete_package/:package_id'; post]
pub fn (mut app App) delete_package_deprecated(package_id int) vweb.Result {
return app.delete_package(package_id)
}
2 changes: 1 addition & 1 deletion src/repo/category.v
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const basic_categories = [

pub struct CategoryRepo {
mut:
db orm.Connection [required]
db orm.Connection @[required]
}

pub fn migrate_categories(db orm.Connection) ! {
Expand Down
2 changes: 1 addition & 1 deletion src/repo/package.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const supported_vcs_systems = ['git']

pub struct PackagesRepo {
mut:
db orm.Connection [required]
db orm.Connection @[required]
}

pub fn migrate_packages(db orm.Connection) ! {
Expand Down
2 changes: 1 addition & 1 deletion src/repo/users.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import entity { User }

pub struct UsersRepo {
mut:
db orm.Connection [required]
db orm.Connection @[required]
}

pub fn migrate_users(db orm.Connection) ! {
Expand Down
2 changes: 1 addition & 1 deletion src/search.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module main

import vweb

['/search']
@['/search']
pub fn (mut app App) search() vweb.Result {
query := app.query['q']
category := app.query['category']
Expand Down
6 changes: 2 additions & 4 deletions src/usecase/package/packages.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import x.json2
// Used in search and packages view (index page)
pub const per_page = 6

const (
max_name_len = 35
max_package_url_len = 75
)
const max_name_len = 35
const max_package_url_len = 75

fn default_url_formatter(protocol string, host string, username string) string {
return '${protocol}://${host}/${username}'
Expand Down
6 changes: 3 additions & 3 deletions src/usecase/package/usecase.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module package

pub struct UseCase {
categories CategoriesRepo [required]
packages PackagesRepo [required]
users UsersRepo [required]
categories CategoriesRepo @[required]
packages PackagesRepo @[required]
users UsersRepo @[required]
}
2 changes: 1 addition & 1 deletion src/usecase/user/usecase.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub interface UsersRepo {
}

pub struct UseCase {
users UsersRepo [required]
users UsersRepo @[required]
}

pub fn (u UseCase) get(id int, random_id string) ?User {
Expand Down

0 comments on commit 1bb4ee7

Please sign in to comment.