Skip to content

workshop content#3

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

workshop content#3
kichibeii wants to merge 1 commit intotherizk:masterfrom
kichibeii:workshop

Conversation

@kichibeii
Copy link

No description provided.

"log"

"github.com/tokopedia/code-review-workshop/database"
redislib "github.com/tokopedia/code-review-workshop/redis"
Copy link
Author

Choose a reason for hiding this comment

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

import lebih baik di rapihkan antara external dan internal code

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
redislib "github.com/tokopedia/code-review-workshop/redis"
"github.com/tokopedia/code-review-workshop/database"
redislib "github.com/tokopedia/code-review-workshop/redis"
"github.com/tokopedia/sqlt"

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.

bisa di buat switch case dan di dalamnya masuk2in
-GetNilaiSiswaByID
-GetNilaiSiswaBySekolah
-GetNilaiSiswaSemuaSekolah

lalu baru di luar untuk proses

  • GetDetailSekolah dan mappingGetNilaiSiswa

"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.

parameter sebaiknya di bikin sebuah struct yang baru

import (
"context"

nilai "github.com/tokopedia/code-review-workshop/core/nilai"
Copy link
Author

Choose a reason for hiding this comment

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

import external code dipisah dengan import dari dalam service


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

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

Choose a reason for hiding this comment

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

mungkin pake function Get() dari grpc untuk lebih aman

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.

menggunakan function Get() dari GRPC

var err error
db, err = database.Get(database.PromoCatalog)
if err != nil {
log.Printf("Cannot connect to DB. %+v", err)
Copy link
Author

Choose a reason for hiding this comment

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

lebih baik log.Fatal kah? takutnya ketika servicenya jalan dan tidak bisa ke db jadi error


const (
// Collection queries
QueryGetNilaiSiswaByID = `select nim, mapel_id, nilai, sekolah, kelas
Copy link
Author

Choose a reason for hiding this comment

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

coalesce?

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