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
-- +migrate Up | |
INSERT INTO garbage_types(id, created_at, updated_at, title, description, quantity_type, image_base64) VALUES | |
('1', '2019-04-15 15:51:39.38991+00', '2019-04-15 15:51:39.38991+00', 'Sampah Plastik', 'Pile of used plastic', 'Kg', 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIGlkPSJDYXBhXzEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMzY4IDM2OCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMzY4IDM2ODsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIj48Zz48Zz4KCTxnPgoJCTxwYXRoIGQ9Ik0yOTYsMGgtMzJjLTEzLjIzMiwwLTI0LDEwLjc2OC0yNCwyNHY5NmMwLDQuNDE2LTMuNTg0LDgtOCw4aC05NmMtNC40MTYsMC04LTMuNTkyLTgtOFYyNGMwLTEzLjIzMi0xMC43NjgtMjQtMjQtMjRINzIgICAgQzU4Ljc2OCwwLDQ4LDEwLjc2OCw0OCwyNHYzMjBjMCwxMy4yMzIsMTAuNzY4LDI0LDI0LDI0aDIyNGMxMy4yMzIsMCwyNC0xMC43NjgsMjQtMjRWMjRDMzIwLDEwLjc2OCwzMDkuMjMyLDAsMjk2LDB6IE0zMDQsMzA0ICAgIGgtNDBjLTQuNDI0LDAtOCwzLjU4NC04LDhjMCw0LjQxNiwzLjU3Niw4LDgsOGg0MHYyNGMwLDQuNDA4LTMuNTg0LDgtOCw4SDcyYy00Lj |
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
-- +migrate Up | |
INSERT INTO order_statuses(id, created_at, updated_at, description) VALUES | |
('1', '2019-04-15 15:51:39.38991+00', '2019-04-15 15:51:39.38991+00', 'init order, finding mitra'), | |
('2', '2019-04-15 15:51:39.38991+00', '2019-04-15 15:51:39.38991+00', 'accepted by a mitra'), | |
('3', '2019-04-15 15:51:39.38991+00', '2019-04-15 15:51:39.38991+00', 'completed'), | |
('4', '2019-04-15 15:51:39.38991+00', '2019-04-15 15:51:39.38991+00', 'cancelled'); | |
SELECT SETVAL('order_statuses_id_seq', 4); | |
-- +migrate Down |
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
-- +migrate Up | |
-- SEQUENCE: public.customers_id_seq | |
CREATE SEQUENCE customers_id_seq; | |
-- Table: public.customers | |
CREATE TABLE customers | |
( | |
id integer NOT NULL DEFAULT nextval('customers_id_seq'::regclass), |
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
func main() { | |
... | |
userRepository := new(UserRepository) // initiate an object | |
// initiate userProfileService object | |
userProfileService := UserProfileService{ | |
UserRepository: userRepository // <--- inject !! | |
} | |
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 "backend/repositories" | |
type UserProfileService struct { | |
UserRepository repositories.IUserRepository // put the dependency!! | |
} | |
// class UserProfileServices implements this interface | |
type IUserProfileService interface { | |
GetUserProfile(userID int) (*models.User, 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 UserProfileService struct { | |
UserRepository repositories.IUserRepository // masukkan interface repository ke dalam UserProfileServices | |
} | |
// class UserProfileServices implements this interface | |
type IUserProfileService interface { | |
GetUserProfile(userID int) (*models.User, 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
// class ORM: models.User | |
type User struct { | |
UserID int | |
Name string | |
Email string | |
Phone string | |
Address string | |
Password string | |
} |
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 UserProfileService struct { | |
} | |
// class UserProfileServices implements this interface | |
type IUserProfileService interface { | |
GetUserProfile(userID int) (*models.User, 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
package customercontrollers | |
import ( | |
"encoding/json" | |
"net/http" | |
) | |
func writeEncoded(w http.ResponseWriter, data interface{}) { | |
w.Header().Add("Content-Type", "application/json") | |
json.NewEncoder(w).Encode(data) |
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
func TestMitraGetByPhoneNumber(t *testing.T) { | |
var mitraFieldNames = []string{"id", "phone", "email", "password"} | |
rows := sqlmock.NewRows(mitraFieldNames) | |
rows.AddRow("1", "0812345678", "abdul@gmail.com", "abcdefghi") | |
db, mock, _ := sqlmock.New() | |
gormDb, _ := gorm.Open("postgres", db) | |
gormDb.LogMode(true) | |
mock.ExpectQuery("^SELECT (.+) FROM \"mitras\".+$").WillReturnRows(rows) | |
models.SetDB(gormDb) | |
mitraRepo := new(MitraRepository) |
NewerOlder