Skip to content

workshop content#12

Open
natasharamdani wants to merge 1 commit intotherizk:masterfrom
natasharamdani:workshop
Open

workshop content#12
natasharamdani wants to merge 1 commit intotherizk:masterfrom
natasharamdani:workshop

Conversation

@natasharamdani
Copy link

No description provided.

var (
db *sqlt.DB
stmt PreparedStatements
redis *redislib.RedisStore // redis module
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
redis *redislib.RedisStore // redis module
redis *redislib.RedisStore

remove unnecessary comment

)

const (
// Collection queries
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Collection queries
// Nilai Siswa queries

Comment on lines +24 to +26
QueryGetNilaiSiswaByID = `select nim, mapel_id, nilai, sekolah, kelas
from nilai_siswa
where mapel_id = $1 and nim = $2;`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QueryGetNilaiSiswaByID = `select nim, mapel_id, nilai, sekolah, kelas
from nilai_siswa
where mapel_id = $1 and nim = $2;`
QueryGetNilaiSiswaByMapelIDAndNIM = `
SELECT nim, mapel_id, nilai, sekolah, kelas
FROM nilai_siswa
WHERE mapel_id = $1 AND nim = $2;
`


type NilaiSiswa struct {
NIM int64 `json:"nim" db:"nim"`
MapelID int64 `json:"mapel_id" db:"mapel_id"`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MapelID int64 `json:"mapel_id" db:"mapel_id"`
MapelID int `json:"mapel_id" db:"mapel_id"`

sepertinya data type int64 terlalu berlebihan untuk mata pelajaran

type NilaiSiswa struct {
NIM int64 `json:"nim" db:"nim"`
MapelID int64 `json:"mapel_id" db:"mapel_id"`
Nilai int64 `json:"nili" db:"nili"`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Nilai int64 `json:"nili" db:"nili"`
Nilai float32 `json:"nilai" db:"nilai"`

nilai biasanya ada angka di belakang koma

)

func (s *server) GetNilaiSiswa(ctx context.Context, req *pb.GetNilaiSiswaRequest) (resp *pb.GetNilaiSiswaResponse, err error) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
span, ctx := tracer.StartSpanFromContext(ctx)
defer span.Finish()

func (s *server) GetNilaiSiswa(ctx context.Context, req *pb.GetNilaiSiswaRequest) (resp *pb.GetNilaiSiswaResponse, err error) {

if req.sekolah == "" {
req.sekolah = "semua"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

untuk string "semua" mungkin bisa dibuat const

req.sekolah = "semua"
}

nilai, err := mnilai.GetNilaiSiswa(req.nim, req.sekolah, req.kelas, mapel_id)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nilai, err := mnilai.GetNilaiSiswa(req.nim, req.sekolah, req.kelas, mapel_id)
nilai, err := mnilai.GetNilaiSiswa(req.nim, req.sekolah, req.kelas, req.mapel_id)

Comment on lines +7 to +9
"github.com/tokopedia/code-review-workshop/database"
redislib "github.com/tokopedia/code-review-workshop/redis"
"github.com/tokopedia/sqlt"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import beda repo sebaiknya dipisah dengan newline

Comment on lines +6 to +8
nilai "github.com/tokopedia/code-review-workshop/core/nilai"
"github.com/tokopedia/tokopoints/errors"
"github.com/tokopedia/tokopoints/tracer"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import beda repo sebaiknya dipisah dengan newline

span, ctx := tracer.StartSpanFromContext(ctx)
defer span.Finish()

if nim != 0 && mapel_id != 0 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if nim != 0 && mapel_id != 0 {
if nim > 0 && mapel_id > 0 {

antisipasi negative value

Comment on lines +33 to +38
detailSekolah, err := nilai.GetDetailSekolah(ctx, nilai.Sekolah[0])
if err != nil {
return resp, errors.AddTrace(err)
}

resp = mappingGetNilaiSiswa(nilai, detailSekolah)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetDetailSekolah dan mappingGetNilaiSiswa lebih baik setelah if else selesai agar tidak redundant

}

resp = mappingGetNilaiSiswa(nilai, detailSekolah)
} else if sekolah == "semua" {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if sekolah == "semua" {
} else {

"github.com/tokopedia/tokopoints/tracer"
)

func GetNilaiSiswa(ctx context.Context, nim int64, sekolah, kelas string, mapel_id int64) (resp GetNilaiSiswaResponse, err error) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param pakai struct supaya lebih rapi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants