Skip to content

Commit

Permalink
feature:
Browse files Browse the repository at this point in the history
1. config enf file 통일
2. model선언(jsonb_build_object배열 받기위해서 category, hashtag의
   scan/value implements)
  • Loading branch information
koreanddinghwan committed Nov 16, 2023
1 parent d92a0c9 commit 725be5f
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 164 deletions.
14 changes: 7 additions & 7 deletions api/_build/api-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -952,17 +952,17 @@ components:
x-oapi-codegen-extra-tags:
db: updated_at
hashtags:
x-go-type: pq.StringArray
x-go-type-import:
path: github.com/lib/pq
type: array
x-oapi-codegen-extra-tags:
db: hashtags
items:
$ref: '#/components/schemas/HashtagGet'
categories:
x-go-type: pq.StringArray
x-go-type-import:
path: github.com/lib/pq
type: array
x-oapi-codegen-extra-tags:
db: categories
items:
$ref: '#/components/schemas/HashtagGet'
$ref: '#/components/schemas/CategoryGet'
user:
$ref: '#/components/schemas/HomeSimpleUser'
HomeSimpleUser:
Expand Down
14 changes: 7 additions & 7 deletions api/api-server/schemas/home/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ properties:
x-oapi-codegen-extra-tags:
db: "updated_at"
hashtags:
x-go-type: pq.StringArray
x-go-type-import:
path: "github.com/lib/pq"
type: array
x-oapi-codegen-extra-tags:
db: "hashtags"
items:
$ref: '../hashtags/get.yaml'
categories:
x-go-type: pq.StringArray
x-go-type-import:
path: "github.com/lib/pq"
type: array
x-oapi-codegen-extra-tags:
db: "categories"
items:
$ref: '../hashtags/get.yaml'
$ref: '../categories/get.yaml'
user:
$ref: './user.yaml'

Binary file modified cmd/api-server/api-server
Binary file not shown.
8 changes: 4 additions & 4 deletions cmd/api-server/internal/repository/MentorProfileRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
query "golang-with-k8s/cmd/api-server/internal/repository/internal"
"golang-with-k8s/generated/api_server"
"golang-with-k8s/pkg/database"
"golang-with-k8s/pkg/models"
)

func SearchMentor(searchString *api_server.SearchStringPath, params *api_server.GetSearchMentorSearchStringParams) (*[]api_server.HomeGet, error) {

result := []api_server.HomeGet{}
func MentorProfileSearch(searchString *api_server.SearchStringPath, params *api_server.GetSearchMentorSearchStringParams) (*[]models.HomeGet, error) {
result := []models.HomeGet{}
db := database.SqlX

sql := query.GetSearchMentorWhereQuery(searchString, params)
sql += query.GetSearchMentorGroupbyQuery()

fmt.Println(sql)
err := db.Select(&result, sql, false, "%"+string(*searchString)+"%", params.Take, params.Take*params.Page)
if err != nil {
fmt.Println(err)
return nil, err
}
return &result, nil
Expand Down
18 changes: 9 additions & 9 deletions cmd/api-server/internal/repository/UserRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/lib/pq"
)

func GetUsers(params *api_server.GetUsersParams) (*[]models.User, error) {
func GetUsers(params *api_server.GetUsersParams) (*[]models.UserGet, error) {

users := []models.User{}
users := []models.UserGet{}

sql := query.GetUsers

Expand All @@ -27,8 +27,8 @@ func GetUsers(params *api_server.GetUsersParams) (*[]models.User, error) {
return &users, err
}

func GetUserById(id *api_server.IdPath) (*api_server.UserGet, error) {
var user api_server.UserGet
func GetUserById(id *api_server.IdPath) (*models.UserGet, error) {
var user models.UserGet

sql := query.GetUserById

Expand All @@ -41,10 +41,10 @@ func GetUserById(id *api_server.IdPath) (*api_server.UserGet, error) {
return &user, err
}

func GetUsersIdReservations(id *api_server.IdPath, params *api_server.GetUsersIdReservationsParams) (*api_server.UserReservationPagination, error) {
func GetUsersIdReservations(id *api_server.IdPath, params *api_server.GetUsersIdReservationsParams) (*models.UserReservationPagination, error) {

result := api_server.UserReservationPagination{}
reservations := []api_server.ReservationGet{}
result := models.UserReservationPagination{}
reservations := []models.ReservationGet{}
var page *api_server.Page

db := database.SqlX
Expand All @@ -71,8 +71,8 @@ func GetUsersIdReservations(id *api_server.IdPath, params *api_server.GetUsersId
return &result, nil
}

func PatchUser(id *api_server.IdPath, body *api_server.PatchUsersIdJSONRequestBody) (*api_server.UserGet, error) {
var user api_server.UserGet
func PatchUser(id *api_server.IdPath, body *api_server.PatchUsersIdJSONRequestBody) (*models.UserGet, error) {
var user models.UserGet

sql := query.PatchUser

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const (
m.created_at as created_at,
m.updated_at as updated_at,
m.ishide as is_hide,
array_agg(DISTINCT c.name) FILTER (WHERE c.name IS NOT NULL) as "categories",
array_agg(DISTINCT h.tag_name) FILTER (WHERE h.tag_name IS NOT NULL) as "hashtags",
json_agg(DISTINCT jsonb_build_object('id', c.id, 'name', c.name)) FILTER (WHERE c.name IS NOT NULL) as "categories",
json_agg(DISTINCT jsonb_build_object('id', h.id, 'name', h.tag_name)) FILTER (WHERE h.tag_name IS NOT NULL) as "hashtags",
u.id as "user.id",
u.nickname as "user.nickname",
u.profile_image as "user.profile_image"
Expand Down
10 changes: 5 additions & 5 deletions cmd/api-server/internal/repository/internal/userQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const (
mp.mentoring_count as "mentorprofile.mentoring_count",
mp.isHide as "mentorprofile.isHide",
mp.shortDescription as "mentorprofile.shortDescription",
array_agg(DISTINCT c.name) FILTER (WHERE c.name IS NOT NULL) as "mentorprofile.categories",
array_agg(DISTINCT h.tag_name) FILTER (WHERE h.tag_name IS NOT NULL) as "mentorprofile.hashtags"
json_agg(DISTINCT jsonb_build_object('id', c.id, 'name', c.name)) FILTER (WHERE c.name IS NOT NULL) as "mentorprofile.categories",
json_agg(DISTINCT jsonb_build_object('id', h.id, 'name', h.tag_name)) FILTER (WHERE h.tag_name IS NOT NULL) as "mentorprofile.hashtags",
FROM users u
right join mentor_profiles mp on mp.user_id = u.id
left join _profiles_categories pc on pc.B = mp.id
Expand All @@ -46,8 +46,8 @@ const (
mp.mentoring_count as "mentorprofile.mentoring_count",
mp.isHide as "mentorprofile.isHide",
mp.shortDescription as "mentorprofile.shortDescription",
array_agg(DISTINCT c.name) FILTER (WHERE c.name IS NOT NULL) as "mentorprofile.categories",
array_agg(DISTINCT h.tag_name) FILTER (WHERE h.tag_name IS NOT NULL) as "mentorprofile.hashtags"
json_agg(DISTINCT jsonb_build_object('id', c.id, 'name', c.name)) FILTER (WHERE c.name IS NOT NULL) as "mentorprofile.categories",
json_agg(DISTINCT jsonb_build_object('id', h.id, 'name', h.tag_name)) FILTER (WHERE h.tag_name IS NOT NULL) as "mentorprofile.hashtags",
FROM users u
right join mentor_profiles mp on mp.user_id = u.id
left join _profiles_categories pc on pc.B = mp.id
Expand Down Expand Up @@ -86,7 +86,7 @@ const (
cr.requested_user_id as "cancelreason.requested_user_id",
c.id as "category.id",
c.name as "category.name",
array_agg(DISTINCT h.tag_name) FILTER (WHERE h.tag_name IS NOT NULL) as "hashtags"
json_agg(DISTINCT jsonb_build_object('id', h.id, 'name', h.tag_name)) FILTER (WHERE h.tag_name IS NOT NULL) as "hashtags",
from reservations r
right join mentor_profiles mp on mp.user_id = r.mentor_id
left join _profiles_categories pc on pc.B = mp.id
Expand Down
5 changes: 3 additions & 2 deletions cmd/api-server/internal/service/SearchService.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package service
import (
"golang-with-k8s/cmd/api-server/internal/repository"
"golang-with-k8s/generated/api_server"
"golang-with-k8s/pkg/models"
)

func MentorSearchString(searchString *api_server.SearchStringPath, params *api_server.GetSearchMentorSearchStringParams) (*[]api_server.HomeGet, error) {
return repository.SearchMentor(searchString, params)
func MentorSearchString(searchString *api_server.SearchStringPath, params *api_server.GetSearchMentorSearchStringParams) (*[]models.HomeGet, error) {
return repository.MentorProfileSearch(searchString, params)
}
8 changes: 4 additions & 4 deletions cmd/api-server/internal/service/UserService.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"golang-with-k8s/pkg/models"
)

func GetUsersService(param *api_server.GetUsersParams) (*[]models.User, error) {
func GetUsersService(param *api_server.GetUsersParams) (*[]models.UserGet, error) {
return repository.GetUsers(param)
}

func GetUserByIdService(id *api_server.IdPath) (*api_server.UserGet, error) {
func GetUserByIdService(id *api_server.IdPath) (*models.UserGet, error) {
return repository.GetUserById(id)
}

func GetUsersIdReservationService(id *api_server.IdPath, params *api_server.GetUsersIdReservationsParams) (*api_server.UserReservationPagination, error) {
func GetUsersIdReservationService(id *api_server.IdPath, params *api_server.GetUsersIdReservationsParams) (*models.UserReservationPagination, error) {
return repository.GetUsersIdReservations(id, params)
}

func PatchUserService(id *api_server.IdPath, body *api_server.PatchUsersIdJSONRequestBody) (*api_server.UserGet, error) {
func PatchUserService(id *api_server.IdPath, body *api_server.PatchUsersIdJSONRequestBody) (*models.UserGet, error) {
return repository.PatchUser(id, body)
}
Empty file added deployments/api-server.yaml
Empty file.
4 changes: 2 additions & 2 deletions generated/api_server/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ func (c *config) initConfig() {
func init() {
ConfigInstance = new(config)
ConfigInstance.initConfig()
var envFilePath string

deploy_mode := os.Getenv("ENVIROMENT")
if deploy_mode == "production" {
envFilePath = ".env.prod"
} else {
envFilePath = ".env.dev"
}

envFilePath := ".env.auth"
ConfigInstance.loadEnvfile(&envFilePath, []string{"GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET", "GOOGLE_LOGIN_CALLBACK"})
ConfigInstance.loadEnvfile(&envFilePath, []string{"FT_CLIENT_ID", "FT_CLIENT_SECRET", "FT_LOGIN_CALLBACK"})

envFilePath = ".env.db"
ConfigInstance.loadEnvfile(&envFilePath, []string{"URL"})

envFilePath = ".env.secrets"
ConfigInstance.loadEnvfile(&envFilePath, []string{"SESSION_SECRET"})
}
13 changes: 5 additions & 8 deletions pkg/models/cancel_reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package models

import "time"

type CancelReason struct {
ID int
Content string
CreatedAt time.Time
RequestUser User
RequestedUserId int
Reservation Reservation
ReservationId int
type ReservationCancelReason struct {
Content *string `db:"content" json:"content,omitempty"`
CreatedAt *time.Time `db:"created_at" json:"createdAt,omitempty"`
RequestedUserId *int32 `db:"requested_user_id" json:"requestedUserId,omitempty"`
ReservationId *int32 `db:"reservation_id" json:"reservationId,omitempty"`
}
28 changes: 23 additions & 5 deletions pkg/models/category.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
package models

type Category struct {
ID int `db:"id"`
Name string `db:"name"`
MentorProfiles []MentorProfile
Reservations []Reservation
import (
"database/sql/driver"
"encoding/json"
"golang-with-k8s/generated/api_server"
)

type CategorySlices []*api_server.CategoryGet

func (s CategorySlices) Value() (driver.Value, error) {
return json.Marshal(s)
}

func (s *CategorySlices) Scan(src interface{}) error {
var data []byte
switch v := src.(type) {
case string:
data = []byte(v)
case []byte:
data = v
default:
return nil
}
return json.Unmarshal(data, s)
}
15 changes: 0 additions & 15 deletions pkg/models/consts.go

This file was deleted.

29 changes: 24 additions & 5 deletions pkg/models/hashtag.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
package models

type Hashtag struct {
ID int `db:"id"`
Name string `db:"tag_name"`
MentorProfile []MentorProfile
Reservations []Reservation
import (
"database/sql/driver"
"encoding/json"
"golang-with-k8s/generated/api_server"
)

type HashtagSlices []*api_server.HashtagGet

func (s HashtagSlices) Value() (driver.Value, error) {
return json.Marshal(s)

}

func (s *HashtagSlices) Scan(src interface{}) error {
var data []byte
switch v := src.(type) {
case string:
data = []byte(v)
case []byte:
data = v
default:
return nil
}
return json.Unmarshal(data, s)
}
20 changes: 20 additions & 0 deletions pkg/models/home.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package models

import (
"golang-with-k8s/generated/api_server"
"time"
)

// HomeGet defines model for HomeGet.
type HomeGet struct {
Categories CategorySlices `db:"categories" json:"categories,omitempty"`
CreatedAt *time.Time `db:"created_at" json:"createdAt,omitempty"`
Description *string `db:"description" json:"description,omitempty"`
Hashtags HashtagSlices `db:"hashtags" json:"hashtags,omitempty"`
Id *int32 `db:"id" json:"id,omitempty"`
IsHide *bool `db:"is_hide" json:"isHide,omitempty"`
MentoringCount *int `db:"mentoring_count" json:"mentoringCount,omitempty"`
ShortDescription *string `db:"short_description" json:"shortDescription,omitempty"`
UpdatedAt *time.Time `db:"updated_at" json:"updatedAt,omitempty"`
User *api_server.HomeSimpleUser `json:"user,omitempty"`
}
16 changes: 0 additions & 16 deletions pkg/models/mentee_feedback.go
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
package models

import "time"

type MenteeFeedback struct {
ID int
Mentee User
MenteeId int
Mentor User
MentorId int
Reservation Reservation
ReservationId int
Rating float64
Content *string
CreatedAt time.Time
UpdatedAt *time.Time
}
15 changes: 0 additions & 15 deletions pkg/models/mentor_feedback.go
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
package models

import "time"

type MentorFeedback struct {
ID int
Mentee User
MenteeId int
Mentor User
MentorId int
Reservation Reservation
ReservationId int
Rating float64
CreatedAt time.Time
UpdatedAt *time.Time
}
Loading

0 comments on commit 725be5f

Please sign in to comment.